mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
fix(records): offer Undo after deleting a vaccination, visit or entry
Deleting a vaccination, a doctor visit or an address-book entry closed the sheet with no way back, although all three are soft deletes with a documented restore route. The vaccination hook had a restore mutation nobody called; visits and the address book had none. The two hooks gain a restore mutation, and each delete now confirms with an Undo toast, the same pattern the illness episode uses. The Undo runs after the sheet has closed, so it awaits the restore itself and the hook's own onSuccess refreshes the lists, instead of relying on callbacks a closed sheet never receives. Restoring an address-book entry brings the entry back, not the links the delete cleared on the visits that named it. The three new success toasts are pinned in the success-affordance guard.
This commit is contained in:
1 parent
f761500247
commit
d204b4344b
18 files changed
+259
-46
No files matched your search
@@ -19,7 +19,13 @@ import {
|
||||
useQueryClient,
|
||||
} from "@tanstack/react-query";
|
||||
|
||||
import { apiDelete, apiGet, apiGetList, apiPatch } from "@/lib/api/api-fetch";
|
||||
import {
|
||||
apiDelete,
|
||||
apiGet,
|
||||
apiGetList,
|
||||
apiPatch,
|
||||
apiPost,
|
||||
} from "@/lib/api/api-fetch";
|
||||
import { useIdempotentPost } from "@/lib/api/use-idempotent-post";
|
||||
import { invalidateReminderReads } from "@/hooks/use-measurement-reminders";
|
||||
import {
|
||||
@@ -192,5 +198,13 @@ export function useEncounterMutations() {
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
return { create, update, remove };
|
||||
// The Undo of a delete. A restored visit re-anchors its reminder only
|
||||
// while its date is still ahead.
|
||||
const restore = useMutation({
|
||||
mutationKey: queryKeys.encounterRestore(),
|
||||
mutationFn: (id: string) => apiPost<Encounter>(`${BASE}/${id}/restore`, {}),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
return { create, update, remove, restore };
|
||||
}
|
||||
@@ -91,5 +91,14 @@ export function usePractitionerMutations() {
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
return { create, update, remove };
|
||||
// The Undo of a delete. It brings the entry back, not the links the
|
||||
// delete cleared on the visits that named it.
|
||||
const restore = useMutation({
|
||||
mutationKey: queryKeys.practitionerRestore(),
|
||||
mutationFn: (id: string) =>
|
||||
apiPost<Practitioner>(`${BASE}/${id}/restore`, {}),
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
return { create, update, remove, restore };
|
||||
}
|
||||
Reference in new issue
Block a user