import { create } from 'zustand' import { getMyInfo, getMyEntList as _getMyEntList, getMyPrivacy } from '@/service/user' import { TEntItem, TUserInfo, TMyPrivacy } from '@/types/user' import { isSuccess } from '@/utils' export interface UserState { whoami: TUserInfo | null entList: TEntItem[] privacy: TMyPrivacy fetchtMyInfo: ()=> Promise fetchMyPrivacy: ()=> Promise fetchMyEntList: ()=> Promise } export const useUserStore = create((set) => ({ whoami: null, privacy: { contactVisibleMyInfo: false, directVisibleMyInfo: false, forwardVisibleMyInfo: false }, entList: [], fetchtMyInfo: async () => { const res = await getMyInfo() if(isSuccess(res.status)){ set({ whoami: res.data}) } }, fetchMyPrivacy: async () => { const res = await getMyPrivacy() if(isSuccess(res.status)){ set({ privacy: res.data}) } }, fetchMyEntList: async () => { const res = await _getMyEntList() if(isSuccess(res.status)){ set({ entList: res.data}) } }, }))