Skip to content

Commit

Permalink
feat: do not allow creation of org units at level 1 unless it's the f…
Browse files Browse the repository at this point in the history
…irst (#470) [skip release]

* fix: require a parent orgunit when creating new org units

* feat: add tests specs
  • Loading branch information
flaminic authored Dec 17, 2024
1 parent e05fd78 commit 21e73b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/pages/organisationUnits/New.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ describe('Indicator type add form additional tests', () => {
it('should show an error if latitude is above 180', () => {})
it('should show an error if latitude is below -180', () => {})
it('should show an error if email is not valid', () => {})
it('should show an error if parent org unit is not selected', () => {})
it('should allow creation of the first org unit', () => {})
})
8 changes: 6 additions & 2 deletions src/pages/organisationUnits/form/OrganisationUnitSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ 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 { useField } from 'react-final-form'
import { FieldRenderProps, useField } from 'react-final-form'
import { useCurrentUserRootOrgUnits } from '../../../lib/user/currentUserStore'
import classes from './OrganisationUnitSelector.module.css'

export function OrganisationUnitSelector() {
const fieldName = 'parent'
const { input, meta } = useField(fieldName, { format: (value) => value })
const { input, meta } = useField(fieldName, {
format: (value) => value,
validate: (value) =>
!value && userRootOrgUnits.length > 0 ? 'Required' : undefined,
})
const userRootOrgUnits = useCurrentUserRootOrgUnits()
const userRootOrgUnitsIds = userRootOrgUnits.map((unit) => unit.id)
const userRootOrgUnitsPaths = userRootOrgUnits.map((unit) => unit.path)
Expand Down

0 comments on commit 21e73b8

Please sign in to comment.