feat(notifications): add notification system and wire order/dispute events

This commit is contained in:
zetaloop
2026-02-23 11:05:04 +08:00
parent 2222dccbb7
commit c986539954
7 changed files with 214 additions and 17 deletions
+26 -2
View File
@@ -1,17 +1,31 @@
import { create } from "zustand"
import type { User, UserRole, VerificationStatus } from "@/lib/types"
interface NotificationPrefs {
order: boolean
community: boolean
system: boolean
}
const defaultNotificationPrefs: NotificationPrefs = {
order: true,
community: true,
system: false,
}
interface AuthState {
isAuthenticated: boolean
currentRole: UserRole
verifiedRoles: UserRole[]
verificationStatus: Partial<Record<UserRole, VerificationStatus>>
verificationReasons: Partial<Record<UserRole, string>>
notificationPrefs: NotificationPrefs
user: User | null
switchRole: (role: UserRole) => void
submitVerification: (role: UserRole) => void
approveVerification: (role: UserRole) => void
rejectVerification: (role: UserRole, reason: string) => void
setNotificationPref: (type: keyof NotificationPrefs, enabled: boolean) => void
updateProfile: (patch: { nickname?: string; bio?: string; avatar?: string }) => void
login: (user: User, verifiedRoles?: UserRole[]) => void
logout: () => void
@@ -23,6 +37,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
verifiedRoles: ["consumer"],
verificationStatus: { consumer: "approved" },
verificationReasons: {},
notificationPrefs: defaultNotificationPrefs,
user: null,
switchRole: (role) => {
const { verifiedRoles } = get()
@@ -84,6 +99,13 @@ export const useAuthStore = create<AuthState>((set, get) => ({
},
}
}),
setNotificationPref: (type, enabled) =>
set((state) => ({
notificationPrefs: {
...state.notificationPrefs,
[type]: enabled,
},
})),
updateProfile: (patch) =>
set((state) => {
if (!state.user) return state
@@ -98,7 +120,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
}
}),
login: (user, verifiedRoles = ["consumer"]) =>
set({
set((state) => ({
isAuthenticated: true,
user,
currentRole: user.role,
@@ -111,7 +133,8 @@ export const useAuthStore = create<AuthState>((set, get) => ({
{},
),
verificationReasons: {},
}),
notificationPrefs: state.notificationPrefs,
})),
logout: () =>
set({
isAuthenticated: false,
@@ -119,6 +142,7 @@ export const useAuthStore = create<AuthState>((set, get) => ({
verifiedRoles: ["consumer"],
verificationStatus: { consumer: "approved" },
verificationReasons: {},
notificationPrefs: defaultNotificationPrefs,
user: null,
}),
}))