Skip to content

Commit 14ad16c

Browse files
committed
401 fix back navigation (#423)
* Fix back navigation on each add button * Add mechanism to keep adding expenses instead of going back to activity
1 parent 5ea1e14 commit 14ad16c

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/components/AddExpense/AddExpensePage.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,24 @@ export const AddOrEditExpensePage: React.FC<{
120120
onSuccess: (d) => {
121121
if (d) {
122122
const id = d?.id ?? expenseId;
123-
router
124-
.push(group?.id ? `/groups/${group.id}/expenses/${id}` : `/expenses/${id}`)
123+
124+
let navPromise: () => Promise<any> = () => Promise.resolve(true);
125+
126+
const { friendId, groupId } = router.query;
127+
128+
if (friendId && !groupId) {
129+
navPromise = () => router.push(`/balances/${friendId as string}/expenses/${id}`);
130+
} else if (groupId) {
131+
navPromise = () => router.push(`/groups/${groupId as string}/expenses/${id}`);
132+
} else {
133+
navPromise = () => router.push(`/expenses/${id}?keepAdding=1`);
134+
}
135+
136+
if (expenseId) {
137+
navPromise = async () => router.back();
138+
}
139+
140+
navPromise()
125141
.then(() => resetState())
126142
.catch(console.error);
127143
}
@@ -163,10 +179,14 @@ export const AddOrEditExpensePage: React.FC<{
163179
[setDescription],
164180
);
165181

182+
const onBackButtonPress = useCallback(() => {
183+
router.back();
184+
}, [router]);
185+
166186
return (
167187
<div className="flex flex-col gap-4">
168188
<div className="flex items-center justify-between">
169-
<Button variant="ghost" className="text-primary px-0" onClick={router.back}>
189+
<Button variant="ghost" className="text-primary px-0" onClick={onBackButtonPress}>
170190
{t('ui.actions.cancel', { ns: 'common' })}
171191
</Button>
172192
<div className="text-center">

src/pages/expenses/[expenseId].tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const ExpensesPage: NextPageWithUser<{ storagePublicUrl?: string }> = ({
2121
const { t } = useTranslation('expense_details');
2222
const router = useRouter();
2323
const expenseId = router.query.expenseId as string;
24+
const keepAdding = !!router.query.keepAdding;
2425

2526
const expenseQuery = api.expense.getExpenseDetails.useQuery({ expenseId });
2627

@@ -32,7 +33,7 @@ const ExpensesPage: NextPageWithUser<{ storagePublicUrl?: string }> = ({
3233
<MainLayout
3334
title={
3435
<div className="flex items-center gap-2">
35-
<Link href="/activity">
36+
<Link href={keepAdding ? '/add' : '/activity'}>
3637
<ChevronLeftIcon className="mr-1 h-6 w-6" />
3738
</Link>
3839
<p className="text-[16px] font-normal">{t('ui.expense_details', { ns: 'common' })}</p>

0 commit comments

Comments
 (0)