Extend toast notifications to all forms (bills and locations)

- Update billActions to redirect with toast messages
  - billSaved: when bill is created or updated
  - billDeleted: when bill is deleted
- Update locationActions to redirect with toast messages
  - locationSaved: when location is created or updated
  - locationDeleted: when location is deleted
- Enhance MonthLocationList to check for all toast parameters
  - Consolidated success message handling for all operations
  - Clean up all URL parameters after showing toast
- Add translations for all success messages (EN and HR)
  - Bill saved/deleted messages
  - Location saved/deleted messages

User experience: All forms now redirect to home with toast
notifications, providing consistent feedback across the app.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Knee Cola
2025-11-17 19:06:10 +01:00
parent 5bbf80c2ae
commit fa1d04480f
5 changed files with 60 additions and 26 deletions

View File

@@ -6,10 +6,10 @@ import { BillingLocation, YearMonth } from '../db-types';
import { ObjectId } from 'mongodb';
import { withUser } from '@/app/lib/auth';
import { AuthenticatedUser } from '../types/next-auth';
import { gotoHome } from './navigationActions';
import { gotoHome, gotoHomeWithMessage } from './navigationActions';
import { unstable_noStore as noStore } from 'next/cache';
import { IntlTemplateFn } from '@/app/i18n';
import { getTranslations } from "next-intl/server";
import { getTranslations, getLocale } from "next-intl/server";
export type State = {
errors?: {
@@ -221,12 +221,10 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
}
}
if(yearMonth) await gotoHome(yearMonth);
return {
message: null,
errors: undefined,
};
if(yearMonth) {
const locale = await getLocale();
await gotoHomeWithMessage(locale, 'locationSaved');
}
});
@@ -402,10 +400,7 @@ export const deleteLocationById = withUser(async (user:AuthenticatedUser, locati
// Delete only the specific location (current behavior)
await dbClient.collection<BillingLocation>("lokacije").deleteOne({ _id: locationID, userId });
}
await gotoHome(yearMonth);
return {
message: null
};
const locale = await getLocale();
await gotoHomeWithMessage(locale, 'locationDeleted');
})