diff options
Diffstat (limited to 'src/app/(main)/boards')
| -rw-r--r-- | src/app/(main)/boards/BoardAddButton.tsx | 32 | ||||
| -rw-r--r-- | src/app/(main)/boards/BoardAddForm.tsx | 60 | ||||
| -rw-r--r-- | src/app/(main)/boards/BoardsPage.tsx | 17 | ||||
| -rw-r--r-- | src/app/(main)/boards/[boardId]/Board.tsx | 10 | ||||
| -rw-r--r-- | src/app/(main)/boards/[boardId]/page.tsx | 12 | ||||
| -rw-r--r-- | src/app/(main)/boards/page.tsx | 10 |
6 files changed, 141 insertions, 0 deletions
diff --git a/src/app/(main)/boards/BoardAddButton.tsx b/src/app/(main)/boards/BoardAddButton.tsx new file mode 100644 index 0000000..f9f80f4 --- /dev/null +++ b/src/app/(main)/boards/BoardAddButton.tsx @@ -0,0 +1,32 @@ +import { Button, Dialog, DialogTrigger, Icon, Modal, Text, useToast } from '@umami/react-zen'; +import { useMessages, useModified, useNavigation } from '@/components/hooks'; +import { Plus } from '@/components/icons'; +import { BoardAddForm } from './BoardAddForm'; + +export function BoardAddButton() { + 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.addBoard)}</Text> + </Button> + <Modal> + <Dialog title={formatMessage(labels.addBoard)} style={{ width: 400 }}> + {({ close }) => <BoardAddForm teamId={teamId} onSave={handleSave} onClose={close} />} + </Dialog> + </Modal> + </DialogTrigger> + ); +} diff --git a/src/app/(main)/boards/BoardAddForm.tsx b/src/app/(main)/boards/BoardAddForm.tsx new file mode 100644 index 0000000..6471b21 --- /dev/null +++ b/src/app/(main)/boards/BoardAddForm.tsx @@ -0,0 +1,60 @@ +import { Button, Form, FormField, FormSubmitButton, Row, TextField } from '@umami/react-zen'; +import { useMessages, useUpdateQuery } from '@/components/hooks'; +import { DOMAIN_REGEX } from '@/lib/constants'; + +export function BoardAddForm({ + teamId, + onSave, + onClose, +}: { + teamId?: string; + onSave?: () => void; + onClose?: () => void; +}) { + const { formatMessage, labels, messages } = useMessages(); + const { mutateAsync, error, isPending } = useUpdateQuery('/websites', { teamId }); + + const handleSubmit = async (data: any) => { + await mutateAsync(data, { + onSuccess: async () => { + onSave?.(); + onClose?.(); + }, + }); + }; + + return ( + <Form onSubmit={handleSubmit} error={error?.message}> + <FormField + label={formatMessage(labels.name)} + data-test="input-name" + name="name" + rules={{ required: formatMessage(labels.required) }} + > + <TextField autoComplete="off" /> + </FormField> + + <FormField + label={formatMessage(labels.domain)} + data-test="input-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> + ); +} diff --git a/src/app/(main)/boards/BoardsPage.tsx b/src/app/(main)/boards/BoardsPage.tsx new file mode 100644 index 0000000..fa5eb64 --- /dev/null +++ b/src/app/(main)/boards/BoardsPage.tsx @@ -0,0 +1,17 @@ +'use client'; +import { Column } from '@umami/react-zen'; +import { PageBody } from '@/components/common/PageBody'; +import { PageHeader } from '@/components/common/PageHeader'; +import { BoardAddButton } from './BoardAddButton'; + +export function BoardsPage() { + return ( + <PageBody> + <Column margin="2"> + <PageHeader title="My Boards"> + <BoardAddButton /> + </PageHeader> + </Column> + </PageBody> + ); +} diff --git a/src/app/(main)/boards/[boardId]/Board.tsx b/src/app/(main)/boards/[boardId]/Board.tsx new file mode 100644 index 0000000..93f24cc --- /dev/null +++ b/src/app/(main)/boards/[boardId]/Board.tsx @@ -0,0 +1,10 @@ +import { Column, Heading } from '@umami/react-zen'; + +export function Board({ boardId }: { boardId: string }) { + return ( + <Column> + <Heading>Board title</Heading> + <div>{boardId}</div> + </Column> + ); +} diff --git a/src/app/(main)/boards/[boardId]/page.tsx b/src/app/(main)/boards/[boardId]/page.tsx new file mode 100644 index 0000000..2cb076a --- /dev/null +++ b/src/app/(main)/boards/[boardId]/page.tsx @@ -0,0 +1,12 @@ +import type { Metadata } from 'next'; +import { Board } from './Board'; + +export default async function ({ params }: { params: Promise<{ boardId: string }> }) { + const { boardId } = await params; + + return <Board boardId={boardId} />; +} + +export const metadata: Metadata = { + title: 'Board', +}; diff --git a/src/app/(main)/boards/page.tsx b/src/app/(main)/boards/page.tsx new file mode 100644 index 0000000..e8ca662 --- /dev/null +++ b/src/app/(main)/boards/page.tsx @@ -0,0 +1,10 @@ +import type { Metadata } from 'next'; +import { BoardsPage } from './BoardsPage'; + +export default function () { + return <BoardsPage />; +} + +export const metadata: Metadata = { + title: 'Boards', +}; |