const updateDiary = async (updatedDiary: Day[], userId: string) => {
const { error } = await supabase
.from('current_diaries')
.update({ days: updatedDiary })
.eq('uid', userId);
// this throws unhandled error
if (error) {
throw new Error(`${error.message}: ${error.details}`);
}
};
export function useUpdateDiary() {
return useMutation({
mutationFn: async ({
updatedDiary,
userId
}: {
updatedDiary: Day[];
userId: string;
}) => {
updateDiary(updatedDiary, userId);
},
onSuccess: () => {
toast.success('Day updated');
},
// this is not called on error
onError: () => {
toast.error(
"We couldn't save your diary please check your internet connection!"
);
}
});
}
const updateDiary = async (updatedDiary: Day[], userId: string) => {
const { error } = await supabase
.from('current_diaries')
.update({ days: updatedDiary })
.eq('uid', userId);
// this throws unhandled error
if (error) {
throw new Error(`${error.message}: ${error.details}`);
}
};
export function useUpdateDiary() {
return useMutation({
mutationFn: async ({
updatedDiary,
userId
}: {
updatedDiary: Day[];
userId: string;
}) => {
updateDiary(updatedDiary, userId);
},
onSuccess: () => {
toast.success('Day updated');
},
// this is not called on error
onError: () => {
toast.error(
"We couldn't save your diary please check your internet connection!"
);
}
});
}