mirror of
https://github.com/spliit-app/spliit.git
synced 2026-03-01 02:46:12 +01:00
* Use tRPC for recent groups page * Use tRPC for adding group by URL * Use tRPC for saving visited group * Group context
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
'use client'
|
|
|
|
import { useToast } from '@/components/ui/use-toast'
|
|
import { trpc } from '@/trpc/client'
|
|
import { useTranslations } from 'next-intl'
|
|
import { PropsWithChildren, useEffect } from 'react'
|
|
import { CurrentGroupProvider } from './current-group-context'
|
|
import { GroupHeader } from './group-header'
|
|
import { SaveGroupLocally } from './save-recent-group'
|
|
|
|
export function GroupLayoutClient({
|
|
groupId,
|
|
children,
|
|
}: PropsWithChildren<{ groupId: string }>) {
|
|
const { data, isLoading } = trpc.groups.get.useQuery({ groupId })
|
|
const t = useTranslations('Groups.NotFound')
|
|
const { toast } = useToast()
|
|
|
|
useEffect(() => {
|
|
if (data && !data.group) {
|
|
toast({
|
|
description: t('text'),
|
|
variant: 'destructive',
|
|
})
|
|
}
|
|
}, [data])
|
|
|
|
const props =
|
|
isLoading || !data?.group
|
|
? { isLoading: true as const, groupId, group: undefined }
|
|
: { isLoading: false as const, groupId, group: data.group }
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<CurrentGroupProvider {...props}>
|
|
<GroupHeader />
|
|
{children}
|
|
</CurrentGroupProvider>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<CurrentGroupProvider {...props}>
|
|
<GroupHeader />
|
|
{children}
|
|
<SaveGroupLocally />
|
|
</CurrentGroupProvider>
|
|
)
|
|
}
|