Skip to content

Commit

Permalink
fix(in-app): stale tickets result
Browse files Browse the repository at this point in the history
  • Loading branch information
sdjdd committed Dec 14, 2023
1 parent 32c023a commit a9d2617
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion in-app/v1/src/App/Tickets/New/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo } from 'react';
import { Link, useLocation, useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { useMutation } from 'react-query';
import { useMutation, useQueryClient } from 'react-query';
import { Helmet } from 'react-helmet-async';
import { pick, cloneDeep } from 'lodash-es';

Expand Down Expand Up @@ -180,9 +180,16 @@ export function NewTicket() {
}
}, [categories, category_id]);

const queryClient = useQueryClient();

const { mutateAsync: submit, isLoading: submitting } = useMutation({
mutationFn: createTicket,
onSuccess: (ticketId: string) => {
// In react-query@3, useInfiniteQuery always returns stale data
// Clear tickets query cache manaully to prevent this
const cache = queryClient.getQueryCache();
cache.findAll(['tickets']).forEach((query) => cache.remove(query));

navigate({ pathname: '', search }, { replace: false, state: ticketId });
},
});
Expand Down

0 comments on commit a9d2617

Please sign in to comment.