Skip to content

Commit

Permalink
fix(organisationUnit): selected org units update according to input.v…
Browse files Browse the repository at this point in the history
…alue [skip release] (#493)

* fix: need to make sure selected org units update once the input value updates

* fix: use input value path rather than state selected
  • Loading branch information
flaminic authored Jan 16, 2025
1 parent 7527246 commit 2562297
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/pages/organisationUnits/form/OrganisationUnitSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import i18n from '@dhis2/d2-i18n'
import { Field, NoticeBox, OrganisationUnitTree } from '@dhis2/ui'
import { IconInfo16 } from '@dhis2/ui-icons'
import React, { useState } from 'react'
import { FieldRenderProps, useField } from 'react-final-form'
import React from 'react'
import { useField } from 'react-final-form'
import { useCurrentUserRootOrgUnits } from '../../../lib/user/currentUserStore'
import classes from './OrganisationUnitSelector.module.css'

Expand All @@ -16,9 +16,7 @@ export function OrganisationUnitSelector() {
const userRootOrgUnits = useCurrentUserRootOrgUnits()
const userRootOrgUnitsIds = userRootOrgUnits.map((unit) => unit.id)
const userRootOrgUnitsPaths = userRootOrgUnits.map((unit) => unit.path)
const [selected, setSelected] = useState<[string] | []>(
input.value?.path ? [input.value.path] : []
)
const selectedPath = input.value?.path ? [input.value.path] : []

const handleChange = (orgUnit: {
displayName: string
Expand All @@ -30,7 +28,6 @@ export function OrganisationUnitSelector() {
id: orgUnit.id,
path: orgUnit.path,
})
setSelected([orgUnit.path])
input.onBlur()
}

Expand All @@ -47,10 +44,10 @@ export function OrganisationUnitSelector() {
onChange={handleChange}
singleSelection
roots={userRootOrgUnitsIds}
selected={selected}
selected={selectedPath}
initiallyExpanded={[
...userRootOrgUnitsPaths,
...selected,
...selectedPath,
]}
/>
</div>
Expand Down

0 comments on commit 2562297

Please sign in to comment.