From 6611e3a187e5398f686449938b7cf1ddbfcb5392 Mon Sep 17 00:00:00 2001 From: Sebastien Castiel Date: Thu, 7 Dec 2023 11:11:53 -0500 Subject: Store amounts as cents --- src/app/groups/[groupId]/balances-list.tsx | 69 +++++++++------------- src/app/groups/[groupId]/expenses/expense-list.tsx | 2 +- src/app/groups/[groupId]/reimbursement-list.tsx | 10 +++- src/app/groups/[groupId]/save-recent-group.tsx | 2 +- 4 files changed, 39 insertions(+), 44 deletions(-) (limited to 'src/app/groups') diff --git a/src/app/groups/[groupId]/balances-list.tsx b/src/app/groups/[groupId]/balances-list.tsx index 26092ec..0e321bb 100644 --- a/src/app/groups/[groupId]/balances-list.tsx +++ b/src/app/groups/[groupId]/balances-list.tsx @@ -15,51 +15,38 @@ export function BalancesList({ balances, participants, currency }: Props) { return (
- {participants.map((participant) => ( -
= 0 || 'flex-row-reverse', - )} - > + {participants.map((participant) => { + const balance = balances[participant.id]?.total ?? 0 + const isLeft = balance >= 0 + return (
= 0 && 'text-right', - )} + key={participant.id} + className={cn('flex', isLeft || 'flex-row-reverse')} > - {participant.name} -
-
= 0 || 'text-right', - )} - > -
- {currency} {(balances[participant.id]?.total ?? 0).toFixed(2)} +
+ {participant.name} +
+
+
+ {currency} {(balance / 100).toFixed(2)} +
+ {balance !== 0 && ( +
+ )}
- {balances[participant.id]?.total !== 0 && ( -
0 - ? 'bg-green-200 left-0 rounded-r-lg border border-green-300' - : 'bg-red-200 right-0 rounded-l-lg border border-red-300', - )} - style={{ - width: - (Math.abs(balances[participant.id]?.total ?? 0) / - maxBalance) * - 100 + - '%', - }} - >
- )}
-
- ))} + ) + })}
) } diff --git a/src/app/groups/[groupId]/expenses/expense-list.tsx b/src/app/groups/[groupId]/expenses/expense-list.tsx index 0c03756..1ba7df7 100644 --- a/src/app/groups/[groupId]/expenses/expense-list.tsx +++ b/src/app/groups/[groupId]/expenses/expense-list.tsx @@ -53,7 +53,7 @@ export function ExpenseList({
- {currency} {expense.amount.toFixed(2)} + {currency} {(expense.amount / 100).toFixed(2)}
- {currency} {reimbursement.amount.toFixed(2)} + {currency} {(reimbursement.amount / 100).toFixed(2)}
))} diff --git a/src/app/groups/[groupId]/save-recent-group.tsx b/src/app/groups/[groupId]/save-recent-group.tsx index e55d7c8..084681a 100644 --- a/src/app/groups/[groupId]/save-recent-group.tsx +++ b/src/app/groups/[groupId]/save-recent-group.tsx @@ -12,7 +12,7 @@ type Props = { export function SaveGroupLocally({ group }: Props) { useEffect(() => { saveRecentGroup(group) - }, []) + }, [group]) return null } -- cgit v1.3