import { createStore } from 'zustand'; import { mutative } from 'zustand-mutative'; export interface UserProfileData { id: string; displayName: string; fullName: string; loginName: string; avatarUrl?: string; photoUrl?: string; email: string; roles?: { id: string; title: string; code: string; }[]; } export interface UserState extends UserProfileData { load(data: UserProfileData): void; } export type UserStore = ReturnType; export function createUserStore(init: Partial = {}) { return createStore( mutative((setState, getState, store) => { return { id: '', displayName: '', fullName: '', loginName: '', email: '', roles: [], ...init, load: (v) => { setState((s) => { Object.assign(s, v); }); }, }; }), ); }