From 2d781cbbcbbaa6d6cafcc2610541b51f7b3d132f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20D=C3=B6ll?= Date: Thu, 11 Jan 2024 20:44:07 +0000 Subject: [PATCH] feat: create new team form --- package-lock.json | 1 - packages/app/src/app/teams/layout.tsx | 11 +- packages/app/src/app/teams/new/page.tsx | 22 ++ .../teams/{new => }/new-form.action.tsx | 0 .../src/components/teams/new-form.schema.tsx | 12 ++ .../app/src/components/teams/new-form.tsx | 124 ++++++++++++ .../components/teams/new/new-form.schema.tsx | 18 -- .../app/src/components/teams/new/new-form.tsx | 188 ------------------ packages/app/src/db/models/team.ts | 79 ++++++++ 9 files changed, 238 insertions(+), 217 deletions(-) create mode 100644 packages/app/src/app/teams/new/page.tsx rename packages/app/src/components/teams/{new => }/new-form.action.tsx (100%) create mode 100644 packages/app/src/components/teams/new-form.schema.tsx create mode 100644 packages/app/src/components/teams/new-form.tsx delete mode 100644 packages/app/src/components/teams/new/new-form.schema.tsx delete mode 100644 packages/app/src/components/teams/new/new-form.tsx create mode 100644 packages/app/src/db/models/team.ts diff --git a/package-lock.json b/package-lock.json index a9d6eaab..93e7ede0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19006,7 +19006,6 @@ "swr": "^2.2.4", "tailwind-merge": "^2.2.0", "tailwindcss-animate": "^1.0.7", - "uuid": "^9.0.1", "winston": "^3.11.0", "zod": "^3.22.4" }, diff --git a/packages/app/src/app/teams/layout.tsx b/packages/app/src/app/teams/layout.tsx index deadc813..6de98566 100644 --- a/packages/app/src/app/teams/layout.tsx +++ b/packages/app/src/app/teams/layout.tsx @@ -15,16 +15,7 @@ type PageProps = { export default function Layout({ children }: PageProps) { return ( <> - - - - Teams - Manage teams and team members. - - - -
{children}
-
+ {children} ) } diff --git a/packages/app/src/app/teams/new/page.tsx b/packages/app/src/app/teams/new/page.tsx new file mode 100644 index 00000000..fa1488ee --- /dev/null +++ b/packages/app/src/app/teams/new/page.tsx @@ -0,0 +1,22 @@ +import { SubNav, SubNavTitle, SubNavSubtitle } from '@/components/sub-nav' +import { Section } from '@/components/section' +import { NewTeamForm } from '@/components/teams/new-form' +import { Suspense } from 'react' + +export default function Page() { + return ( + <> + + + New Team + Create a new team. + + +
+ + + +
+ + ) +} diff --git a/packages/app/src/components/teams/new/new-form.action.tsx b/packages/app/src/components/teams/new-form.action.tsx similarity index 100% rename from packages/app/src/components/teams/new/new-form.action.tsx rename to packages/app/src/components/teams/new-form.action.tsx diff --git a/packages/app/src/components/teams/new-form.schema.tsx b/packages/app/src/components/teams/new-form.schema.tsx new file mode 100644 index 00000000..5320e84b --- /dev/null +++ b/packages/app/src/components/teams/new-form.schema.tsx @@ -0,0 +1,12 @@ +import { z } from 'zod' + +export const rhfActionSchema = z.object({ + name: z.string().min(3).max(128), + description: z.string().min(10).max(256).optional(), + contactEmail: z.string().email().optional() +}) + +export type NewTeamFormValues = z.infer +export const defaultValues: Partial = { + name: '' +} diff --git a/packages/app/src/components/teams/new-form.tsx b/packages/app/src/components/teams/new-form.tsx new file mode 100644 index 00000000..a9e2ad43 --- /dev/null +++ b/packages/app/src/components/teams/new-form.tsx @@ -0,0 +1,124 @@ +'use client' + +import { + Form, + FormControl, + FormItem, + FormLabel, + FormDescription, + FormMessage, + FormField +} from '@/components/ui/form' +import { Textarea } from '@/components/ui/textarea' +import { useEffect } from 'react' +import { Input } from '@/components/ui/input' +import { Button } from '@/components/ui/button' +import { zodResolver } from '@hookform/resolvers/zod' +import { rhfActionSchema } from './new-form.schema' +import { rhfAction } from './new-form.action' +import { useForm } from 'react-hook-form' +import { z } from 'zod' +import { useAction } from '@/trpc/client' +import { useRouter } from 'next/navigation' +import type { PropsWithChildren } from 'react' +import type { NewTeamFormValues } from './new-form.schema' +import { defaultValues } from './new-form.schema' + +export type NewTeamFormProps = {} + +export function NewTeamForm({ ...props }: PropsWithChildren) { + const form = useForm({ + resolver: zodResolver(rhfActionSchema), + defaultValues, + mode: 'onChange' + }) + const router = useRouter() + + const mutation = useAction(rhfAction) + const handleSubmit = async (data: z.infer) => + await mutation.mutateAsync({ ...data }) + + useEffect(() => { + if (mutation.status === 'success') { + router.push(`/teams/${mutation.data?.id}`) + } + }) + + return ( + <> +
+ + ( + + +

Name

+
+ + + + Give it a great name. + +
+ )} + /> + + ( + + +

Contact email

+
+ + + + + Add a shared inbox for you team (optional). + + +
+ )} + /> + + ( +
+ + +

Description

+
+ +