Implement redirect with toast notification on profile save
- Add gotoHomeWithMessage function to navigationActions - Redirect to home page after successful profile save - Display success message in toast notification instead of in-form - Check for profileSaved URL parameter on home page mount - Clean up URL parameter after showing toast - Move success message translation to home-page section - Remove unused success state and message from AccountForm - Remove useEffect import from AccountForm User experience: After saving profile, users are redirected to the familiar home screen and see a toast notification confirming the save. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -9,8 +9,9 @@ import { LocationCard } from "./LocationCard";
|
||||
import { PrintButton } from "./PrintButton";
|
||||
import { BillingLocation, YearMonth } from "../lib/db-types";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { ToastContainer } from 'react-toastify';
|
||||
import { ToastContainer, toast } from 'react-toastify';
|
||||
import 'react-toastify/dist/ReactToastify.css';
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
const getNextYearMonth = (yearMonth:YearMonth) => {
|
||||
const {year, month} = yearMonth;
|
||||
@@ -38,13 +39,26 @@ export const MonthLocationList:React.FC<MonthLocationListProps > = ({
|
||||
|
||||
const router = useRouter();
|
||||
const search = useSearchParams();
|
||||
const t = useTranslations("home-page");
|
||||
|
||||
const initialMonth = search.get('month')
|
||||
|
||||
|
||||
const [expandedMonth, setExpandedMonth] = React.useState<number>(
|
||||
initialMonth ? parseInt(initialMonth as string) : -1 // no month is expanded
|
||||
);
|
||||
|
||||
// Check for profile saved success message
|
||||
React.useEffect(() => {
|
||||
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');
|
||||
const newSearch = params.toString();
|
||||
router.replace(newSearch ? `?${newSearch}` : '/');
|
||||
}
|
||||
}, [search, router, t]);
|
||||
|
||||
if(!availableYears || !months) {
|
||||
const currentYearMonth:YearMonth = {
|
||||
year: new Date().getFullYear(),
|
||||
|
||||
Reference in New Issue
Block a user