frontend/containers/Alerts/useCreateTripAlert.tsx (view raw)
1import {useCallback} from 'react';
2import {
3 SetTripAlertMutationVariables,
4 useSetTripAlertMutation,
5} from '../../generated/graphql';
6import {t} from 'i18next';
7import useToastStore from '../../stores/useToastStore';
8
9const useCreateTripAlert = () => {
10 const addToast = useToastStore(s => s.addToast);
11 const [setTripAlertMutation] = useSetTripAlertMutation();
12
13 const handleCreateTripAlert = useCallback(
14 async (variables: SetTripAlertMutationVariables) => {
15 try {
16 await setTripAlertMutation({
17 variables,
18 });
19 addToast(t('alert.create'));
20 } catch (error) {
21 addToast(t('alert.errors.cant_create'));
22 console.error(error);
23 }
24 },
25 [addToast, setTripAlertMutation]
26 );
27
28 return handleCreateTripAlert;
29};
30
31export default useCreateTripAlert;