mars-v2-frontend/stores/useCreditManagerStore.tsx
Linkie Link 27cdd1c954
Linter and prettier adjustments (#50)
* tidy: added eslintrc and prettierrc rules

* tidy: formated the files via ‚yarn format‘

* import sort improvements

* format script regex fix

* replace eslint import severity to warning

* remove staged file

Co-authored-by: Gustavo Mauricio <gustavo.mauricio58@gmail.com>
2022-11-09 10:04:06 +01:00

38 lines
891 B
TypeScript

import create from 'zustand'
import { persist } from 'zustand/middleware'
interface CreditManagerStore {
isOpen: boolean
selectedAccount: string | null
actions: {
toggleCreditManager: () => void
setSelectedAccount: (id: string) => void
}
}
const useCreditManagerStore = create<CreditManagerStore>()(
persist(
(set, get) => ({
isOpen: false,
selectedAccount: null,
actions: {
toggleCreditManager: () => set(() => ({ isOpen: !get().isOpen })),
setSelectedAccount: (accountId: string) => {
set(() => ({
selectedAccount: accountId,
}))
},
},
}),
{
name: 'creditManager',
partialize: (state) =>
Object.fromEntries(
Object.entries(state).filter(([key]) => ['selectedAccount'].includes(key)),
),
},
),
)
export default useCreditManagerStore