refactor: align client state and ui with backend contract
This commit is contained in:
+8
-3
@@ -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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user