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

fix(datatrak): RN-1330: Fix logout request cache clearing #5865

Merged
merged 4 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions packages/datatrak-web/src/api/mutations/useLogout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const useLogout = () => {
const queryClient = useQueryClient();

return useMutation('logout', () => post('logout'), {
onSuccess: () => {
queryClient.invalidateQueries();
onSuccess: async () => {
await queryClient.resetQueries();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalidateQueries triggers re-fetches of the data instantly which can lead to race conditions. removeQueries or clear doesn't work because the app no longer fetches data for queries once they are removed. ResetQueries puts the queries back to their initial state so it acts like a fresh login after logout.

removeTaskFilterSetting('all_assignees_tasks');
removeTaskFilterSetting('show_completed_tasks');
removeTaskFilterSetting('show_cancelled_tasks');
Expand Down
1 change: 1 addition & 0 deletions packages/datatrak-web/src/components/Tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const ButtonWrapper = styled(Wrapper).attrs({
flex-direction: row;
position: relative;
justify-content: flex-start;
align-items: flex-start;

svg {
margin-right: 0.4rem;
Expand Down
7 changes: 6 additions & 1 deletion packages/datatrak-web/src/features/SurveyResponseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ export const SurveyResponseModal = () => {

const surveyResponseId = urlSearchParams.get('responseId');

const { data: surveyResponse, isLoading, error, isFetched } = useSurveyResponse(surveyResponseId);
const {
data: surveyResponse,
isLoading,
error,
isFetched,
} = useSurveyResponse(surveyResponseId, { meta: { applyCustomErrorHandling: true } });

const isLoadingSurveyResponse = isLoading || !isFetched;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { LoadingContainer } from '@tupaia/ui-components';
import { useEditTask, useSurveyResponse } from '../../../api';
import { displayDate } from '../../../utils';
import { Button as BaseButton, SurveyTickIcon, Tile } from '../../../components';
import { SingleTaskResponse } from '../../../types';
import { SingleTaskResponse } from '../../../types';
import { RepeatScheduleInput } from '../RepeatScheduleInput';
import { DueDatePicker } from '../DueDatePicker';
import { AssigneeInput } from '../AssigneeInput';
Expand Down Expand Up @@ -114,7 +114,9 @@ const SectionHeading = styled(Typography).attrs({
`;

const InitialRequest = ({ initialRequestId }) => {
const { data: surveyResponse, isLoading } = useSurveyResponse(initialRequestId);
const { data: surveyResponse, isLoading } = useSurveyResponse(initialRequestId, {
meta: { applyCustomErrorHandling: true },
});
if (isLoading || !surveyResponse) {
return null;
}
Expand Down
1 change: 1 addition & 0 deletions packages/datatrak-web/src/features/Tasks/TaskTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const TileContent = styled.div`
align-items: center;

> span {
text-wrap: nowrap;
margin-inline-end: 0.6rem;
}
`;
Expand Down