fix slots queries
This commit is contained in:
parent
c710537727
commit
a4608ead43
@ -10,6 +10,7 @@ import {
|
||||
updateSlot,
|
||||
} from '@/actions/api/slots';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
export const useSlotsQuery = (variables: Parameters<typeof getSlots>[0]) => {
|
||||
const { data: { customer } = {} } = useCustomerQuery();
|
||||
@ -19,7 +20,7 @@ export const useSlotsQuery = (variables: Parameters<typeof getSlots>[0]) => {
|
||||
|
||||
return useQuery({
|
||||
queryFn: () => getSlots(variables),
|
||||
queryKey: ['slots', { date: date?.toISOString(), masterId }],
|
||||
queryKey: ['slots', masterId, dayjs(date).format('YYYY-MM-DD')],
|
||||
});
|
||||
};
|
||||
|
||||
@ -53,7 +54,9 @@ export const useSlotMutation = ({
|
||||
mutationKey: ['slot', 'update', documentId],
|
||||
onSuccess: () => {
|
||||
if (documentId) {
|
||||
queryClient.invalidateQueries({ queryKey: ['slot', documentId] });
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['slot', documentId],
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -68,13 +71,11 @@ export const useSlotCreate = () => {
|
||||
return useMutation({
|
||||
mutationFn: createSlot,
|
||||
mutationKey: ['slot', 'create'],
|
||||
onSuccess: masterId
|
||||
? (data) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['slots', { date: data?.createSlot?.date?.toISOString(), masterId }],
|
||||
});
|
||||
}
|
||||
: undefined,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['slots', masterId],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@ -88,17 +89,15 @@ export const useSlotDelete = ({ documentId }: Parameters<typeof deleteSlot>[0])
|
||||
mutationKey: ['slot', 'delete', documentId],
|
||||
onSuccess: () => {
|
||||
const date = slot?.date;
|
||||
const masterId = slot?.master;
|
||||
const masterId = slot?.master?.documentId;
|
||||
|
||||
if (date && masterId) {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['slots', { date: date?.toISOString(), masterId }],
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['slots', masterId, dayjs(date).format('YYYY-MM-DD')],
|
||||
});
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['slot', documentId],
|
||||
});
|
||||
}
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['slot', documentId],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@ -19,10 +19,13 @@ export class SlotsService extends BaseService {
|
||||
mutation: GQL.CreateSlotDocument,
|
||||
variables: {
|
||||
...variables,
|
||||
date: formatDate(variables.input.date).db(),
|
||||
master: customer?.documentId,
|
||||
time_end: variables.input.time_end && formatTime(variables.input.time_end).db(),
|
||||
time_start: variables.input.time_start && formatTime(variables.input.time_start).db(),
|
||||
input: {
|
||||
...variables.input,
|
||||
date: formatDate(variables.input.date).db(),
|
||||
master: customer?.documentId,
|
||||
time_end: variables.input.time_end && formatTime(variables.input.time_end).db(),
|
||||
time_start: variables.input.time_start && formatTime(variables.input.time_start).db(),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user