99 lines
2.3 KiB
TypeScript
99 lines
2.3 KiB
TypeScript
import { create } from 'zustand';
|
|
import { devtools, persist } from 'zustand/middleware';
|
|
import { immer } from 'zustand/middleware/immer';
|
|
|
|
export type BakeryType = 'artisan' | 'dependent';
|
|
export type BusinessModel = 'production' | 'retail' | 'hybrid';
|
|
|
|
interface BakeryState {
|
|
// State
|
|
currentTenant: Tenant | null;
|
|
bakeryType: BakeryType;
|
|
businessModel: BusinessModel;
|
|
operatingHours: {
|
|
start: string;
|
|
end: string;
|
|
};
|
|
features: {
|
|
inventory: boolean;
|
|
production: boolean;
|
|
forecasting: boolean;
|
|
analytics: boolean;
|
|
pos: boolean;
|
|
};
|
|
|
|
// Actions
|
|
setTenant: (tenant: Tenant) => void;
|
|
setBakeryType: (type: BakeryType) => void;
|
|
setBusinessModel: (model: BusinessModel) => void;
|
|
updateFeatures: (features: Partial<BakeryState['features']>) => void;
|
|
reset: () => void;
|
|
}
|
|
|
|
interface Tenant {
|
|
id: string;
|
|
name: string;
|
|
subscription_plan: string;
|
|
created_at: string;
|
|
members_count: number;
|
|
}
|
|
|
|
const initialState = {
|
|
currentTenant: null,
|
|
bakeryType: 'artisan' as BakeryType,
|
|
businessModel: 'production' as BusinessModel,
|
|
operatingHours: {
|
|
start: '04:00',
|
|
end: '20:00',
|
|
},
|
|
features: {
|
|
inventory: true,
|
|
production: true,
|
|
forecasting: true,
|
|
analytics: true,
|
|
pos: false,
|
|
},
|
|
};
|
|
|
|
export const useBakeryStore = create<BakeryState>()(
|
|
devtools(
|
|
persist(
|
|
immer((set) => ({
|
|
...initialState,
|
|
|
|
setTenant: (tenant) =>
|
|
set((state) => {
|
|
state.currentTenant = tenant;
|
|
}),
|
|
|
|
setBakeryType: (type) =>
|
|
set((state) => {
|
|
state.bakeryType = type;
|
|
// Adjust features based on bakery type
|
|
if (type === 'artisan') {
|
|
state.features.pos = false;
|
|
state.businessModel = 'production';
|
|
} else if (type === 'dependent') {
|
|
state.features.pos = true;
|
|
state.businessModel = 'retail';
|
|
}
|
|
}),
|
|
|
|
setBusinessModel: (model) =>
|
|
set((state) => {
|
|
state.businessModel = model;
|
|
}),
|
|
|
|
updateFeatures: (features) =>
|
|
set((state) => {
|
|
state.features = { ...state.features, ...features };
|
|
}),
|
|
|
|
reset: () => set(() => initialState),
|
|
})),
|
|
{
|
|
name: 'bakery-storage',
|
|
}
|
|
)
|
|
)
|
|
); |