refactor: align client state and ui with backend contract

This commit is contained in:
zetaloop
2026-05-03 05:40:01 +08:00
parent a3f0b49112
commit 0e7270aa8d
4 changed files with 51 additions and 9 deletions
+8 -3
View File
@@ -22,6 +22,7 @@ interface PersistedAuth {
currentRole: UserRole
verifiedRoles: UserRole[]
verificationStatus: Partial<Record<UserRole, VerificationStatus>>
notificationPrefs: NotificationPrefs
themePreference: ThemePreference
}
@@ -50,6 +51,7 @@ function persistCurrent(state: AuthState) {
currentRole: state.currentRole,
verifiedRoles: state.verifiedRoles,
verificationStatus: state.verificationStatus,
notificationPrefs: state.notificationPrefs,
themePreference: state.themePreference,
})
}
@@ -95,13 +97,15 @@ export const useAuthStore = create<AuthState>((set, get) => ({
persistCurrent(get())
}
},
setNotificationPref: (type, enabled) =>
setNotificationPref: (type, enabled) => {
set((state) => ({
notificationPrefs: {
...state.notificationPrefs,
[type]: enabled,
},
})),
}))
persistCurrent(get())
},
setThemePreference: (theme) => {
set({ themePreference: theme })
persistCurrent(get())
@@ -138,6 +142,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
currentRole: user.role,
verifiedRoles: nextVerifiedRoles,
verificationStatus: nextVerificationStatus,
notificationPrefs: state.notificationPrefs,
themePreference: nextTheme,
})
@@ -160,7 +165,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
verifiedRoles: ["consumer"],
verificationStatus: { consumer: "approved" },
verificationReasons: {},
notificationPrefs: defaultNotificationPrefs,
notificationPrefs: persisted?.notificationPrefs ?? defaultNotificationPrefs,
themePreference: "system",
user: null,
})