-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3024: Extract date and duration fields from report form
Move those fields to a dedicated component in order to implement all-day related features in isolation.
- Loading branch information
1 parent
4ecce7d
commit 4cf1c39
Showing
4 changed files
with
112 additions
and
39 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import CustomDateInput from "components/CustomDateInput" | ||
import * as FieldHelper from "components/FieldHelper" | ||
import { FastField } from "formik" | ||
import { Report } from "models" | ||
import PropTypes from "prop-types" | ||
import React from "react" | ||
import { HelpBlock } from "react-bootstrap" | ||
import Settings from "settings" | ||
|
||
const futureEngagementHint = ( | ||
<HelpBlock> | ||
<span className="text-success">This will create a planned engagement</span> | ||
</HelpBlock> | ||
) | ||
|
||
const EngagementDateFormPartial = ({ | ||
setFieldValue, | ||
setFieldTouched, | ||
validateFieldDebounced, | ||
initialValues, | ||
edit, | ||
values | ||
}) => { | ||
if (!Settings.engagementsIncludeTimeAndDuration) { | ||
return ( | ||
<FastField | ||
name="engagementDate" | ||
component={FieldHelper.SpecialField} | ||
onChange={value => { | ||
setFieldTouched("engagementDate", true, false) // onBlur doesn't work when selecting a date | ||
setFieldValue("engagementDate", value, true) | ||
}} | ||
onBlur={() => setFieldTouched("engagementDate")} | ||
widget={<CustomDateInput id="engagementDate" />} | ||
> | ||
{Report.isFuture(values.engagementDate) && futureEngagementHint} | ||
</FastField> | ||
) | ||
} | ||
|
||
return ( | ||
<> | ||
<FastField | ||
name="engagementDate" | ||
component={FieldHelper.SpecialField} | ||
onChange={value => { | ||
setFieldTouched("engagementDate", true, false) // onBlur doesn't work when selecting a date | ||
setFieldValue("engagementDate", value, true) | ||
}} | ||
onBlur={() => setFieldTouched("engagementDate")} | ||
widget={<CustomDateInput id="engagementDate" withTime />} | ||
> | ||
{Report.isFuture(values.engagementDate) && futureEngagementHint} | ||
</FastField> | ||
|
||
<FastField | ||
name="duration" | ||
label="Duration (minutes)" | ||
component={FieldHelper.InputField} | ||
onChange={event => { | ||
setFieldTouched("duration", true, false) | ||
setFieldValue("duration", event.target.value, false) | ||
validateFieldDebounced("duration") | ||
}} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
EngagementDateFormPartial.propTypes = { | ||
setFieldValue: PropTypes.func.isRequired, | ||
setFieldTouched: PropTypes.func.isRequired, | ||
validateFieldDebounced: PropTypes.func.isRequired, | ||
values: PropTypes.object.isRequired, | ||
initialValues: PropTypes.instanceOf(Report).isRequired, | ||
edit: PropTypes.bool.isRequired | ||
} | ||
|
||
export default EngagementDateFormPartial |
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