c9dbf5037e
Allow deferred login actions to return promises and execute them safely without violating lint rules. Also initialize order detail timer state without impure render-time Date.now calls so React hook purity checks pass.
28 lines
791 B
TypeScript
28 lines
791 B
TypeScript
import { create } from "zustand"
|
|
|
|
interface LoginDialogState {
|
|
open: boolean
|
|
pendingActions: Array<() => void | Promise<void>>
|
|
openLoginDialog: (action?: () => void | Promise<void>) => void
|
|
closeLoginDialog: () => void
|
|
consumePendingAction: () => void
|
|
}
|
|
|
|
export const useLoginDialogStore = create<LoginDialogState>((set, get) => ({
|
|
open: false,
|
|
pendingActions: [],
|
|
openLoginDialog: (action) =>
|
|
set((state) => ({
|
|
open: true,
|
|
pendingActions: action ? [...state.pendingActions, action] : state.pendingActions,
|
|
})),
|
|
closeLoginDialog: () => set({ open: false, pendingActions: [] }),
|
|
consumePendingAction: () => {
|
|
const actions = get().pendingActions
|
|
set({ pendingActions: [] })
|
|
actions.forEach((action) => {
|
|
void action()
|
|
})
|
|
},
|
|
}))
|