mirror of
https://github.com/lux-tel/websites.git
synced 2026-10-30 20:31:36 +00:00
35 lines
692 B
TypeScript
35 lines
692 B
TypeScript
import { toast } from '@session/ui/lib/toast';
|
|
import { useId } from 'react';
|
|
|
|
export type ToastErrorRefetchProps = {
|
|
messages: {
|
|
error: string;
|
|
refetching: string;
|
|
success: string;
|
|
};
|
|
refetch: () => Promise<unknown>;
|
|
toastId?: string;
|
|
};
|
|
|
|
export const toastErrorRefetch = ({
|
|
messages: { error, refetching, success },
|
|
refetch,
|
|
toastId,
|
|
}: ToastErrorRefetchProps) => {
|
|
const id = toastId ?? useId();
|
|
toast.error(error, {
|
|
id,
|
|
action: {
|
|
label: 'Refetch',
|
|
onClick: (event) => {
|
|
event.preventDefault();
|
|
toast.promise(refetch(), {
|
|
id,
|
|
loading: refetching,
|
|
success,
|
|
});
|
|
},
|
|
},
|
|
});
|
|
};
|