Commit 63733aa4 authored by tom's avatar tom

fix watchlist notification toggle

parent c52edbe8
...@@ -45,11 +45,11 @@ const WatchListItem = ({ item, isLoading, onEditClick, onDeleteClick, hasEmail } ...@@ -45,11 +45,11 @@ const WatchListItem = ({ item, isLoading, onEditClick, onDeleteClick, hasEmail }
const showNotificationToast = useCallback((isOn: boolean) => { const showNotificationToast = useCallback((isOn: boolean) => {
toaster.success({ toaster.success({
title: 'Success', title: 'Success',
description: !isOn ? 'Email notification is ON' : 'Email notification is OFF', description: isOn ? 'Email notification is ON' : 'Email notification is OFF',
}); });
}, [ ]); }, [ ]);
const { mutate } = useMutation({ const { mutate } = useMutation<WatchlistAddress>({
mutationFn: () => { mutationFn: () => {
setSwitchDisabled(true); setSwitchDisabled(true);
const body = { ...item, notification_methods: { email: !notificationEnabled } }; const body = { ...item, notification_methods: { email: !notificationEnabled } };
...@@ -57,16 +57,16 @@ const WatchListItem = ({ item, isLoading, onEditClick, onDeleteClick, hasEmail } ...@@ -57,16 +57,16 @@ const WatchListItem = ({ item, isLoading, onEditClick, onDeleteClick, hasEmail }
return apiFetch('watchlist', { return apiFetch('watchlist', {
pathParams: { id: String(item.id) }, pathParams: { id: String(item.id) },
fetchParams: { method: 'PUT', body }, fetchParams: { method: 'PUT', body },
}); }) as Promise<WatchlistAddress>;
}, },
onError: () => { onError: () => {
showErrorToast(); showErrorToast();
setNotificationEnabled(prevState => !prevState); setNotificationEnabled(prevState => !prevState);
setSwitchDisabled(false); setSwitchDisabled(false);
}, },
onSuccess: () => { onSuccess: (data) => {
setSwitchDisabled(false); setSwitchDisabled(false);
showNotificationToast(notificationEnabled); showNotificationToast(data.notification_methods.email);
}, },
}); });
......
...@@ -44,11 +44,11 @@ const WatchlistTableItem = ({ item, isLoading, onEditClick, onDeleteClick, hasEm ...@@ -44,11 +44,11 @@ const WatchlistTableItem = ({ item, isLoading, onEditClick, onDeleteClick, hasEm
const showNotificationToast = useCallback((isOn: boolean) => { const showNotificationToast = useCallback((isOn: boolean) => {
toaster.success({ toaster.success({
title: 'Success', title: 'Success',
description: !isOn ? 'Email notification is ON' : 'Email notification is OFF', description: isOn ? 'Email notification is ON' : 'Email notification is OFF',
}); });
}, [ ]); }, [ ]);
const { mutate } = useMutation({ const { mutate } = useMutation<WatchlistAddress>({
mutationFn: () => { mutationFn: () => {
setSwitchDisabled(true); setSwitchDisabled(true);
const body = { ...item, notification_methods: { email: !notificationEnabled } }; const body = { ...item, notification_methods: { email: !notificationEnabled } };
...@@ -56,16 +56,16 @@ const WatchlistTableItem = ({ item, isLoading, onEditClick, onDeleteClick, hasEm ...@@ -56,16 +56,16 @@ const WatchlistTableItem = ({ item, isLoading, onEditClick, onDeleteClick, hasEm
return apiFetch('watchlist', { return apiFetch('watchlist', {
pathParams: { id: String(item.id) }, pathParams: { id: String(item.id) },
fetchParams: { method: 'PUT', body }, fetchParams: { method: 'PUT', body },
}); }) as Promise<WatchlistAddress>;
}, },
onError: () => { onError: () => {
showErrorToast(); showErrorToast();
setNotificationEnabled(prevState => !prevState); setNotificationEnabled(prevState => !prevState);
setSwitchDisabled(false); setSwitchDisabled(false);
}, },
onSuccess: () => { onSuccess: (data) => {
setSwitchDisabled(false); setSwitchDisabled(false);
showNotificationToast(!notificationEnabled); showNotificationToast(data.notification_methods.email);
}, },
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment