mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 18:34:09 +00:00
fix(client): cache a visit note saved from the place dialog
The place dialog stopped reloading the days after a save, so the new visit note only reached the Zustand store. Nothing wrote it to Dexie, the tab never sees its own assignment:updated echo, and the time save before it cached the server row with the old note. A trip reopened offline then showed the old note until the next full sync. The note now goes through assignmentRepo.setNotes, which caches the saved row on its day online and queues the write behind any other write of the same visit offline, like setTimes does. A new store action applies it, so the page hook no longer patches the store by hand. usePlaceEdits drops its direct API import and leaves the offline baseline.
This commit is contained in:
@@ -427,6 +427,46 @@ describe('assignmentsSlice', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('setAssignmentNotes', () => {
|
||||
const visit = () => buildAssignment({ id: 5, day_id: 1, place_id: 10, notes: 'old', assignment_time: '09:00' });
|
||||
|
||||
it('FE-ASSIGN-030: shows the note at once and keeps the one the server saved', async () => {
|
||||
seedStore(useTripStore, { assignments: { '1': [visit()] } });
|
||||
let seen: unknown;
|
||||
server.use(
|
||||
http.put('/api/trips/1/assignments/5/notes', async ({ request }) => {
|
||||
seen = await request.json();
|
||||
expect(useTripStore.getState().assignments['1'][0].notes).toBe('Bring cash');
|
||||
return HttpResponse.json({ assignment: { ...visit(), notes: 'Bring cash' } });
|
||||
}),
|
||||
);
|
||||
|
||||
await useTripStore.getState().setAssignmentNotes(1, 1, 5, 'Bring cash');
|
||||
|
||||
expect(seen).toEqual({ notes: 'Bring cash' });
|
||||
expect(useTripStore.getState().assignments['1'][0]).toMatchObject({ notes: 'Bring cash', assignment_time: '09:00' });
|
||||
});
|
||||
|
||||
it('FE-ASSIGN-031: a refused write puts the old note back', async () => {
|
||||
seedStore(useTripStore, { assignments: { '1': [visit()] } });
|
||||
server.use(http.put('/api/trips/1/assignments/5/notes', () => HttpResponse.json({ error: 'no' }, { status: 403 })));
|
||||
|
||||
await expect(useTripStore.getState().setAssignmentNotes(1, 1, 5, null)).rejects.toBeTruthy();
|
||||
|
||||
expect(useTripStore.getState().assignments['1'][0].notes).toBe('old');
|
||||
});
|
||||
|
||||
it('FE-ASSIGN-032: a visit it cannot find, or one not yet saved, is left alone', async () => {
|
||||
const unsaved = { ...visit(), id: -3 };
|
||||
seedStore(useTripStore, { assignments: { '1': [unsaved] } });
|
||||
|
||||
await useTripStore.getState().setAssignmentNotes(1, 1, 5, 'x');
|
||||
await useTripStore.getState().setAssignmentNotes(1, 1, -3, 'x');
|
||||
|
||||
expect(useTripStore.getState().assignments['1'][0]).toEqual(unsaved);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setAssignmentTimes', () => {
|
||||
// The pool place still carries an End of its own, which the visit shows once its
|
||||
// own override is gone, exactly as a fresh read of the day would.
|
||||
|
||||
Reference in New Issue
Block a user