diff --git a/packages/app/src/app/account/layout.tsx b/packages/app/src/app/account/layout.tsx index 9c31c88c..0ed9063b 100644 --- a/packages/app/src/app/account/layout.tsx +++ b/packages/app/src/app/account/layout.tsx @@ -7,10 +7,9 @@ import { import { SidebarNav } from '@/components/sidebar-nav' import { Main } from '@/components/main' import DefaultLayout from '@/components/default-layout' +import { PropsWithChildren } from 'react' -type PageProps = { - children?: React.ReactNode -} +type PageProps = {} const sidebarNavItems = [ { @@ -20,10 +19,14 @@ const sidebarNavItems = [ { title: 'Appearance', href: '/account/appearance' + }, + { + title: 'Teams', + href: '/account/teams' } ] -export default function Layout({ children }: PageProps) { +export default function Layout({ children }: PropsWithChildren) { return ( <> diff --git a/packages/app/src/app/account/teams/page.tsx b/packages/app/src/app/account/teams/page.tsx new file mode 100644 index 00000000..1c116d09 --- /dev/null +++ b/packages/app/src/app/account/teams/page.tsx @@ -0,0 +1,13 @@ +import { Separator } from '@/components/ui/separator' + +export default function Page() { + return ( +
+
+

Teams

+

+
+ +
+ ) +} diff --git a/packages/app/src/components/team-switcher.tsx b/packages/app/src/components/team-switcher.tsx index 79cf211f..be3a41a1 100644 --- a/packages/app/src/components/team-switcher.tsx +++ b/packages/app/src/components/team-switcher.tsx @@ -1,16 +1,26 @@ 'use client' import * as React from 'react' -import { - CaretSortIcon, - CheckIcon, - PlusCircledIcon, - PersonIcon -} from '@radix-ui/react-icons' - +import { CaretSortIcon, CheckIcon } from '@radix-ui/react-icons' import { cn } from '@/lib/utils' import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' import { Button } from '@/components/ui/button' +import { zodResolver } from '@hookform/resolvers/zod' +import { NewTeamFormValues } from '@/components/teams/new-form.schema' +import { defaultValues } from '@/components/teams/new-form.schema' +import { TeamsCreateSchema } from '@/server/routers/schemas/teams' +import { useAction } from '@/trpc/client' +import { rhfAction } from '@/components/teams/new-form.action' +import { Textarea } from '@/components/ui/textarea' +import { + Form, + FormControl, + FormItem, + FormLabel, + FormDescription, + FormMessage, + FormField +} from '@/components/ui/form' import { Command, CommandEmpty, @@ -29,6 +39,7 @@ import { DialogTitle, DialogTrigger } from '@/components/ui/dialog' +import { useForm } from 'react-hook-form' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { @@ -44,17 +55,9 @@ import { SelectValue } from '@/components/ui/select' import { useRouter } from 'next/navigation' +import { api } from '@/trpc/client' const groups = [ - { - label: 'Personal Account', - teams: [ - { - label: 'Alicia Koch', - value: 'personal' - } - ] - }, { label: 'Teams', teams: [ @@ -77,6 +80,13 @@ type PopoverTriggerProps = React.ComponentPropsWithoutRef interface TeamSwitcherProps extends PopoverTriggerProps { } export default function TeamSwitcher({ className }: TeamSwitcherProps) { + const me = React.use(api.me.query()) + const user = React.use(api.users.get.query()) + const teams = React.useMemo( + () => user?.teams?.map(team => ({ label: team.name, value: team.id })), + [user?.teams] + ) + const [open, setOpen] = React.useState(false) const [showNewTeamDialog, setShowNewTeamDialog] = React.useState(false) const [selectedTeam, setSelectedTeam] = React.useState( @@ -84,6 +94,22 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) { ) const router = useRouter() + const form = useForm({ + resolver: zodResolver(TeamsCreateSchema), + defaultValues, + mode: 'onChange' + }) + + const mutation = useAction(rhfAction) + const handleSubmit = async (data: NewTeamFormValues) => + await mutation.mutateAsync({ ...data }) + + React.useEffect(() => { + if (mutation.status === 'success') { + setShowNewTeamDialog(false) + } + }, [showNewTeamDialog, mutation.status]) + return ( @@ -97,8 +123,8 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) { > SC @@ -111,6 +137,26 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) { No team found. + + + + + SC + + {me?.user.name} + + + + {teams?.map(team => ( + + {team.label} + + ))} + {groups.map(group => ( {group.teams.map(team => ( @@ -157,7 +203,7 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) { Create Team - router.push('/teams')}> + router.push('/account/teams')}> Manage Teams @@ -172,42 +218,89 @@ export default function TeamSwitcher({ className }: TeamSwitcherProps) { Add a new team to manage products and customers. -
-
-
- - -
-
- - -
-
-
- - - - +
+ + ( + + +

Name

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

Contact email

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

Description

+
+ +