- 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.
24 lines
739 B
TypeScript
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 }),
|
|
});
|