mirror of
https://github.com/umami-software/umami.git
synced 2026-02-14 01:25:37 +01:00
New schema for pixels and links.
This commit is contained in:
parent
c60e8b3d23
commit
88639dfe83
67 changed files with 993 additions and 208 deletions
32
src/app/(main)/pixels/PixelAddButton.tsx
Normal file
32
src/app/(main)/pixels/PixelAddButton.tsx
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { useMessages, useModified, useNavigation } from '@/components/hooks';
|
||||
import { Button, Icon, Modal, Dialog, DialogTrigger, Text, useToast } from '@umami/react-zen';
|
||||
import { Plus } from '@/components/icons';
|
||||
import { PixelAddForm } from './PixelAddForm';
|
||||
|
||||
export function PixelAddButton() {
|
||||
const { formatMessage, labels, messages } = useMessages();
|
||||
const { toast } = useToast();
|
||||
const { touch } = useModified();
|
||||
const { teamId } = useNavigation();
|
||||
|
||||
const handleSave = async () => {
|
||||
toast(formatMessage(messages.saved));
|
||||
touch('boards');
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogTrigger>
|
||||
<Button data-test="button-website-add" variant="primary">
|
||||
<Icon>
|
||||
<Plus />
|
||||
</Icon>
|
||||
<Text>{formatMessage(labels.addPixel)}</Text>
|
||||
</Button>
|
||||
<Modal>
|
||||
<Dialog title={formatMessage(labels.addPixel)} style={{ width: 400 }}>
|
||||
{({ close }) => <PixelAddForm teamId={teamId} onSave={handleSave} onClose={close} />}
|
||||
</Dialog>
|
||||
</Modal>
|
||||
</DialogTrigger>
|
||||
);
|
||||
}
|
||||
62
src/app/(main)/pixels/PixelAddForm.tsx
Normal file
62
src/app/(main)/pixels/PixelAddForm.tsx
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
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>
|
||||
);
|
||||
}
|
||||
|
|
@ -2,8 +2,7 @@
|
|||
import { PageBody } from '@/components/common/PageBody';
|
||||
import { Column } from '@umami/react-zen';
|
||||
import { PageHeader } from '@/components/common/PageHeader';
|
||||
import { BoardAddButton } from '@/app/(main)/boards/BoardAddButton';
|
||||
import Link from 'next/link';
|
||||
import { PixelAddButton } from './PixelAddButton';
|
||||
import { useMessages } from '@/components/hooks';
|
||||
|
||||
export function PixelsPage() {
|
||||
|
|
@ -13,11 +12,8 @@ export function PixelsPage() {
|
|||
<PageBody>
|
||||
<Column>
|
||||
<PageHeader title={formatMessage(labels.pixels)}>
|
||||
<BoardAddButton />
|
||||
<PixelAddButton />
|
||||
</PageHeader>
|
||||
<Link href="/teams/3a97e34a-7f9d-4de2-8754-ed81714b528d/boards/86d4095c-a2a8-4fc8-9521-103e858e2b41">
|
||||
Board 1
|
||||
</Link>
|
||||
</Column>
|
||||
</PageBody>
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue