Skip to content

Commit

Permalink
feat: move isAcceptDenyOpen away from store
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin9foong committed Dec 24, 2024
1 parent c4ebcdb commit 66521d8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { useAssistanceMutations } from '~features/admin-form/assistance/mutation

import { useDeleteFormField } from '../../mutations/useDeleteFormField'
import {
isAcceptDenyOpenSelector,
recentlyCreatedFieldIdsSelector,
useMagicFormBuilderStore,
} from '../../useMagicFormBuilderStore'
Expand Down Expand Up @@ -180,7 +179,8 @@ const MagicFormBuilderPopover = ({
recentlyCreatedFieldIdsSelector,
)

const isAcceptDenyOpen = useMagicFormBuilderStore(isAcceptDenyOpenSelector)
const isAcceptDenyOpen =
!!recentlyCreatedFieldIds && recentlyCreatedFieldIds.size > 0

const onClickDefaults = () => {
clearRecentlyCreatedFieldIds()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import create from 'zustand'

export type MagicFormBuilderStore = {
isAcceptDenyOpen: boolean
recentlyCreatedFieldIds: Set<string>
setRecentlyCreatedFieldIds: (fieldIds: Set<string>) => void
clearRecentlyCreatedFieldIds: () => void
}

export const useMagicFormBuilderStore = create<MagicFormBuilderStore>(
(set, get) => ({
isAcceptDenyOpen: get().recentlyCreatedFieldIds.size > 0,
(set) => ({
recentlyCreatedFieldIds: new Set(),
setRecentlyCreatedFieldIds: (fieldIds) =>
set({ recentlyCreatedFieldIds: fieldIds }),
Expand All @@ -18,10 +16,6 @@ export const useMagicFormBuilderStore = create<MagicFormBuilderStore>(
}),
)

export const isAcceptDenyOpenSelector = (
state: MagicFormBuilderStore,
): MagicFormBuilderStore['isAcceptDenyOpen'] => state.isAcceptDenyOpen

export const recentlyCreatedFieldIdsSelector = (
state: MagicFormBuilderStore,
): MagicFormBuilderStore['recentlyCreatedFieldIds'] =>
Expand Down

0 comments on commit 66521d8

Please sign in to comment.