zapishis-client/apps/web/stores/lib/slices/services-slice.ts
vchikalkin 64dfec1355 refactor(order-form): update service handling to support multiple services
- Renamed `ServiceSelect` to `ServicesSelect` for clarity.
- Updated state management to handle multiple service IDs instead of a single service ID.
- Adjusted related components (`DateSelect`, `TimeSelect`, `SubmitButton`, and `NextButton`) to accommodate the new services structure.
- Removed the deprecated `service-select.tsx` file and refactored related logic in the order store and API to support multiple services.
- Enhanced error handling in the slots service to validate multiple services correctly.
2025-08-19 19:14:14 +03:00

24 lines
739 B
TypeScript

import { type StateCreator } from 'zustand';
export type ServiceSlice = {
addServiceId: (id: string) => void;
clearServiceIds: () => void;
removeServiceId: (id: string) => void;
serviceIds: string[];
setServiceIds: (ids: string[]) => void;
};
export const createServicesSlice: StateCreator<ServiceSlice> = (set) => ({
addServiceId: (id) =>
set((state) => ({
serviceIds: state.serviceIds.includes(id) ? state.serviceIds : [...state.serviceIds, id],
})),
clearServiceIds: () => set({ serviceIds: [] }),
removeServiceId: (id) =>
set((state) => ({
serviceIds: state.serviceIds.filter((serviceId) => serviceId !== id),
})),
serviceIds: [],
setServiceIds: (ids) => set({ serviceIds: ids }),
});