Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: do not allow creation of org units at level 1 unless it's the first #470

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading