Files
Account/src/components/NavigateWithToast.tsx
2025-08-20 14:33:15 +03:30

25 lines
668 B
TypeScript

import { useToast, type ToastOptions } from '@rkheftan/harmony-ui';
import React, { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { Navigate } from 'react-router-dom';
export interface NavigateWithToastProps extends ToastOptions {
to: string;
replace?: boolean;
translator?: string;
}
export const NavigateWithToast = (props: NavigateWithToastProps) => {
const { t } = useTranslation(props.translator ?? 'common');
const toast = useToast();
useEffect(() => {
toast({
...props,
message: t(props.message),
});
}, []);
return <Navigate to={props.to} replace={props.replace ? true : false} />;
};