Vlad Chikalkin ccfc65ca9b
Fix/bugs features pt 2 (#58)
* refactor(profile): comment out change role feature

* refactor(orders): update OrderServices and ServiceSelect components to utilize ServiceCard, and enhance service fields with duration in GraphQL types

* refactor(schedule): implement forbidden order states to disable editing slots with active orders

* fix(deploy): update SSH configuration to use dynamic port from secrets for improved flexibility

* refactor(api/orders): simplify order creation logic by removing unnecessary validations and improving error handling

* refactor(contact-row): replace role display logic with useIsMaster hook for improved clarity

* refactor(profile/orders-list): update header text from "Общие записи" to "Недавние записи" for better clarity
gql: GetOrders add sort slot.date:desc

* refactor(profile/orders-list): enhance OrderCard component by adding avatarSource prop based on user role

* feat(order-form): implement date selection with event highlighting and monthly view for available time slots

* refactor(i18n/config): update timeZone from 'Europe/Amsterdam' to 'Europe/Moscow'

* refactor(order-form/datetime-select): enhance date selection logic to include slot availability check

* refactor(datetime-format): integrate dayjs timezone support with default Moscow timezone for date and time formatting

* fix(contact-row): replace useIsMaster hook with isCustomerMaster utility for role display logic

* refactor(service-card): replace formatTime with getMinutes for duration display

* refactor(order-datetime): update date and time handling to use datetime_start and datetime_end for improved consistency

* refactor(profile): streamline profile and slot pages by integrating session user retrieval and updating booking logic with BookButton component

* fix(navigation): append query parameter to bottom-nav links and enhance back navigation logic in success page
2025-07-18 17:11:43 +03:00

120 lines
3.0 KiB
TypeScript

'use client';
import { useCustomerQuery } from './customers';
import {
createSlot,
deleteSlot,
getAvailableTimeSlots,
getSlot,
getSlots,
updateSlot,
} from '@/actions/api/slots';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
type UseMasterSlotsVariables = {
filters: Required<
Pick<NonNullable<Parameters<typeof getSlots>[0]['filters']>, 'datetime_start' | 'master'>
>;
};
export const useMasterSlotsQuery = (variables: UseMasterSlotsVariables) => {
const masterId = variables.filters?.master?.documentId?.eq;
const datetimeStart = variables.filters?.datetime_start;
return useQuery({
queryFn: () => getSlots(variables),
queryKey: ['slots', masterId, datetimeStart],
});
};
export const useSlotsQuery = (variables: Parameters<typeof getSlots>[0]) => {
return useQuery({
queryFn: () => getSlots(variables),
queryKey: ['slots', variables],
});
};
export const useSlotQuery = (variables: Parameters<typeof getSlot>[0]) => {
const { documentId } = variables;
return useQuery({
queryFn: () => getSlot(variables),
queryKey: ['slot', documentId],
});
};
export const useAvailableTimeSlotsQuery = (
...variables: Parameters<typeof getAvailableTimeSlots>
) => {
return useQuery({
queryFn: () => getAvailableTimeSlots(...variables),
queryKey: ['available-time-slots', variables],
staleTime: 15 * 1_000,
});
};
export const useSlotMutation = ({
documentId,
}: Pick<Parameters<typeof updateSlot>[0], 'documentId'>) => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ data }: Pick<Parameters<typeof updateSlot>[0], 'data'>) =>
updateSlot({ data, documentId }),
mutationKey: ['slot', 'update', documentId],
onSuccess: () => {
if (documentId) {
queryClient.invalidateQueries({
queryKey: ['slot', documentId],
});
queryClient.invalidateQueries({
queryKey: ['slots'],
});
}
},
});
};
export const useSlotCreate = () => {
const { data: { customer } = {} } = useCustomerQuery();
const masterId = customer?.documentId;
const queryClient = useQueryClient();
return useMutation({
mutationFn: createSlot,
mutationKey: ['slot', 'create'],
onSuccess: (data) => {
queryClient.invalidateQueries({
queryKey: ['slots', masterId],
});
const documentId = data?.createSlot?.documentId;
if (documentId)
queryClient.prefetchQuery({
queryFn: () => getSlot({ documentId }),
queryKey: ['slot', documentId],
});
},
});
};
export const useSlotDelete = ({ documentId }: Parameters<typeof deleteSlot>[0]) => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: () => deleteSlot({ documentId }),
mutationKey: ['slot', 'delete', documentId],
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['slots'],
});
queryClient.invalidateQueries({
queryKey: ['slot', documentId],
});
},
});
};