diff --git a/app/lib/actions/billActions.ts b/app/lib/actions/billActions.ts index 98ae03b..dc58f43 100644 --- a/app/lib/actions/billActions.ts +++ b/app/lib/actions/billActions.ts @@ -6,8 +6,8 @@ import { Bill, BilledTo, BillAttachment, BillingLocation, YearMonth } from '../d import { ObjectId } from 'mongodb'; import { withUser } from '@/app/lib/auth'; import { AuthenticatedUser } from '../types/next-auth'; -import { gotoHome } from './navigationActions'; -import { getTranslations } from "next-intl/server"; +import { gotoHome, gotoHomeWithMessage } from './navigationActions'; +import { getTranslations, getLocale } from "next-intl/server"; import { IntlTemplateFn } from '@/app/i18n'; export type State = { @@ -278,8 +278,9 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI } } } - if(billYear && billMonth ) { - await gotoHome({ year: billYear, month: billMonth }); + if(billYear && billMonth) { + const locale = await getLocale(); + await gotoHomeWithMessage(locale, 'billSaved'); } }) /* @@ -445,7 +446,7 @@ export const deleteBillById = withUser(async (user:AuthenticatedUser, locationID } }); } - - await gotoHome({year, month}); - return { message: null }; + + const locale = await getLocale(); + await gotoHomeWithMessage(locale, 'billDeleted'); }); \ No newline at end of file diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index be3fc07..d85c9f3 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -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("lokacije").deleteOne({ _id: locationID, userId }); } - - await gotoHome(yearMonth); - - return { - message: null - }; + + const locale = await getLocale(); + await gotoHomeWithMessage(locale, 'locationDeleted'); }) \ No newline at end of file diff --git a/app/ui/MonthLocationList.tsx b/app/ui/MonthLocationList.tsx index 3a2c9cb..25533b8 100644 --- a/app/ui/MonthLocationList.tsx +++ b/app/ui/MonthLocationList.tsx @@ -47,13 +47,43 @@ export const MonthLocationList:React.FC = ({ initialMonth ? parseInt(initialMonth as string) : -1 // no month is expanded ); - // Check for profile saved success message + // Check for success messages React.useEffect(() => { + const params = new URLSearchParams(search.toString()); + let messageShown = false; + if (search.get('profileSaved') === 'true') { toast.success(t("profile-saved-message"), { theme: "dark" }); - // Clean up URL parameter - const params = new URLSearchParams(search.toString()); params.delete('profileSaved'); + messageShown = true; + } + + if (search.get('billSaved') === 'true') { + toast.success(t("bill-saved-message"), { theme: "dark" }); + params.delete('billSaved'); + messageShown = true; + } + + if (search.get('billDeleted') === 'true') { + toast.success(t("bill-deleted-message"), { theme: "dark" }); + params.delete('billDeleted'); + messageShown = true; + } + + if (search.get('locationSaved') === 'true') { + toast.success(t("location-saved-message"), { theme: "dark" }); + params.delete('locationSaved'); + messageShown = true; + } + + if (search.get('locationDeleted') === 'true') { + toast.success(t("location-deleted-message"), { theme: "dark" }); + params.delete('locationDeleted'); + messageShown = true; + } + + // Clean up URL parameters if any message was shown + if (messageShown) { const newSearch = params.toString(); router.replace(newSearch ? `?${newSearch}` : '/'); } diff --git a/messages/en.json b/messages/en.json index 9aa61b2..fca9fc4 100644 --- a/messages/en.json +++ b/messages/en.json @@ -74,7 +74,11 @@ "empty-state-title": "No Barcode Data Found", "empty-state-message": "No bills with 2D barcodes found for {yearMonth}" }, - "profile-saved-message": "Profile updated successfully" + "profile-saved-message": "Profile updated successfully", + "bill-saved-message": "Bill saved successfully", + "bill-deleted-message": "Bill deleted successfully", + "location-saved-message": "Location saved successfully", + "location-deleted-message": "Location deleted successfully" }, "bill-delete-form": { "text": "Please confirm deletion of bill \"{bill_name}\" at \"{location_name}\".", diff --git a/messages/hr.json b/messages/hr.json index 7ecad93..23f407a 100644 --- a/messages/hr.json +++ b/messages/hr.json @@ -74,7 +74,11 @@ "empty-state-title": "Nema Podataka o Barkodovima", "empty-state-message": "Nema računa s 2D barkodovima za {yearMonth}" }, - "profile-saved-message": "Profil uspješno ažuriran" + "profile-saved-message": "Profil uspješno ažuriran", + "bill-saved-message": "Račun uspješno spremljen", + "bill-deleted-message": "Račun uspješno obrisan", + "location-saved-message": "Nekretnina uspješno spremljena", + "location-deleted-message": "Nekretnina uspješno obrisana" }, "bill-delete-form": { "text": "Molim potvrdi brisanje računa \"{bill_name}\" koji pripada nekretnini \"{location_name}\".",