-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add orgunit selector to schedule form
- Loading branch information
Showing
9 changed files
with
225 additions
and
128 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
85 changes: 43 additions & 42 deletions
85
...odules/capture-core/components/WidgetEventSchedule/ScheduleDate/ScheduleDate.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 |
---|---|---|
@@ -1,51 +1,52 @@ | ||
// @flow | ||
import React, { type ComponentType } from 'react'; | ||
import { spacersNum } from '@dhis2/ui'; | ||
import withStyles from '@material-ui/core/styles/withStyles'; | ||
import { DateField } from 'capture-core/components/FormFields/New'; | ||
import { InfoBox } from '../InfoBox'; | ||
import type { Props } from './scheduleDate.types'; | ||
import React from 'react'; | ||
import i18n from '@dhis2/d2-i18n'; | ||
import { DateField, | ||
withDefaultFieldContainer, | ||
withLabel, | ||
withDisplayMessages, | ||
withInternalChangeHandler, | ||
} from 'capture-core/components/FormFields/New'; | ||
import labelTypeClasses from './dataEntryFieldLabels.module.css'; | ||
import { convertStringToDateFormat } from '../../../utils/converters/date'; | ||
|
||
|
||
const styles = { | ||
container: { | ||
display: 'flex', | ||
marginTop: spacersNum.dp4, | ||
}, | ||
button: { | ||
paddingRight: spacersNum.dp16, | ||
}, | ||
const LabelledRequiredDateField = withDefaultFieldContainer()( | ||
withLabel({ | ||
onGetCustomFieldLabeClass: () => labelTypeClasses.dateLabel, | ||
})( | ||
withDisplayMessages()( | ||
withInternalChangeHandler()( | ||
DateField, | ||
), | ||
), | ||
), | ||
); | ||
|
||
type Props = { | ||
scheduleDate: ?string, | ||
setScheduleDate: (dateString: ?string) => void, | ||
hideDueDate?: boolean, | ||
}; | ||
|
||
const ScheduleDatePlain = ({ | ||
export const ScheduleDate = ({ | ||
scheduleDate, | ||
serverScheduleDate, | ||
setScheduleDate, | ||
orgUnit, | ||
serverSuggestedScheduleDate, | ||
eventCountInOrgUnit, | ||
classes, | ||
hideDueDate, | ||
}: Props) => (<> | ||
{!hideDueDate && <div className={classes.container}> | ||
<DateField | ||
value={scheduleDate} | ||
width="100%" | ||
calendarWidth={350} | ||
onSetFocus={() => {}} | ||
onFocus={() => { }} | ||
onRemoveFocus={() => { }} | ||
onBlur={(e) => { setScheduleDate(convertStringToDateFormat(e)); }} | ||
/> | ||
</div>} | ||
<InfoBox | ||
scheduleDate={serverScheduleDate} | ||
suggestedScheduleDate={serverSuggestedScheduleDate} | ||
eventCountInOrgUnit={eventCountInOrgUnit} | ||
orgUnitName={orgUnit?.name} | ||
hideDueDate={hideDueDate} | ||
/> | ||
</>); | ||
|
||
export const ScheduleDate: ComponentType<$Diff<Props, CssClasses>> = (withStyles(styles)(ScheduleDatePlain)); | ||
}: Props) => ( | ||
<> | ||
{!hideDueDate && ( | ||
<LabelledRequiredDateField | ||
label={i18n.t('Schedule date / Due date')} | ||
required | ||
value={scheduleDate} | ||
width="100%" | ||
calendarWidth={350} | ||
onSetFocus={() => { }} | ||
onFocus={() => { }} | ||
onRemoveFocus={() => { }} | ||
onBlur={(e) => { setScheduleDate(convertStringToDateFormat(e)); }} | ||
/> | ||
)} | ||
</> | ||
); |
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; | ||
} |
64 changes: 64 additions & 0 deletions
64
.../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,64 @@ | ||
// @flow | ||
import React from 'react'; | ||
import i18n from '@dhis2/d2-i18n'; | ||
import { | ||
SingleOrgUnitSelectField, | ||
withDefaultFieldContainer, | ||
withDisplayMessages, | ||
withInternalChangeHandler, | ||
withLabel, | ||
} from '../../FormFields/New'; | ||
import labelTypeClasses from './dataEntryFieldLabels.module.css'; | ||
import { baseInputStyles } from './commonProps'; | ||
|
||
type OrgUnitValue = {| | ||
checked: boolean, | ||
id: string, | ||
children: number, | ||
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 handleSelect = (event) => { | ||
onSelectOrgUnit(event); | ||
}; | ||
|
||
const handleDeselect = () => { | ||
onDeselectOrgUnit(); | ||
}; | ||
|
||
return ( | ||
<OrgUnitFieldForForm | ||
label={i18n.t('Organisation unit')} | ||
value={orgUnit} | ||
required | ||
onSelectClick={handleSelect} | ||
onBlur={handleDeselect} | ||
styles={baseInputStyles} | ||
/> | ||
); | ||
}; |
6 changes: 6 additions & 0 deletions
6
src/core_modules/capture-core/components/WidgetEventSchedule/ScheduleOrgUnit/commonProps.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,6 @@ | ||
// @flow | ||
|
||
export const baseInputStyles = { | ||
inputContainerStyle: { flexBasis: 150 }, | ||
labelContainerStyle: { flexBasis: 200 }, | ||
}; |
3 changes: 3 additions & 0 deletions
3
...pture-core/components/WidgetEventSchedule/ScheduleOrgUnit/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
Oops, something went wrong.