-
-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
129 additions
and
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Totals } from '@/app/groups/[groupId]/stats/totals' | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from '@/components/ui/card' | ||
import { useTranslations } from 'next-intl' | ||
|
||
export function TotalsPageClient({ groupId }: { groupId: string }) { | ||
const t = useTranslations('Stats') | ||
|
||
return ( | ||
<> | ||
<Card className="mb-4"> | ||
<CardHeader> | ||
<CardTitle>{t('Totals.title')}</CardTitle> | ||
<CardDescription>{t('Totals.description')}</CardDescription> | ||
</CardHeader> | ||
<CardContent className="flex flex-col space-y-4"> | ||
<Totals groupId={groupId} /> | ||
</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
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
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
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,35 @@ | ||
import { getGroupExpenses } from '@/lib/api' | ||
import { | ||
getTotalActiveUserPaidFor, | ||
getTotalActiveUserShare, | ||
getTotalGroupSpending, | ||
} from '@/lib/totals' | ||
import { baseProcedure } from '@/trpc/init' | ||
import { z } from 'zod' | ||
|
||
export const getGroupStatsProcedure = baseProcedure | ||
.input( | ||
z.object({ | ||
groupId: z.string().min(1), | ||
participantId: z.string().optional(), | ||
}), | ||
) | ||
.query(async ({ input: { groupId, participantId } }) => { | ||
const expenses = await getGroupExpenses(groupId) | ||
const totalGroupSpendings = getTotalGroupSpending(expenses) | ||
|
||
const totalParticipantSpendings = | ||
participantId !== undefined | ||
? getTotalActiveUserPaidFor(participantId, expenses) | ||
: undefined | ||
const totalParticipantShare = | ||
participantId !== undefined | ||
? getTotalActiveUserShare(participantId, expenses) | ||
: undefined | ||
|
||
return { | ||
totalGroupSpendings, | ||
totalParticipantSpendings, | ||
totalParticipantShare, | ||
} | ||
}) |
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 { getGroupStatsProcedure } from '@/trpc/routers/groups/stats/get.procedure' | ||
|
||
export const groupStatsRouter = createTRPCRouter({ | ||
get: getGroupStatsProcedure, | ||
}) |