Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger a reload of forms when an update occured #153

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
65a905f
Add flood number in table
ericboucher Jul 14, 2024
92fdfc2
Update utils.ts
ericboucher Jul 15, 2024
93bb5fd
Initialize select logic
ericboucher Jul 15, 2024
5548dcb
Add dialog to edit flood numbers
ericboucher Jul 15, 2024
91e6962
Update TableDisplay.tsx
ericboucher Jul 15, 2024
d452444
Fix FloodForm type
ericboucher Jul 15, 2024
f6c256e
Merge branch 'new-ui-2024' into flood-number
ericboucher Jul 15, 2024
b0959c5
Add icons
ericboucher Jul 16, 2024
35f596f
Use floating button
ericboucher Jul 16, 2024
a93eae3
Update TableDisplay.tsx
ericboucher Jul 16, 2024
43beb89
Merge branch 'new-ui-2024' into flood-number
ericboucher Jul 16, 2024
5fa39ee
Update TableDisplay.tsx
ericboucher Jul 16, 2024
caa5fc1
Update button
ericboucher Jul 16, 2024
387cb53
Update buttons
ericboucher Jul 16, 2024
1141450
Split into two files
ericboucher Jul 16, 2024
24c301a
Add translations
ericboucher Jul 16, 2024
a41164d
Add a batch patch function for flood numbers
ericboucher Jul 16, 2024
142f378
Update TableDisplay.tsx
ericboucher Jul 16, 2024
de291e0
Shrink label and add margins
ericboucher Jul 17, 2024
8ca858c
Move checkboxes to the Flood column
ericboucher Jul 17, 2024
b400f0a
Move utils
ericboucher Jul 17, 2024
d859e64
Adapt modal
ericboucher Jul 17, 2024
59b9cd4
Adjust styling
ericboucher Jul 17, 2024
c675d79
Update SearchFilters.tsx
ericboucher Jul 17, 2024
eb85057
Add tooltip
ericboucher Jul 17, 2024
48c0952
Update BatchEditControls.tsx
ericboucher Jul 17, 2024
611a60b
Update BatchEditControls.tsx
ericboucher Jul 17, 2024
0cc08c8
Cleanup
ericboucher Jul 17, 2024
e0b0b40
Update BatchEditControls.tsx
ericboucher Jul 17, 2024
cecd270
Trigger a reload of forms when an update occured
ericboucher Jul 17, 2024
059a6b8
Merge branch 'new-ui-2024' into trigger-forms-reload
ericboucher Jul 18, 2024
c674dd4
Merge branch 'new-ui-2024' into trigger-forms-reload
ericboucher Jul 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion apps/frontend/services/api/kobo/useGetForms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DroughtDto, FloodDto, IncidentDto } from '@wfp-dmp/interfaces';
import { useEffect } from 'react';
import useSWR from 'swr';

import { SearchFormData } from 'components/Filters/SearchFilters';
Expand All @@ -19,7 +20,7 @@ export const useGetForms = ({
const inputCommune =
inputRegion.commune.length === 0 ? undefined : inputRegion.commune;

const { data, isLoading } = useSWR(
const { data, isLoading, mutate } = useSWR(
[
ApiRoutes.forms,
inputDisTyps,
Expand Down Expand Up @@ -48,5 +49,21 @@ export const useGetForms = ({
},
);

// Trigger a revalidation when the localStorage changes,
// suggesting form data has been updated.
useEffect(() => {
const handleStorageChange = (event: StorageEvent) => {
if (event.key === 'formDataTrigger') {
void mutate(); // Trigger a revalidation
}
};

window.addEventListener('storage', handleStorageChange);

return () => {
window.removeEventListener('storage', handleStorageChange);
};
}, [mutate]);

return { data, isLoading };
};
2 changes: 2 additions & 0 deletions apps/frontend/services/api/kobo/usePatchForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const usePatchForm = (
// If the edit was successful, update the validation status to "onHold".
if (status === 201) {
await validationTrigger(ValidationStatusValue.onHold);
// Notify other tabs that the form data has been updated.
localStorage.setItem('formDataTrigger', JSON.stringify(new Date()));
}

return status;
Expand Down
3 changes: 3 additions & 0 deletions apps/frontend/services/api/kobo/usePatchValidationStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export const usePatchValidationStatus = (
validationStatusValue: arg,
});

// Notify other tabs that the form data has been updated.
localStorage.setItem('formDataTrigger', JSON.stringify(new Date()));

return updatedValidationStatus;
},
);
Expand Down
Loading