generated from EyeSeeTea/dhis2-app-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DateTime picker UI element for Facility level form
- Loading branch information
Showing
7 changed files
with
354 additions
and
18 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
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
39 changes: 39 additions & 0 deletions
39
src/webapp/components/survey-questions/widgets/DateTimePickerWidget.tsx
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,39 @@ | ||
import React from "react"; | ||
// @ts-ignore | ||
import { Maybe } from "../../../../types/utils"; | ||
import { BaseWidgetProps } from "./BaseWidget"; | ||
import { DateTimePicker } from "@mui/x-date-pickers"; | ||
import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFns"; | ||
import { LocalizationProvider } from "@mui/x-date-pickers"; | ||
|
||
export interface DateTimePickerWidgetProps extends BaseWidgetProps<string> { | ||
value: Maybe<string>; | ||
name: string; | ||
} | ||
|
||
const DateTimePickerWidget: React.FC<DateTimePickerWidgetProps> = props => { | ||
const { onChange: onValueChange, value } = props; | ||
|
||
const [stateValue, setStateValue] = React.useState(value); | ||
React.useEffect(() => setStateValue(value), [value]); | ||
|
||
const notifyChange = React.useCallback( | ||
(newValue: string) => { | ||
setStateValue(newValue); | ||
onValueChange(newValue); | ||
}, | ||
[onValueChange] | ||
); | ||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDateFns}> | ||
<DateTimePicker | ||
key={props.name} | ||
value={new Date(stateValue)} | ||
disabled={props.disabled} | ||
onChange={newValue => notifyChange(newValue?.toISOString() ?? "")} | ||
/> | ||
</LocalizationProvider> | ||
); | ||
}; | ||
|
||
export default React.memo(DateTimePickerWidget); |
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.