Skip to content

Commit

Permalink
chore: update link category on dropdown click
Browse files Browse the repository at this point in the history
  • Loading branch information
seaerchin committed Jan 28, 2025
1 parent 462fee3 commit b309867
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { useFeatureValue } from "@growthbook/growthbook-react"
import { and, rankWith, schemaMatches } from "@jsonforms/core"
import { withJsonFormsControlProps } from "@jsonforms/react"
import { FormLabel, SingleSelect } from "@opengovsg/design-system-react"
import { useSetAtom } from "jotai"

import Suspense from "~/components/Suspense"
import { JSON_FORMS_RANKING } from "~/constants/formBuilder"
import { linkAtom } from "~/features/editing-experience/atoms"
import { collectionItemSchema } from "~/features/editing-experience/schema"
import { useQueryParse } from "~/hooks/useQueryParse"
import { CATEGORY_DROPDOWN_FEATURE_KEY } from "~/lib/growthbook"
Expand Down Expand Up @@ -46,7 +48,9 @@ function SuspendableJsonFormsCategoryControl({
return { label: category, value: category }
})}
isClearable={false}
onChange={(value) => handleChange(path, value)}
onChange={(value) => {
handleChange(path, value)
}}
/>
)
}
Expand All @@ -57,18 +61,27 @@ export function JsonFormsCategoryControl({
label,
...props
}: ControlProps) {
const { siteId } = useQueryParse(editPageSchema)
const { siteId } = useQueryParse(collectionItemSchema)
const setLink = useSetAtom(linkAtom)
const { enabledSites } = useFeatureValue<{ enabledSites: string[] }>(
CATEGORY_DROPDOWN_FEATURE_KEY,
{ enabledSites: [] },
)
const handleChange: ControlProps["handleChange"] = (path, value) => {
props.handleChange(path, value)
setLink((prev) => ({ ...prev, category: value }))
}

const isDropdownEnabled = enabledSites.includes(siteId.toString())
return isDropdownEnabled ? (
<FormControl isRequired={required} gap="0.5rem">
<FormLabel description={description}>{label}</FormLabel>
<Suspense fallback={<Skeleton />}>
<SuspendableJsonFormsCategoryControl {...props} label={label} />
<SuspendableJsonFormsCategoryControl
{...props}
label={label}
handleChange={handleChange}
/>
</Suspense>
</FormControl>
) : (
Expand All @@ -77,6 +90,7 @@ export function JsonFormsCategoryControl({
description={description}
required={required}
label={label}
handleChange={handleChange}
/>
)
}
Expand Down

0 comments on commit b309867

Please sign in to comment.