Initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { create } from 'zustand'
|
||||
|
||||
const MAX_COMPARE_ITEMS = 3
|
||||
|
||||
interface CompareState {
|
||||
compareTray: string[]
|
||||
addToCompare: (propertyId: string) => void
|
||||
removeFromCompare: (propertyId: string) => void
|
||||
clearCompare: () => void
|
||||
isInCompare: (propertyId: string) => boolean
|
||||
isFull: () => boolean
|
||||
}
|
||||
|
||||
export const useCompareStore = create<CompareState>((set, get) => ({
|
||||
compareTray: [],
|
||||
addToCompare: (propertyId) =>
|
||||
set((state) => {
|
||||
if (state.compareTray.length >= MAX_COMPARE_ITEMS) return state
|
||||
if (state.compareTray.includes(propertyId)) return state
|
||||
return { compareTray: [...state.compareTray, propertyId] }
|
||||
}),
|
||||
removeFromCompare: (propertyId) =>
|
||||
set((state) => ({ compareTray: state.compareTray.filter(id => id !== propertyId) })),
|
||||
clearCompare: () => set({ compareTray: [] }),
|
||||
isInCompare: (propertyId) => get().compareTray.includes(propertyId),
|
||||
isFull: () => get().compareTray.length >= MAX_COMPARE_ITEMS,
|
||||
}))
|
||||
@@ -0,0 +1,22 @@
|
||||
import { create } from 'zustand'
|
||||
import { WorkspaceType } from '../domain/enums'
|
||||
|
||||
interface LayoutState {
|
||||
activeWorkspace: WorkspaceType
|
||||
sidebarCollapsed: boolean
|
||||
pinnedPanels: string[]
|
||||
setActiveWorkspace: (workspace: WorkspaceType) => void
|
||||
toggleSidebar: () => void
|
||||
pinPanel: (panelId: string) => void
|
||||
unpinPanel: (panelId: string) => void
|
||||
}
|
||||
|
||||
export const useLayoutStore = create<LayoutState>((set) => ({
|
||||
activeWorkspace: WorkspaceType.SUPPLY,
|
||||
sidebarCollapsed: false,
|
||||
pinnedPanels: [],
|
||||
setActiveWorkspace: (workspace) => set({ activeWorkspace: workspace }),
|
||||
toggleSidebar: () => set((state) => ({ sidebarCollapsed: !state.sidebarCollapsed })),
|
||||
pinPanel: (panelId) => set((state) => ({ pinnedPanels: [...state.pinnedPanels, panelId] })),
|
||||
unpinPanel: (panelId) => set((state) => ({ pinnedPanels: state.pinnedPanels.filter(id => id !== panelId) })),
|
||||
}))
|
||||
@@ -0,0 +1,38 @@
|
||||
import { create } from 'zustand'
|
||||
import { UserRole } from '../domain/enums'
|
||||
|
||||
export interface MockUser {
|
||||
id: string
|
||||
email: string
|
||||
name: string
|
||||
role: UserRole
|
||||
organizationId: string
|
||||
organizationName: string
|
||||
}
|
||||
|
||||
interface SessionState {
|
||||
currentUser: MockUser | null
|
||||
activeOrganizationId: string | null
|
||||
isAuthenticated: boolean
|
||||
login: (user: MockUser) => void
|
||||
logout: () => void
|
||||
switchOrganization: (organizationId: string) => void
|
||||
}
|
||||
|
||||
const mockUser: MockUser = {
|
||||
id: 'user-001',
|
||||
email: 'admin@ideal-sharing.ch',
|
||||
name: 'Admin User',
|
||||
role: UserRole.ORGANIZATION_ADMIN,
|
||||
organizationId: 'org-wincasa',
|
||||
organizationName: 'Wincasa AG',
|
||||
}
|
||||
|
||||
export const useSessionStore = create<SessionState>((set) => ({
|
||||
currentUser: mockUser,
|
||||
activeOrganizationId: mockUser.organizationId,
|
||||
isAuthenticated: true,
|
||||
login: (user) => set({ currentUser: user, activeOrganizationId: user.organizationId, isAuthenticated: true }),
|
||||
logout: () => set({ currentUser: null, activeOrganizationId: null, isAuthenticated: false }),
|
||||
switchOrganization: (organizationId) => set({ activeOrganizationId: organizationId }),
|
||||
}))
|
||||
Reference in New Issue
Block a user