-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add org unit selector in schedule event form
- Loading branch information
Showing
12 changed files
with
336 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ | |
} | ||
|
||
.orgUnitLabel { | ||
padding-top: 3px; | ||
padding-top: 13px; | ||
} | ||
|
||
.selectLabel { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
.../capture-core/components/WidgetEventSchedule/ScheduleDate/dataEntryFieldLabels.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.dateLabel { | ||
padding-top: 13px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../capture-core/components/WidgetEventSchedule/ScheduleOrgUnit/ScheduleOrgUnit.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// @flow | ||
import React, { useState } from 'react'; | ||
import i18n from '@dhis2/d2-i18n'; | ||
import { isValidOrgUnit } from 'capture-core-utils/validators/form'; | ||
import labelTypeClasses from './dataEntryFieldLabels.module.css'; | ||
import { baseInputStyles } from './commonProps'; | ||
import { | ||
SingleOrgUnitSelectField, | ||
withDefaultFieldContainer, | ||
withDisplayMessages, | ||
withInternalChangeHandler, | ||
withLabel, | ||
} from '../../FormFields/New'; | ||
|
||
type OrgUnitValue = {| | ||
checked: boolean, | ||
id: string, | ||
children: number, | ||
name: string, | ||
displayName: string, | ||
path: string, | ||
selected: string[], | ||
|} | ||
|
||
type Props = { | ||
onSelectOrgUnit: (orgUnit: OrgUnitValue) => void, | ||
onDeselectOrgUnit: () => void, | ||
orgUnit: OrgUnitValue, | ||
}; | ||
|
||
const OrgUnitFieldForForm = withDefaultFieldContainer()( | ||
withLabel({ | ||
onGetCustomFieldLabeClass: () => labelTypeClasses.dateLabel, | ||
})( | ||
withDisplayMessages()( | ||
withInternalChangeHandler()( | ||
SingleOrgUnitSelectField, | ||
), | ||
), | ||
), | ||
); | ||
|
||
export const ScheduleOrgUnit = ({ | ||
onSelectOrgUnit, | ||
onDeselectOrgUnit, | ||
orgUnit, | ||
}: Props) => { | ||
const [touched, setTouched] = useState(false); | ||
|
||
const handleSelect = (event) => { | ||
setTouched(true); | ||
onSelectOrgUnit(event); | ||
}; | ||
|
||
const handleDeselect = () => { | ||
setTouched(true); | ||
onDeselectOrgUnit(); | ||
}; | ||
|
||
const shouldShowError = (!isValidOrgUnit(orgUnit) && touched); | ||
const errorMessages = i18n.t('Please provide a valid organisation unit'); | ||
|
||
return ( | ||
<OrgUnitFieldForForm | ||
label={i18n.t('Organisation unit')} | ||
value={orgUnit} | ||
required | ||
onSelectClick={handleSelect} | ||
onBlur={handleDeselect} | ||
styles={baseInputStyles} | ||
errorMessage={shouldShowError && errorMessages} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.