-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use tRPC in group information + better loading states
- Loading branch information
Showing
7 changed files
with
151 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/app/groups/[groupId]/information/group-information.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use client' | ||
|
||
import { Button } from '@/components/ui/button' | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from '@/components/ui/card' | ||
import { Skeleton } from '@/components/ui/skeleton' | ||
import { trpc } from '@/trpc/client' | ||
import { Pencil } from 'lucide-react' | ||
import { useTranslations } from 'next-intl' | ||
import Link from 'next/link' | ||
|
||
export default function GroupInformation({ groupId }: { groupId: string }) { | ||
const t = useTranslations('Information') | ||
const { data, isLoading } = trpc.groups.information.get.useQuery({ groupId }) | ||
|
||
return ( | ||
<> | ||
<Card className="mb-4"> | ||
<CardHeader> | ||
<CardTitle className="flex justify-between"> | ||
<span>{t('title')}</span> | ||
<Button size="icon" asChild className="-mb-12"> | ||
<Link href={`/groups/${groupId}/edit`}> | ||
<Pencil className="w-4 h-4" /> | ||
</Link> | ||
</Button> | ||
</CardTitle> | ||
<CardDescription className="mr-12"> | ||
{t('description')} | ||
</CardDescription> | ||
</CardHeader> | ||
<CardContent className="prose prose-sm sm:prose-base max-w-full whitespace-break-spaces"> | ||
{isLoading || !data ? ( | ||
<div className="py-1 flex flex-col gap-2"> | ||
<Skeleton className="h-3 w-3/4" /> | ||
<Skeleton className="h-3 w-1/2" /> | ||
</div> | ||
) : ( | ||
data.information || ( | ||
<p className="text-muted-foreground text-sm">{t('empty')}</p> | ||
) | ||
)} | ||
</CardContent> | ||
</Card> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,14 @@ | ||
import { cached } from '@/app/cached-functions' | ||
import { Button } from '@/components/ui/button' | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from '@/components/ui/card' | ||
import { Pencil } from 'lucide-react' | ||
import GroupInformation from '@/app/groups/[groupId]/information/group-information' | ||
import { Metadata } from 'next' | ||
import { getTranslations } from 'next-intl/server' | ||
import Link from 'next/link' | ||
import { notFound } from 'next/navigation' | ||
|
||
export const metadata: Metadata = { | ||
title: 'Totals', | ||
title: 'Group Information', | ||
} | ||
|
||
export default async function InformationPage({ | ||
export default function InformationPage({ | ||
params: { groupId }, | ||
}: { | ||
params: { groupId: string } | ||
}) { | ||
const group = await cached.getGroup(groupId) | ||
if (!group) notFound() | ||
|
||
const t = await getTranslations('Information') | ||
|
||
return ( | ||
<> | ||
<Card className="mb-4"> | ||
<CardHeader> | ||
<CardTitle className="flex justify-between"> | ||
<span>{t('title')}</span> | ||
<Button size="icon" asChild className="-mb-12"> | ||
<Link href={`/groups/${groupId}/edit`}> | ||
<Pencil className="w-4 h-4" /> | ||
</Link> | ||
</Button> | ||
</CardTitle> | ||
<CardDescription className="mr-12"> | ||
{t('description')} | ||
</CardDescription> | ||
</CardHeader> | ||
<CardContent className="prose prose-sm sm:prose-base max-w-full whitespace-break-spaces"> | ||
{group.information || ( | ||
<p className="text-muted-foreground italic">{t('empty')}</p> | ||
)} | ||
</CardContent> | ||
</Card> | ||
</> | ||
) | ||
return <GroupInformation groupId={groupId} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { createTRPCRouter } from '@/trpc/init' | ||
import { groupBalancesRouter } from '@/trpc/routers/groups/balances' | ||
import { groupExpensesRouter } from '@/trpc/routers/groups/expenses' | ||
import { groupInformationRouter } from '@/trpc/routers/groups/information' | ||
|
||
export const groupsRouter = createTRPCRouter({ | ||
expenses: groupExpensesRouter, | ||
balances: groupBalancesRouter, | ||
information: groupInformationRouter, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { getGroup } from '@/lib/api' | ||
import { baseProcedure } from '@/trpc/init' | ||
import { TRPCError } from '@trpc/server' | ||
import { z } from 'zod' | ||
|
||
export const getGroupInformationProcedure = baseProcedure | ||
.input( | ||
z.object({ | ||
groupId: z.string().min(1), | ||
}), | ||
) | ||
.query(async ({ input: { groupId } }) => { | ||
const group = await getGroup(groupId) | ||
if (!group) { | ||
throw new TRPCError({ | ||
code: 'NOT_FOUND', | ||
message: 'Group not found.', | ||
}) | ||
} | ||
return { information: group.information ?? '' } | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createTRPCRouter } from '@/trpc/init' | ||
import { getGroupInformationProcedure } from '@/trpc/routers/groups/information/get.procedure' | ||
|
||
export const groupInformationRouter = createTRPCRouter({ | ||
get: getGroupInformationProcedure, | ||
}) |