25 lines
668 B
TypeScript
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} />;
|
|
};
|