Pixel/links development. New validations folder. More refactoring.

This commit is contained in:
Mike Cao 2025-08-14 23:48:11 -07:00
parent 88639dfe83
commit 247e14646b
136 changed files with 1395 additions and 516 deletions

View file

@ -20,23 +20,25 @@ export function AdminTeamsTable({
return (
<>
<DataTable data={data}>
<DataColumn id="name" label={formatMessage(labels.name)} width="2fr">
<DataColumn id="name" label={formatMessage(labels.name)} width="1fr">
{(row: any) => <Link href={`/admin/teams/${row.id}`}>{row.name}</Link>}
</DataColumn>
<DataColumn id="websites" label={formatMessage(labels.members)}>
{(row: any) => row?._count?.teamUser}
<DataColumn id="websites" label={formatMessage(labels.members)} width="140px">
{(row: any) => row?._count?.members}
</DataColumn>
<DataColumn id="members" label={formatMessage(labels.websites)}>
{(row: any) => row?._count?.website}
<DataColumn id="members" label={formatMessage(labels.websites)} width="140px">
{(row: any) => row?._count?.websites}
</DataColumn>
<DataColumn id="owner" label={formatMessage(labels.owner)} width="200px">
{(row: any) => (
<Text title={row?.teamUser?.[0]?.user?.username} truncate>
<Link href={`/admin/users/${row?.teamUser?.[0]?.user?.id}`}>
{row?.teamUser?.[0]?.user?.username}
</Link>
<DataColumn id="owner" label={formatMessage(labels.owner)}>
{(row: any) => {
const name = row?.members?.[0]?.user?.username;
return (
<Text title={name} truncate>
<Link href={`/admin/users/${row?.members?.[0]?.user?.id}`}>{name}</Link>
</Text>
)}
);
}}
</DataColumn>
<DataColumn id="created" label={formatMessage(labels.created)} width="160px">
{(row: any) => <DateDistance date={new Date(row.createdAt)} />}

View file

@ -33,7 +33,7 @@ export function UsersTable({
}
</DataColumn>
<DataColumn id="websites" label={formatMessage(labels.websites)}>
{(row: any) => row._count.websiteUser}
{(row: any) => row._count.websites}
</DataColumn>
<DataColumn id="created" label={formatMessage(labels.created)}>
{(row: any) => <DateDistance date={new Date(row.createdAt)} />}

View file

@ -34,7 +34,7 @@ export function LinkDeleteButton({
};
return (
<ActionButton tooltip={formatMessage(labels.delete)} icon={<Trash />}>
<ActionButton title={formatMessage(labels.delete)} icon={<Trash />}>
<Dialog title={formatMessage(labels.confirm)} style={{ width: 400 }}>
{({ close }) => (
<ConfirmationForm

View file

@ -8,7 +8,7 @@ export function LinkEditButton({ linkId }: { linkId: string }) {
const { formatMessage, labels } = useMessages();
return (
<ActionButton tooltip={formatMessage(labels.edit)} icon={<Edit />}>
<ActionButton title={formatMessage(labels.edit)} icon={<Edit />}>
<Dialog title={formatMessage(labels.link)} style={{ width: 800 }}>
{({ close }) => {
return <LinkEditForm linkId={linkId} onClose={close} />;

View file

@ -1,13 +1,16 @@
import { DataTable, DataColumn, Row } from '@umami/react-zen';
import { useMessages, useNavigation } from '@/components/hooks';
import { useConfig, useMessages, useNavigation } from '@/components/hooks';
import { Empty } from '@/components/common/Empty';
import { DateDistance } from '@/components/common/DateDistance';
import { ExternalLink } from '@/components/common/ExternalLink';
import { LinkEditButton } from './LinkEditButton';
import { LinkDeleteButton } from './LinkDeleteButton';
export function LinksTable({ data = [] }) {
const { formatMessage, labels } = useMessages();
const { websiteId } = useNavigation();
const { linksUrl } = useConfig();
const hostUrl = linksUrl || `${window.location.origin}/x`;
if (data.length === 0) {
return <Empty />;
@ -16,14 +19,22 @@ export function LinksTable({ data = [] }) {
return (
<DataTable data={data}>
<DataColumn id="name" label={formatMessage(labels.name)} />
<DataColumn id="url" label={formatMessage(labels.destinationUrl)} />
<DataColumn id="created" label={formatMessage(labels.created)}>
<DataColumn id="slug" label={formatMessage(labels.link)}>
{({ slug }: any) => {
const url = `${hostUrl}/${slug}`;
return <ExternalLink href={url}>{url}</ExternalLink>;
}}
</DataColumn>
<DataColumn id="url" label={formatMessage(labels.destinationUrl)}>
{({ url }: any) => {
return <ExternalLink href={url}>{url}</ExternalLink>;
}}
</DataColumn>
<DataColumn id="created" label={formatMessage(labels.created)} width="200px">
{(row: any) => <DateDistance date={new Date(row.createdAt)} />}
</DataColumn>
<DataColumn id="action" align="end" width="100px">
{(row: any) => {
const { id, name } = row;
{({ id, name }: any) => {
return (
<Row>
<LinkEditButton linkId={id} />

View file

View file

@ -1,17 +1,16 @@
import { useMessages, useModified, useNavigation } from '@/components/hooks';
import { useMessages, useModified } from '@/components/hooks';
import { Button, Icon, Modal, Dialog, DialogTrigger, Text, useToast } from '@umami/react-zen';
import { Plus } from '@/components/icons';
import { PixelAddForm } from './PixelAddForm';
import { PixelEditForm } from './PixelEditForm';
export function PixelAddButton() {
export function PixelAddButton({ teamId }: { teamId?: string }) {
const { formatMessage, labels, messages } = useMessages();
const { toast } = useToast();
const { touch } = useModified();
const { teamId } = useNavigation();
const handleSave = async () => {
toast(formatMessage(messages.saved));
touch('boards');
touch('pixels');
};
return (
@ -23,8 +22,8 @@ export function PixelAddButton() {
<Text>{formatMessage(labels.addPixel)}</Text>
</Button>
<Modal>
<Dialog title={formatMessage(labels.addPixel)} style={{ width: 400 }}>
{({ close }) => <PixelAddForm teamId={teamId} onSave={handleSave} onClose={close} />}
<Dialog title={formatMessage(labels.addPixel)} style={{ width: 600 }}>
{({ close }) => <PixelEditForm teamId={teamId} onSave={handleSave} onClose={close} />}
</Dialog>
</Modal>
</DialogTrigger>

View file

@ -1,62 +0,0 @@
import { Form, FormField, FormSubmitButton, Row, TextField, Button } from '@umami/react-zen';
import { useApi } from '@/components/hooks';
import { DOMAIN_REGEX } from '@/lib/constants';
import { useMessages } from '@/components/hooks';
export function PixelAddForm({
teamId,
onSave,
onClose,
}: {
teamId?: string;
onSave?: () => void;
onClose?: () => void;
}) {
const { formatMessage, labels, messages } = useMessages();
const { post, useMutation } = useApi();
const { mutate, error, isPending } = useMutation({
mutationFn: (data: any) => post('/pixels', { ...data, teamId }),
});
const handleSubmit = async (data: any) => {
mutate(data, {
onSuccess: async () => {
onSave?.();
onClose?.();
},
});
};
return (
<Form onSubmit={handleSubmit} error={error?.message}>
<FormField
label={formatMessage(labels.name)}
name="name"
rules={{ required: formatMessage(labels.required) }}
>
<TextField autoComplete="off" />
</FormField>
<FormField
label={formatMessage(labels.domain)}
name="domain"
rules={{
required: formatMessage(labels.required),
pattern: { value: DOMAIN_REGEX, message: formatMessage(messages.invalidDomain) },
}}
>
<TextField autoComplete="off" />
</FormField>
<Row justifyContent="flex-end" paddingTop="3" gap="3">
{onClose && (
<Button isDisabled={isPending} onPress={onClose}>
{formatMessage(labels.cancel)}
</Button>
)}
<FormSubmitButton data-test="button-submit" isDisabled={false}>
{formatMessage(labels.save)}
</FormSubmitButton>
</Row>
</Form>
);
}

View file

@ -0,0 +1,55 @@
import { Dialog } from '@umami/react-zen';
import { ActionButton } from '@/components/input/ActionButton';
import { Trash } from '@/components/icons';
import { ConfirmationForm } from '@/components/common/ConfirmationForm';
import { messages } from '@/components/messages';
import { useApi, useMessages, useModified } from '@/components/hooks';
export function PixelDeleteButton({
pixelId,
websiteId,
name,
onSave,
}: {
pixelId: string;
websiteId: string;
name: string;
onSave?: () => void;
}) {
const { formatMessage, labels } = useMessages();
const { del, useMutation } = useApi();
const { mutate, isPending, error } = useMutation({
mutationFn: () => del(`/websites/${websiteId}/pixels/${pixelId}`),
});
const { touch } = useModified();
const handleConfirm = (close: () => void) => {
mutate(null, {
onSuccess: () => {
touch('pixels');
onSave?.();
close();
},
});
};
return (
<ActionButton title={formatMessage(labels.delete)} icon={<Trash />}>
<Dialog title={formatMessage(labels.confirm)} style={{ width: 400 }}>
{({ close }) => (
<ConfirmationForm
message={formatMessage(messages.confirmRemove, {
target: name,
})}
isLoading={isPending}
error={error}
onConfirm={handleConfirm.bind(null, close)}
onClose={close}
buttonLabel={formatMessage(labels.delete)}
buttonVariant="danger"
/>
)}
</Dialog>
</ActionButton>
);
}

View file

@ -0,0 +1,19 @@
import { ActionButton } from '@/components/input/ActionButton';
import { Edit } from '@/components/icons';
import { Dialog } from '@umami/react-zen';
import { PixelEditForm } from './PixelEditForm';
import { useMessages } from '@/components/hooks';
export function PixelEditButton({ pixelId }: { pixelId: string }) {
const { formatMessage, labels } = useMessages();
return (
<ActionButton title={formatMessage(labels.edit)} icon={<Edit />}>
<Dialog title={formatMessage(labels.pixel)} style={{ width: 800 }}>
{({ close }) => {
return <PixelEditForm pixelId={pixelId} onClose={close} />;
}}
</Dialog>
</ActionButton>
);
}

View file

@ -0,0 +1,105 @@
import {
Form,
FormField,
FormSubmitButton,
Row,
TextField,
Button,
Text,
Label,
Column,
Icon,
Loading,
} from '@umami/react-zen';
import { useConfig, usePixelQuery } from '@/components/hooks';
import { useMessages } from '@/components/hooks';
import { Refresh } from '@/components/icons';
import { getRandomChars } from '@/lib/crypto';
import { useUpdateQuery } from '@/components/hooks/queries/useUpdateQuery';
const generateId = () => getRandomChars(9);
export function PixelEditForm({
pixelId,
teamId,
onSave,
onClose,
}: {
pixelId?: string;
teamId?: string;
onSave?: () => void;
onClose?: () => void;
}) {
const { formatMessage, labels } = useMessages();
const { mutate, error, isPending } = useUpdateQuery('/pixels', { id: pixelId, teamId });
const { pixelDomain } = useConfig();
const { data, isLoading } = usePixelQuery(pixelId);
const handleSubmit = async (data: any) => {
mutate(data, {
onSuccess: async () => {
onSave?.();
onClose?.();
},
});
};
if (pixelId && !isLoading) {
return <Loading position="page" />;
}
return (
<Form
onSubmit={handleSubmit}
error={error?.message}
defaultValues={{ slug: generateId(), ...data }}
>
{({ setValue }) => {
return (
<>
<FormField
label={formatMessage(labels.name)}
name="name"
rules={{ required: formatMessage(labels.required) }}
>
<TextField autoComplete="off" />
</FormField>
<Column>
<Label>{formatMessage(labels.pixel)}</Label>
<Row alignItems="center" gap>
<Text>{pixelDomain || window.location.origin}/</Text>
<FormField
name="slug"
rules={{
required: formatMessage(labels.required),
}}
style={{ width: '100%' }}
>
<TextField autoComplete="off" isReadOnly />
</FormField>
<Button
variant="quiet"
onPress={() => setValue('slug', generateId(), { shouldDirty: true })}
>
<Icon>
<Refresh />
</Icon>
</Button>
</Row>
</Column>
<Row justifyContent="flex-end" paddingTop="3" gap="3">
{onClose && (
<Button isDisabled={isPending} onPress={onClose}>
{formatMessage(labels.cancel)}
</Button>
)}
<FormSubmitButton isDisabled={false}>{formatMessage(labels.save)}</FormSubmitButton>
</Row>
</>
);
}}
</Form>
);
}

View file

@ -0,0 +1,14 @@
import { usePixelsQuery, useNavigation } from '@/components/hooks';
import { PixelsTable } from './PixelsTable';
import { DataGrid } from '@/components/common/DataGrid';
export function PixelsDataTable() {
const { teamId } = useNavigation();
const query = usePixelsQuery({ teamId });
return (
<DataGrid query={query} allowSearch={true} autoFocus={false} allowPaging={true}>
{({ data }) => <PixelsTable data={data} />}
</DataGrid>
);
}

View file

@ -3,17 +3,23 @@ import { PageBody } from '@/components/common/PageBody';
import { Column } from '@umami/react-zen';
import { PageHeader } from '@/components/common/PageHeader';
import { PixelAddButton } from './PixelAddButton';
import { useMessages } from '@/components/hooks';
import { useMessages, useNavigation } from '@/components/hooks';
import { PixelsDataTable } from './PixelsDataTable';
import { Panel } from '@/components/common/Panel';
export function PixelsPage() {
const { formatMessage, labels } = useMessages();
const { teamId } = useNavigation();
return (
<PageBody>
<Column>
<Column gap="6">
<PageHeader title={formatMessage(labels.pixels)}>
<PixelAddButton />
<PixelAddButton teamId={teamId} />
</PageHeader>
<Panel>
<PixelsDataTable />
</Panel>
</Column>
</PageBody>
);

View file

@ -0,0 +1,45 @@
import { DataTable, DataColumn, Row } from '@umami/react-zen';
import { useConfig, useMessages, useNavigation } from '@/components/hooks';
import { Empty } from '@/components/common/Empty';
import { DateDistance } from '@/components/common/DateDistance';
import { PixelEditButton } from './PixelEditButton';
import { PixelDeleteButton } from './PixelDeleteButton';
import Link from 'next/link';
export function PixelsTable({ data = [] }) {
const { formatMessage, labels } = useMessages();
const { websiteId } = useNavigation();
const { pixelsUrl } = useConfig();
const defaultUrl = `${window.location.origin}/p`;
if (data.length === 0) {
return <Empty />;
}
return (
<DataTable data={data}>
<DataColumn id="name" label={formatMessage(labels.name)} />
<DataColumn id="url" label="URL">
{({ slug }: any) => {
const url = `${pixelsUrl || defaultUrl}/${slug}`;
return <Link href={url}>{url}</Link>;
}}
</DataColumn>
<DataColumn id="created" label={formatMessage(labels.created)}>
{(row: any) => <DateDistance date={new Date(row.createdAt)} />}
</DataColumn>
<DataColumn id="action" align="end" width="100px">
{(row: any) => {
const { id, name } = row;
return (
<Row>
<PixelEditButton pixelId={id} />
<PixelDeleteButton pixelId={id} websiteId={websiteId} name={name} />
</Row>
);
}}
</DataColumn>
</DataTable>
);
}

View file

View file

@ -26,7 +26,7 @@ export function TeamMemberEditButton({
};
return (
<ActionButton tooltip={formatMessage(labels.edit)} icon={<Edit />}>
<ActionButton title={formatMessage(labels.edit)} icon={<Edit />}>
<Dialog title={formatMessage(labels.editMember)} style={{ width: 400 }}>
{({ close }) => (
<TeamMemberEditForm

View file

@ -35,7 +35,7 @@ export function TeamMemberRemoveButton({
};
return (
<ActionButton tooltip={formatMessage(labels.delete)} icon={<Trash />}>
<ActionButton title={formatMessage(labels.delete)} icon={<Trash />}>
<Dialog title={formatMessage(labels.removeMember)} style={{ width: 400 }}>
{({ close }) => (
<ConfirmationForm

View file

@ -1,11 +0,0 @@
.website {
padding-bottom: 30px;
border-bottom: 1px solid var(--base300);
margin-bottom: 30px;
align-self: stretch;
}
.website:last-child {
border-bottom: 0;
margin-bottom: 20px;
}

View file

@ -23,8 +23,8 @@ export function WebsiteData({ websiteId, onSave }: { websiteId: string; onSave?:
const canTransferWebsite =
(
(!teamId &&
teams?.data?.filter(({ teamUser }) =>
teamUser.find(
teams?.data?.filter(({ members }) =>
members.find(
({ role, userId }) =>
[ROLES.teamOwner, ROLES.teamManager].includes(role) && userId === user.id,
),
@ -34,7 +34,7 @@ export function WebsiteData({ websiteId, onSave }: { websiteId: string; onSave?:
(teamId &&
!!teams?.data
?.find(({ id }) => id === teamId)
?.teamUser.find(({ role, userId }) => role === ROLES.teamOwner && userId === user.id));
?.members.find(({ role, userId }) => role === ROLES.teamOwner && userId === user.id));
const handleSave = () => {
touch('websites');

View file

@ -6,7 +6,6 @@ import { WebsiteShareForm } from './WebsiteShareForm';
import { WebsiteTrackingCode } from './WebsiteTrackingCode';
import { WebsiteData } from './WebsiteData';
import { WebsiteEditForm } from './WebsiteEditForm';
import { SegmentsDataTable } from '@/app/(main)/websites/[websiteId]/segments/SegmentsDataTable';
export function WebsiteSettings({ websiteId }: { websiteId: string; openExternal?: boolean }) {
const website = useContext(WebsiteContext);
@ -18,7 +17,6 @@ export function WebsiteSettings({ websiteId }: { websiteId: string; openExternal
<Tab id="details">{formatMessage(labels.details)}</Tab>
<Tab id="tracking">{formatMessage(labels.trackingCode)}</Tab>
<Tab id="share"> {formatMessage(labels.shareUrl)}</Tab>
<Tab id="segments"> {formatMessage(labels.segments)}</Tab>
<Tab id="manage">{formatMessage(labels.manage)}</Tab>
</TabList>
<TabPanel id="details" style={{ width: 500 }}>
@ -30,9 +28,6 @@ export function WebsiteSettings({ websiteId }: { websiteId: string; openExternal
<TabPanel id="share" style={{ width: 500 }}>
<WebsiteShareForm websiteId={websiteId} shareId={website.shareId} />
</TabPanel>
<TabPanel id="segments">
<SegmentsDataTable websiteId={websiteId} />
</TabPanel>
<TabPanel id="manage">
<WebsiteData websiteId={websiteId} />
</TabPanel>

View file

@ -1,5 +1,5 @@
import { DataGrid } from '@/components/common/DataGrid';
import { TeamsTable } from '@/app/(main)/settings/teams/TeamsTable';
import { TeamsTable } from './TeamsTable';
import { useLoginQuery, useUserTeamsQuery } from '@/components/hooks';
import { ReactNode } from 'react';

View file

@ -1,9 +1,9 @@
'use client';
import { WebsitesDataTable } from '@/app/(main)/settings/websites/WebsitesDataTable';
import { WebsitesDataTable } from './WebsitesDataTable';
import { WebsiteAddButton } from './WebsiteAddButton';
import { useMessages, useNavigation } from '@/components/hooks';
import { Column } from '@umami/react-zen';
import { PageHeader } from '@/components/common/PageHeader';
import { WebsiteAddButton } from '@/app/(main)/settings/websites/WebsiteAddButton';
import { Panel } from '@/components/common/Panel';
import { PageBody } from '@/components/common/PageBody';

View file

@ -11,6 +11,8 @@ import {
Tag,
Money,
Network,
ChartPie,
UserPlus,
} from '@/components/icons';
import { useMessages, useNavigation } from '@/components/hooks';
import { SideMenu } from '@/components/common/SideMenu';
@ -87,6 +89,23 @@ export function WebsiteNav({ websiteId }: { websiteId: string }) {
},
],
},
{
label: formatMessage(labels.audience),
items: [
{
id: 'segments',
label: formatMessage(labels.segments),
icon: <ChartPie />,
path: renderPath('/segments'),
},
{
id: 'cohorts',
label: formatMessage(labels.cohorts),
icon: <UserPlus />,
path: renderPath('/cohorts'),
},
],
},
{
label: formatMessage(labels.growth),
items: [

View file

@ -0,0 +1,26 @@
import { Button, DialogTrigger, Modal, Text, Icon, Dialog } from '@umami/react-zen';
import { useMessages } from '@/components/hooks';
import { Plus } from '@/components/icons';
import { CohortEditForm } from './CohortEditForm';
export function CohortAddButton({ websiteId }: { websiteId: string }) {
const { formatMessage, labels } = useMessages();
return (
<DialogTrigger>
<Button variant="primary">
<Icon>
<Plus />
</Icon>
<Text>{formatMessage(labels.cohort)}</Text>
</Button>
<Modal>
<Dialog title={formatMessage(labels.cohort)} style={{ width: 800 }}>
{({ close }) => {
return <CohortEditForm websiteId={websiteId} onClose={close} />;
}}
</Dialog>
</Modal>
</DialogTrigger>
);
}

View file

@ -0,0 +1,55 @@
import { Dialog } from '@umami/react-zen';
import { ActionButton } from '@/components/input/ActionButton';
import { Trash } from '@/components/icons';
import { ConfirmationForm } from '@/components/common/ConfirmationForm';
import { messages } from '@/components/messages';
import { useApi, useMessages, useModified } from '@/components/hooks';
export function CohortDeleteButton({
cohortId,
websiteId,
name,
onSave,
}: {
cohortId: string;
websiteId: string;
name: string;
onSave?: () => void;
}) {
const { formatMessage, labels } = useMessages();
const { del, useMutation } = useApi();
const { mutate, isPending, error } = useMutation({
mutationFn: () => del(`/websites/${websiteId}/cohorts/${cohortId}`),
});
const { touch } = useModified();
const handleConfirm = (close: () => void) => {
mutate(null, {
onSuccess: () => {
touch('cohorts');
onSave?.();
close();
},
});
};
return (
<ActionButton title={formatMessage(labels.delete)} icon={<Trash />}>
<Dialog title={formatMessage(labels.confirm)} style={{ width: 400 }}>
{({ close }) => (
<ConfirmationForm
message={formatMessage(messages.confirmRemove, {
target: name,
})}
isLoading={isPending}
error={error}
onConfirm={handleConfirm.bind(null, close)}
onClose={close}
buttonLabel={formatMessage(labels.delete)}
buttonVariant="danger"
/>
)}
</Dialog>
</ActionButton>
);
}

View file

@ -0,0 +1,34 @@
import { ActionButton } from '@/components/input/ActionButton';
import { Edit } from '@/components/icons';
import { Dialog } from '@umami/react-zen';
import { CohortEditForm } from '@/app/(main)/websites/[websiteId]/cohorts/CohortEditForm';
import { useMessages } from '@/components/hooks';
export function CohortEditButton({
cohortId,
websiteId,
filters,
}: {
cohortId: string;
websiteId: string;
filters: any[];
}) {
const { formatMessage, labels } = useMessages();
return (
<ActionButton title={formatMessage(labels.edit)} icon={<Edit />}>
<Dialog title={formatMessage(labels.cohort)} style={{ width: 800 }}>
{({ close }) => {
return (
<CohortEditForm
cohortId={cohortId}
websiteId={websiteId}
filters={filters}
onClose={close}
/>
);
}}
</Dialog>
</ActionButton>
);
}

View file

@ -0,0 +1,100 @@
import {
Button,
Form,
FormButtons,
FormField,
FormSubmitButton,
TextField,
Label,
Loading,
} from '@umami/react-zen';
import { subMonths, endOfDay } from 'date-fns';
import { FieldFilters } from '@/components/input/FieldFilters';
import { useState } from 'react';
import { useApi, useMessages, useModified, useWebsiteCohortQuery } from '@/components/hooks';
import { filtersArrayToObject } from '@/lib/params';
export function CohortEditForm({
cohortId,
websiteId,
filters = [],
showFilters = true,
onSave,
onClose,
}: {
cohortId?: string;
websiteId: string;
filters?: any[];
showFilters?: boolean;
onSave?: () => void;
onClose?: () => void;
}) {
const { data } = useWebsiteCohortQuery(websiteId, cohortId);
const { formatMessage, labels } = useMessages();
const [currentFilters, setCurrentFilters] = useState(filters);
const { touch } = useModified();
const startDate = subMonths(endOfDay(new Date()), 6);
const endDate = endOfDay(new Date());
const { post, useMutation } = useApi();
const { mutate, error, isPending } = useMutation({
mutationFn: (data: any) =>
post(`/websites/${websiteId}/cohorts${cohortId ? `/${cohortId}` : ''}`, {
...data,
type: 'cohort',
}),
});
const handleSubmit = async (data: any) => {
mutate(
{ ...data, parameters: filtersArrayToObject(currentFilters) },
{
onSuccess: async () => {
touch('cohorts');
onSave?.();
onClose?.();
},
},
);
};
if (cohortId && !data) {
return <Loading position="page" />;
}
return (
<Form error={error} onSubmit={handleSubmit} defaultValues={data}>
<FormField
name="name"
label={formatMessage(labels.name)}
rules={{ required: formatMessage(labels.required) }}
>
<TextField autoFocus />
</FormField>
{showFilters && (
<>
<Label>{formatMessage(labels.filters)}</Label>
<FieldFilters
websiteId={websiteId}
filters={currentFilters}
startDate={startDate}
endDate={endDate}
onSave={setCurrentFilters}
/>
</>
)}
<FormButtons>
<Button isDisabled={isPending} onPress={onClose}>
{formatMessage(labels.cancel)}
</Button>
<FormSubmitButton
variant="primary"
data-test="button-submit"
isDisabled={isPending || currentFilters.length === 0}
>
{formatMessage(labels.save)}
</FormSubmitButton>
</FormButtons>
</Form>
);
}

View file

@ -0,0 +1,24 @@
import { CohortAddButton } from './CohortAddButton';
import { useWebsiteCohortsQuery } from '@/components/hooks';
import { CohortsTable } from './CohortsTable';
import { DataGrid } from '@/components/common/DataGrid';
export function CohortsDataTable({ websiteId }: { websiteId?: string }) {
const query = useWebsiteCohortsQuery(websiteId, { type: 'cohort' });
const renderActions = () => {
return <CohortAddButton websiteId={websiteId} />;
};
return (
<DataGrid
query={query}
allowSearch={true}
autoFocus={false}
allowPaging={true}
renderActions={renderActions}
>
{({ data }) => <CohortsTable data={data} />}
</DataGrid>
);
}

View file

@ -0,0 +1,16 @@
'use client';
import { Column } from '@umami/react-zen';
import { CohortsDataTable } from './CohortsDataTable';
import { WebsiteControls } from '@/app/(main)/websites/[websiteId]/WebsiteControls';
import { Panel } from '@/components/common/Panel';
export function CohortsPage({ websiteId }) {
return (
<Column gap="3">
<WebsiteControls websiteId={websiteId} allowFilter={false} allowDateFilter={false} />
<Panel>
<CohortsDataTable websiteId={websiteId} />
</Panel>
</Column>
);
}

View file

@ -0,0 +1,41 @@
import { DataTable, DataColumn, Row } from '@umami/react-zen';
import { useMessages, useNavigation } from '@/components/hooks';
import { Empty } from '@/components/common/Empty';
import { DateDistance } from '@/components/common/DateDistance';
import { filtersObjectToArray } from '@/lib/params';
import { CohortEditButton } from '@/app/(main)/websites/[websiteId]/cohorts/CohortEditButton';
import { CohortDeleteButton } from '@/app/(main)/websites/[websiteId]/cohorts/CohortDeleteButton';
export function CohortsTable({ data = [] }) {
const { formatMessage, labels } = useMessages();
const { websiteId } = useNavigation();
if (data.length === 0) {
return <Empty />;
}
return (
<DataTable data={data}>
<DataColumn id="name" label={formatMessage(labels.name)} />
<DataColumn id="created" label={formatMessage(labels.created)}>
{(row: any) => <DateDistance date={new Date(row.createdAt)} />}
</DataColumn>
<DataColumn id="action" align="end" width="100px">
{(row: any) => {
const { id, name, parameters } = row;
return (
<Row>
<CohortEditButton
cohortId={id}
websiteId={websiteId}
filters={filtersObjectToArray(parameters)}
/>
<CohortDeleteButton cohortId={id} websiteId={websiteId} name={name} />
</Row>
);
}}
</DataColumn>
</DataTable>
);
}

View file

@ -0,0 +1,12 @@
import { Metadata } from 'next';
import { CohortsPage } from './CohortsPage';
export default async function ({ params }: { params: Promise<{ websiteId: string }> }) {
const { websiteId } = await params;
return <CohortsPage websiteId={websiteId} />;
}
export const metadata: Metadata = {
title: 'Cohorts',
};

View file

@ -34,7 +34,7 @@ export function SegmentDeleteButton({
};
return (
<ActionButton tooltip={formatMessage(labels.delete)} icon={<Trash />}>
<ActionButton title={formatMessage(labels.delete)} icon={<Trash />}>
<Dialog title={formatMessage(labels.confirm)} style={{ width: 400 }}>
{({ close }) => (
<ConfirmationForm

View file

@ -16,7 +16,7 @@ export function SegmentEditButton({
const { formatMessage, labels } = useMessages();
return (
<ActionButton tooltip={formatMessage(labels.edit)} icon={<Edit />}>
<ActionButton title={formatMessage(labels.edit)} icon={<Edit />}>
<Dialog title={formatMessage(labels.segment)} style={{ width: 800 }}>
{({ close }) => {
return (

View file

@ -6,8 +6,8 @@ export type Config = {
telemetryDisabled: boolean;
trackerScriptName?: string;
updatesDisabled: boolean;
linkDomain?: string;
pixelDomain?: string;
linksUrl?: string;
pixelsUrl?: string;
};
export async function getConfig(): Promise<Config> {
@ -17,7 +17,7 @@ export async function getConfig(): Promise<Config> {
telemetryDisabled: !!process.env.DISABLE_TELEMETRY,
trackerScriptName: process.env.TRACKER_SCRIPT_NAME,
updatesDisabled: !!process.env.DISABLE_UPDATES,
linkDomain: process.env.LINK_DOMAIN,
pixelDomain: process.env.PIXEL_DOMAIN,
linksUrl: process.env.LINKS_URL,
pixelsUrl: process.env.PIXELS_URL,
};
}

View file

@ -2,7 +2,7 @@ import { z } from 'zod';
import { parseRequest } from '@/lib/request';
import { json, unauthorized } from '@/lib/response';
import { pagingParams, searchParams } from '@/lib/schema';
import { canViewAllTeams } from '@/lib/auth';
import { canViewAllTeams } from '@/validations';
import { getTeams } from '@/queries/prisma/team';
export async function GET(request: Request) {
@ -26,11 +26,11 @@ export async function GET(request: Request) {
include: {
_count: {
select: {
teamUser: true,
website: true,
members: true,
websites: true,
},
},
teamUser: {
members: {
select: {
user: {
omit: {

View file

@ -2,7 +2,7 @@ import { z } from 'zod';
import { parseRequest } from '@/lib/request';
import { json, unauthorized } from '@/lib/response';
import { pagingParams, searchParams } from '@/lib/schema';
import { canViewUsers } from '@/lib/auth';
import { canViewUsers } from '@/validations';
import { getUsers } from '@/queries/prisma/user';
export async function GET(request: Request) {
@ -26,7 +26,7 @@ export async function GET(request: Request) {
include: {
_count: {
select: {
websiteUser: {
websites: {
where: { deletedAt: null },
},
},

View file

@ -2,7 +2,7 @@ import { z } from 'zod';
import { parseRequest } from '@/lib/request';
import { json, unauthorized } from '@/lib/response';
import { pagingParams, searchParams } from '@/lib/schema';
import { canViewAllWebsites } from '@/lib/auth';
import { canViewAllWebsites } from '@/validations';
import { getWebsites } from '@/queries/prisma/website';
import { ROLES } from '@/lib/constants';
@ -39,7 +39,7 @@ export async function GET(request: Request) {
deletedAt: null,
},
include: {
teamUser: {
members: {
where: {
role: ROLES.teamOwner,
},

View file

@ -1,11 +1,10 @@
import { z } from 'zod';
import { checkPassword } from '@/lib/auth';
import { createSecureToken } from '@/lib/jwt';
import redis from '@/lib/redis';
import { getUserByUsername } from '@/queries';
import { json, unauthorized } from '@/lib/response';
import { parseRequest } from '@/lib/request';
import { saveAuth } from '@/lib/auth';
import { saveAuth, checkPassword } from '@/lib/auth';
import { secret } from '@/lib/crypto';
import { ROLES } from '@/lib/constants';

View file

@ -1,9 +1,9 @@
import { z } from 'zod';
import { canUpdateWebsite, canDeleteWebsite, canViewWebsite } from '@/lib/auth';
import { canUpdateLink, canDeleteLink, canViewLink } from '@/validations';
import { SHARE_ID_REGEX } from '@/lib/constants';
import { parseRequest } from '@/lib/request';
import { ok, json, unauthorized, serverError } from '@/lib/response';
import { deleteWebsite, getWebsite, updateWebsite } from '@/queries';
import { deleteLink, getLink, updateLink } from '@/queries';
export async function GET(
request: Request,
@ -17,11 +17,11 @@ export async function GET(
const { websiteId } = await params;
if (!(await canViewWebsite(auth, websiteId))) {
if (!(await canViewLink(auth, websiteId))) {
return unauthorized();
}
const website = await getWebsite(websiteId);
const website = await getLink(websiteId);
return json(website);
}
@ -45,12 +45,12 @@ export async function POST(
const { websiteId } = await params;
const { name, domain, shareId } = body;
if (!(await canUpdateWebsite(auth, websiteId))) {
if (!(await canUpdateLink(auth, websiteId))) {
return unauthorized();
}
try {
const website = await updateWebsite(websiteId, { name, domain, shareId });
const website = await updateLink(websiteId, { name, domain, shareId });
return Response.json(website);
} catch (e: any) {
@ -74,11 +74,11 @@ export async function DELETE(
const { websiteId } = await params;
if (!(await canDeleteWebsite(auth, websiteId))) {
if (!(await canDeleteLink(auth, websiteId))) {
return unauthorized();
}
await deleteWebsite(websiteId);
await deleteLink(websiteId);
return ok();
}

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { canCreateTeamWebsite, canCreateWebsite } from '@/lib/auth';
import { canCreateTeamWebsite, canCreateWebsite } from '@/validations';
import { json, unauthorized } from '@/lib/response';
import { uuid } from '@/lib/crypto';
import { getQueryFilters, parseRequest } from '@/lib/request';
@ -20,9 +20,9 @@ export async function GET(request: Request) {
const filters = await getQueryFilters(query);
const result = await getUserLinks(auth.user.id, filters);
const links = await getUserLinks(auth.user.id, filters);
return json(result);
return json(links);
}
export async function POST(request: Request) {

View file

@ -0,0 +1,84 @@
import { z } from 'zod';
import { canUpdateWebsite, canDeleteWebsite, canViewWebsite } from '@/validations';
import { SHARE_ID_REGEX } from '@/lib/constants';
import { parseRequest } from '@/lib/request';
import { ok, json, unauthorized, serverError } from '@/lib/response';
import { deleteWebsite, getWebsite, updateWebsite } from '@/queries';
export async function GET(
request: Request,
{ params }: { params: Promise<{ websiteId: string }> },
) {
const { auth, error } = await parseRequest(request);
if (error) {
return error();
}
const { websiteId } = await params;
if (!(await canViewWebsite(auth, websiteId))) {
return unauthorized();
}
const website = await getWebsite(websiteId);
return json(website);
}
export async function POST(
request: Request,
{ params }: { params: Promise<{ websiteId: string }> },
) {
const schema = z.object({
name: z.string().optional(),
domain: z.string().optional(),
shareId: z.string().regex(SHARE_ID_REGEX).nullable().optional(),
});
const { auth, body, error } = await parseRequest(request, schema);
if (error) {
return error();
}
const { websiteId } = await params;
const { name, domain, shareId } = body;
if (!(await canUpdateWebsite(auth, websiteId))) {
return unauthorized();
}
try {
const website = await updateWebsite(websiteId, { name, domain, shareId });
return Response.json(website);
} catch (e: any) {
if (e.message.includes('Unique constraint') && e.message.includes('share_id')) {
return serverError(new Error('That share ID is already taken.'));
}
return serverError(e);
}
}
export async function DELETE(
request: Request,
{ params }: { params: Promise<{ websiteId: string }> },
) {
const { auth, error } = await parseRequest(request);
if (error) {
return error();
}
const { websiteId } = await params;
if (!(await canDeleteWebsite(auth, websiteId))) {
return unauthorized();
}
await deleteWebsite(websiteId);
return ok();
}

View file

@ -0,0 +1,62 @@
import { z } from 'zod';
import { canCreateTeamWebsite, canCreateWebsite } from '@/validations';
import { json, unauthorized } from '@/lib/response';
import { uuid } from '@/lib/crypto';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { pagingParams, searchParams } from '@/lib/schema';
import { createPixel, getUserLinks } from '@/queries';
export async function GET(request: Request) {
const schema = z.object({
...pagingParams,
...searchParams,
});
const { auth, query, error } = await parseRequest(request, schema);
if (error) {
return error();
}
const filters = await getQueryFilters(query);
const inks = await getUserLinks(auth.user.id, filters);
return json(inks);
}
export async function POST(request: Request) {
const schema = z.object({
name: z.string().max(100),
slug: z.string().max(100),
teamId: z.string().nullable().optional(),
id: z.string().uuid().nullable().optional(),
});
const { auth, body, error } = await parseRequest(request, schema);
if (error) {
return error();
}
const { id, name, slug, teamId } = body;
if ((teamId && !(await canCreateTeamWebsite(auth, teamId))) || !(await canCreateWebsite(auth))) {
return unauthorized();
}
const data: any = {
id: id ?? uuid(),
name,
slug,
teamId,
};
if (!teamId) {
data.userId = auth.user.id;
}
const result = await createPixel(data);
return json(result);
}

View file

@ -1,6 +1,6 @@
import { json, unauthorized } from '@/lib/response';
import { getRealtimeData } from '@/queries';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { startOfMinute, subMinutes } from 'date-fns';
import { REALTIME_RANGE } from '@/lib/constants';
import { parseRequest, getQueryFilters } from '@/lib/request';

View file

@ -1,6 +1,6 @@
import { parseRequest } from '@/lib/request';
import { deleteReport, getReport, updateReport } from '@/queries';
import { canDeleteReport, canUpdateReport, canViewReport } from '@/lib/auth';
import { canDeleteReport, canUpdateReport, canViewReport } from '@/validations';
import { unauthorized, json, notFound, ok } from '@/lib/response';
import { reportSchema } from '@/lib/schema';

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getQueryFilters, parseRequest, setWebsiteDate } from '@/lib/request';
import { json, unauthorized } from '@/lib/response';
import { reportResultSchema } from '@/lib/schema';

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { unauthorized, json } from '@/lib/response';
import { getQueryFilters, parseRequest, setWebsiteDate } from '@/lib/request';
import { BreakdownParameters, getBreakdown } from '@/queries';

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { unauthorized, json } from '@/lib/response';
import { parseRequest, getQueryFilters, setWebsiteDate } from '@/lib/request';
import { FunnelParameters, getFunnel } from '@/queries';

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { unauthorized, json } from '@/lib/response';
import { getQueryFilters, parseRequest, setWebsiteDate } from '@/lib/request';
import { getGoal, GoalParameters } from '@/queries/sql/reports/getGoal';

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { unauthorized, json } from '@/lib/response';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { getJourney } from '@/queries';

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { unauthorized, json } from '@/lib/response';
import { parseRequest, getQueryFilters, setWebsiteDate } from '@/lib/request';
import { getRetention, RetentionParameters } from '@/queries';

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { unauthorized, json } from '@/lib/response';
import { parseRequest, getQueryFilters, setWebsiteDate } from '@/lib/request';
import { reportResultSchema } from '@/lib/schema';

View file

@ -2,7 +2,7 @@ import { z } from 'zod';
import { uuid } from '@/lib/crypto';
import { pagingParams, reportSchema } from '@/lib/schema';
import { parseRequest } from '@/lib/request';
import { canViewWebsite, canUpdateWebsite } from '@/lib/auth';
import { canViewWebsite, canUpdateWebsite } from '@/validations';
import { unauthorized, json } from '@/lib/response';
import { getReports, createReport } from '@/queries';

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { unauthorized, json } from '@/lib/response';
import { getQueryFilters, parseRequest, setWebsiteDate } from '@/lib/request';
import { getUTM, UTMParameters } from '@/queries';

View file

@ -1,6 +1,6 @@
import { z } from 'zod';
import { unauthorized, json } from '@/lib/response';
import { canViewTeam } from '@/lib/auth';
import { canViewTeam } from '@/validations';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { pagingParams, searchParams } from '@/lib/schema';
import { getTeamLinks } from '@/queries';
@ -23,7 +23,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ team
const filters = await getQueryFilters(query);
const websites = await getTeamLinks(teamId, filters);
const links = await getTeamLinks(teamId, filters);
return json(websites);
return json(links);
}

View file

@ -1,6 +1,6 @@
import { z } from 'zod';
import { unauthorized, json } from '@/lib/response';
import { canViewTeam } from '@/lib/auth';
import { canViewTeam } from '@/validations';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { pagingParams, searchParams } from '@/lib/schema';
import { getTeamPixels } from '@/queries';

View file

@ -1,6 +1,6 @@
import { z } from 'zod';
import { unauthorized, json, notFound, ok } from '@/lib/response';
import { canDeleteTeam, canUpdateTeam, canViewTeam } from '@/lib/auth';
import { canDeleteTeam, canUpdateTeam, canViewTeam } from '@/validations';
import { parseRequest } from '@/lib/request';
import { deleteTeam, getTeam, updateTeam } from '@/queries';

View file

@ -1,4 +1,4 @@
import { canDeleteTeamUser, canUpdateTeam } from '@/lib/auth';
import { canDeleteTeamUser, canUpdateTeam } from '@/validations';
import { parseRequest } from '@/lib/request';
import { badRequest, json, ok, unauthorized } from '@/lib/response';
import { deleteTeamUser, getTeamUser, updateTeamUser } from '@/queries';

View file

@ -1,6 +1,6 @@
import { z } from 'zod';
import { unauthorized, json, badRequest } from '@/lib/response';
import { canAddUserToTeam, canViewTeam } from '@/lib/auth';
import { canAddUserToTeam, canViewTeam } from '@/validations';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { pagingParams, teamRoleParam, searchParams } from '@/lib/schema';
import { createTeamUser, getTeamUser, getTeamUsers } from '@/queries';

View file

@ -1,6 +1,6 @@
import { z } from 'zod';
import { unauthorized, json } from '@/lib/response';
import { canViewTeam } from '@/lib/auth';
import { canViewTeam } from '@/validations';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { pagingParams, searchParams } from '@/lib/schema';
import { getTeamWebsites } from '@/queries';

View file

@ -1,6 +1,6 @@
import { z } from 'zod';
import { unauthorized, json, badRequest, notFound } from '@/lib/response';
import { canCreateTeam } from '@/lib/auth';
import { canCreateTeam } from '@/validations';
import { parseRequest } from '@/lib/request';
import { ROLES } from '@/lib/constants';
import { createTeamUser, findTeam, getTeamUser } from '@/queries';

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { getRandomChars } from '@/lib/crypto';
import { unauthorized, json } from '@/lib/response';
import { canCreateTeam } from '@/lib/auth';
import { canCreateTeam } from '@/validations';
import { uuid } from '@/lib/crypto';
import { parseRequest } from '@/lib/request';
import { createTeam } from '@/queries';

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { canUpdateUser, canViewUser, canDeleteUser } from '@/lib/auth';
import { canUpdateUser, canViewUser, canDeleteUser } from '@/validations';
import { getUser, getUserByUsername, updateUser, deleteUser } from '@/queries';
import { json, unauthorized, badRequest, ok } from '@/lib/response';
import { hashPassword } from '@/lib/auth';

View file

@ -1,5 +1,6 @@
import { z } from 'zod';
import { hashPassword, canCreateUser } from '@/lib/auth';
import { hashPassword } from '@/lib/auth';
import { canCreateUser } from '@/validations';
import { ROLES } from '@/lib/constants';
import { uuid } from '@/lib/crypto';
import { parseRequest } from '@/lib/request';

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { json, unauthorized } from '@/lib/response';
import { getActiveVisitors } from '@/queries';
import { parseRequest } from '@/lib/request';
@ -19,7 +19,7 @@ export async function GET(
return unauthorized();
}
const result = await getActiveVisitors(websiteId);
const visitors = await getActiveVisitors(websiteId);
return json(result);
return json(visitors);
}

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getWebsiteDateRange } from '@/queries';
import { json, unauthorized } from '@/lib/response';
import { parseRequest } from '@/lib/request';
@ -19,7 +19,7 @@ export async function GET(
return unauthorized();
}
const result = await getWebsiteDateRange(websiteId);
const dateRange = await getWebsiteDateRange(websiteId);
return json(result);
return json(dateRange);
}

View file

@ -1,6 +1,6 @@
import { parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getEventData } from '@/queries/sql/events/getEventData';
export async function GET(

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getEventDataEvents } from '@/queries/sql/events/getEventDataEvents';
export async function GET(

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getEventDataFields } from '@/queries';
export async function GET(

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getEventDataProperties } from '@/queries';
export async function GET(

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getEventDataStats } from '@/queries';
export async function GET(

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getEventDataValues } from '@/queries';
export async function GET(

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { dateRangeParams, pagingParams, filterParams, searchParams } from '@/lib/schema';
import { getWebsiteEvents } from '@/queries';

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { parseRequest, getQueryFilters } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { filterParams, timezoneParam, unitParam } from '@/lib/schema';
import { getEventStats } from '@/queries';

View file

@ -3,7 +3,7 @@ import JSZip from 'jszip';
import Papa from 'papaparse';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { pagingParams, dateRangeParams } from '@/lib/schema';
import { getEventMetrics, getPageviewMetrics, getSessionMetrics } from '@/queries';

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { EVENT_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { badRequest, json, unauthorized } from '@/lib/response';

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { EVENT_COLUMNS, SESSION_COLUMNS } from '@/lib/constants';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { badRequest, json, unauthorized } from '@/lib/response';

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { dateRangeParams, filterParams } from '@/lib/schema';
import { getCompareDate } from '@/lib/date';

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getReports } from '@/queries';
import { filterParams, pagingParams } from '@/lib/schema';
import { parseRequest } from '@/lib/request';

View file

@ -1,4 +1,4 @@
import { canUpdateWebsite } from '@/lib/auth';
import { canUpdateWebsite } from '@/validations';
import { resetWebsite } from '@/queries';
import { unauthorized, ok } from '@/lib/response';
import { parseRequest } from '@/lib/request';

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { canUpdateWebsite, canDeleteWebsite, canViewWebsite } from '@/lib/auth';
import { canUpdateWebsite, canDeleteWebsite, canViewWebsite } from '@/validations';
import { SHARE_ID_REGEX } from '@/lib/constants';
import { parseRequest } from '@/lib/request';
import { ok, json, unauthorized, serverError } from '@/lib/response';

View file

@ -1,4 +1,4 @@
import { canDeleteWebsite, canUpdateWebsite, canViewWebsite } from '@/lib/auth';
import { canDeleteWebsite, canUpdateWebsite, canViewWebsite } from '@/validations';
import { parseRequest } from '@/lib/request';
import { json, notFound, ok, unauthorized } from '@/lib/response';
import { segmentTypeParam } from '@/lib/schema';

View file

@ -1,4 +1,4 @@
import { canUpdateWebsite, canViewWebsite } from '@/lib/auth';
import { canUpdateWebsite, canViewWebsite } from '@/validations';
import { uuid } from '@/lib/crypto';
import { parseRequest } from '@/lib/request';
import { json, unauthorized } from '@/lib/response';

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getSessionDataProperties } from '@/queries';
export async function GET(

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { json, unauthorized } from '@/lib/response';
import { getSessionDataValues } from '@/queries';

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { parseRequest, getQueryFilters } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getSessionActivity } from '@/queries';
export async function GET(

View file

@ -1,5 +1,5 @@
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getSessionData } from '@/queries';
import { parseRequest } from '@/lib/request';

View file

@ -1,5 +1,5 @@
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { getWebsiteSession } from '@/queries';
import { parseRequest } from '@/lib/request';

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { dateRangeParams, filterParams, pagingParams, searchParams } from '@/lib/schema';
import { getWebsiteSessions } from '@/queries';

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { parseRequest, getQueryFilters } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { filterParams } from '@/lib/schema';
import { getWebsiteSessionStats } from '@/queries';

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { pagingParams, timezoneParam } from '@/lib/schema';
import { getWebsiteSessionsWeekly } from '@/queries';

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
import { parseRequest, getQueryFilters } from '@/lib/request';
import { unauthorized, json } from '@/lib/response';
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { dateRangeParams, filterParams } from '@/lib/schema';
import { getWebsiteStats } from '@/queries';
import { getCompareDate } from '@/lib/date';

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { canTransferWebsiteToTeam, canTransferWebsiteToUser } from '@/lib/auth';
import { canTransferWebsiteToTeam, canTransferWebsiteToUser } from '@/validations';
import { updateWebsite } from '@/queries';
import { parseRequest } from '@/lib/request';
import { badRequest, unauthorized, json } from '@/lib/response';

View file

@ -1,4 +1,4 @@
import { canViewWebsite } from '@/lib/auth';
import { canViewWebsite } from '@/validations';
import { EVENT_COLUMNS, FILTER_COLUMNS, FILTER_GROUPS, SESSION_COLUMNS } from '@/lib/constants';
import { getQueryFilters, parseRequest } from '@/lib/request';
import { badRequest, json, unauthorized } from '@/lib/response';

View file

@ -1,5 +1,5 @@
import { z } from 'zod';
import { canCreateTeamWebsite, canCreateWebsite } from '@/lib/auth';
import { canCreateTeamWebsite, canCreateWebsite } from '@/validations';
import { json, unauthorized } from '@/lib/response';
import { uuid } from '@/lib/crypto';
import { parseRequest } from '@/lib/request';

Some files were not shown because too many files have changed in this diff Show more