-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [DHIS2-17991] Show orgUnit selector in Enter details now (#3824)
* feat: add org unit selector * feat: select org unit for linked event * feat: add validation
- Loading branch information
Showing
9 changed files
with
161 additions
and
36 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
114 changes: 114 additions & 0 deletions
114
...les/capture-core/components/WidgetRelatedStages/EnterDataInOrgUnit/EnterData.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,114 @@ | ||
// @flow | ||
import React from 'react'; | ||
import i18n from '@dhis2/d2-i18n'; | ||
import type { ComponentType } from 'react'; | ||
import { withStyles } from '@material-ui/core'; | ||
import { colors, spacers, spacersNum, IconInfo16 } from '@dhis2/ui'; | ||
import { OrgUnitSelectorForRelatedStages } from '../FormComponents'; | ||
import type { ErrorMessagesForRelatedStages } from '../RelatedStagesActions'; | ||
import type { RelatedStageDataValueStates } from '../WidgetRelatedStages.types'; | ||
|
||
const styles = { | ||
wrapper: { | ||
padding: `${spacers.dp16} 0`, | ||
maxWidth: '55.75rem', | ||
}, | ||
fieldWrapper: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
alignItems: 'start', | ||
justifyContent: 'space-between', | ||
padding: `${spacers.dp8} ${spacers.dp16}`, | ||
}, | ||
fieldLabel: { | ||
color: colors.grey900, | ||
paddingTop: spacersNum.dp12, | ||
paddingRight: spacersNum.dp16, | ||
flexBasis: '200px', | ||
}, | ||
fieldContent: { | ||
flexBasis: '150px', | ||
flexGrow: 1, | ||
}, | ||
alternateColor: { | ||
backgroundColor: colors.grey100, | ||
}, | ||
infoBox: { | ||
margin: '8px 8px', | ||
display: 'flex', | ||
fontSize: '14px', | ||
gap: '5px', | ||
background: colors.grey100, | ||
padding: '12px 8px', | ||
border: `1px solid ${colors.grey600}`, | ||
}, | ||
}; | ||
|
||
type Props = { | ||
linkableStageLabel: string, | ||
relatedStagesDataValues: RelatedStageDataValueStates, | ||
setRelatedStagesDataValues: (() => Object) => void, | ||
currentStageLabel: string, | ||
saveAttempted: boolean, | ||
errorMessages: ErrorMessagesForRelatedStages, | ||
...CssClasses | ||
} | ||
|
||
export const EnterDataInOrgUnitPlain = ({ | ||
linkableStageLabel, | ||
relatedStagesDataValues, | ||
setRelatedStagesDataValues, | ||
saveAttempted, | ||
errorMessages, | ||
currentStageLabel, | ||
classes, | ||
}: Props) => { | ||
const onSelectOrgUnit = (e: { id: string, displayName: string, path: string }) => { | ||
const orgUnit = { | ||
id: e.id, | ||
name: e.displayName, | ||
path: e.path, | ||
}; | ||
|
||
setRelatedStagesDataValues(prevValues => ({ | ||
...prevValues, | ||
orgUnit, | ||
})); | ||
}; | ||
|
||
const onDeselectOrgUnit = () => { | ||
setRelatedStagesDataValues(prevValues => ({ | ||
...prevValues, | ||
orgUnit: null, | ||
})); | ||
}; | ||
|
||
return ( | ||
<div className={classes.wrapper}> | ||
<div> | ||
<OrgUnitSelectorForRelatedStages | ||
relatedStagesDataValues={relatedStagesDataValues} | ||
onSelectOrgUnit={onSelectOrgUnit} | ||
onDeselectOrgUnit={onDeselectOrgUnit} | ||
errorMessages={errorMessages} | ||
saveAttempted={saveAttempted} | ||
/> | ||
</div> | ||
<div className={classes.infoBox}> | ||
<IconInfo16 /> | ||
{i18n.t( | ||
relatedStagesDataValues?.orgUnit?.name | ||
? 'Enter {{linkableStageLabel}} details for {{orgUnitLabel}} in the next step after completing this {{currentStageLabel}}.' | ||
: 'Select organisation unit and enter {{linkableStageLabel}} details in the next step after completing this {{currentStageLabel}}.', | ||
{ | ||
linkableStageLabel, | ||
currentStageLabel, | ||
orgUnitLabel: relatedStagesDataValues?.orgUnit?.name, | ||
}, | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const EnterDataInOrgUnit: ComponentType<$Diff<Props, CssClasses>> = withStyles(styles)(EnterDataInOrgUnitPlain); |
2 changes: 2 additions & 0 deletions
2
src/core_modules/capture-core/components/WidgetRelatedStages/EnterDataInOrgUnit/index.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,2 @@ | ||
// @flow | ||
export { EnterDataInOrgUnit } from './EnterData.component'; |
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/core_modules/capture-core/components/WidgetRelatedStages/ScheduleInOrgUnit/index.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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// @flow | ||
export { ScheduleInOrgUnit } from './ScheduleInOrgUnit.container'; | ||
export { ScheduleInOrgUnit } from './ScheduleInOrgUnit.component'; |
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