Update navigation to preserve year/month context in redirects
Modified gotoHomeWithMessage to accept optional yearMonth parameter and
updated location actions to redirect with year/month context after save/delete.
Changes:
- Updated gotoHomeWithMessage to accept yearMonth parameter
- Modified redirect URLs to include year and month query params
- updateOrAddLocation now redirects to /${locale}?year=${year}&month=${month}&locationSaved=true
- deleteLocationById now redirects to /${locale}?year=${year}&month=${month}&locationDeleted=true
- Removed unused gotoHome import from locationActions
This ensures users return to the same month view after location operations,
maintaining context and providing success feedback via URL parameters.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import { BillingLocation, YearMonth } from '../db-types';
|
|||||||
import { ObjectId } from 'mongodb';
|
import { ObjectId } from 'mongodb';
|
||||||
import { withUser } from '@/app/lib/auth';
|
import { withUser } from '@/app/lib/auth';
|
||||||
import { AuthenticatedUser } from '../types/next-auth';
|
import { AuthenticatedUser } from '../types/next-auth';
|
||||||
import { gotoHome, gotoHomeWithMessage } from './navigationActions';
|
import { gotoHomeWithMessage } from './navigationActions';
|
||||||
import { unstable_noStore as noStore } from 'next/cache';
|
import { unstable_noStore as noStore } from 'next/cache';
|
||||||
import { IntlTemplateFn } from '@/app/i18n';
|
import { IntlTemplateFn } from '@/app/i18n';
|
||||||
import { getTranslations, getLocale } from "next-intl/server";
|
import { getTranslations, getLocale } from "next-intl/server";
|
||||||
@@ -276,9 +276,10 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Redirect to home page with year and month parameters, including success message
|
||||||
if (yearMonth) {
|
if (yearMonth) {
|
||||||
const locale = await getLocale();
|
const locale = await getLocale();
|
||||||
await gotoHomeWithMessage(locale, 'locationSaved');
|
await gotoHomeWithMessage(locale, 'locationSaved', yearMonth);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This return is needed for TypeScript, but won't be reached due to redirect
|
// This return is needed for TypeScript, but won't be reached due to redirect
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ export async function gotoHome({year, month}: YearMonth) {
|
|||||||
await gotoUrl(path);
|
await gotoUrl(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function gotoHomeWithMessage(locale: string, message: string) {
|
export async function gotoHomeWithMessage(locale: string, message: string, yearMonth?: YearMonth) {
|
||||||
const path = `/${locale}?${message}=true`;
|
const path = yearMonth
|
||||||
|
? `/${locale}?year=${yearMonth.year}&month=${yearMonth.month}&${message}=true`
|
||||||
|
: `/${locale}?${message}=true`;
|
||||||
await gotoUrl(path);
|
await gotoUrl(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user