@mui/lab#DateTimePicker TypeScript Examples
The following examples show how to use
@mui/lab#DateTimePicker.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InviteLinkCreate.tsx From abrechnung with GNU Affero General Public License v3.0 | 4 votes |
export default function InviteLinkCreate({ show, onClose, group }) {
const handleSubmit = (values, { setSubmitting }) => {
createGroupInvite({
groupID: group.id,
description: values.description,
validUntil: values.validUntil,
singleUse: values.singleUse,
joinAsEditor: values.joinAsEditor,
})
.then((result) => {
toast.success("Successfully created invite token");
setSubmitting(false);
onClose();
})
.catch((err) => {
toast.error(err);
setSubmitting(false);
});
};
const nowPlusOneHour = () => {
return DateTime.now().plus({ hours: 1 });
};
return (
<Dialog open={show} onClose={onClose}>
<DialogTitle>Create Invite Link</DialogTitle>
<DialogContent>
<Formik
initialValues={{
description: "",
validUntil: nowPlusOneHour(),
singleUse: false,
joinAsEditor: false,
}}
onSubmit={handleSubmit}
>
{({ values, setFieldValue, handleChange, handleBlur, handleSubmit, isSubmitting }) => (
<Form>
<TextField
margin="normal"
required
fullWidth
autoFocus
variant="standard"
name="description"
label="Description"
value={values.description}
onChange={handleChange}
onBlur={handleBlur}
/>
<DateTimePicker
inputFormat="yyyy-MM-dd HH:mm"
value={values.validUntil}
onChange={(val) => setFieldValue("validUntil", val, true)}
renderInput={(props) => (
<TextField
name="validUntil"
sx={{ marginTop: 2 }}
variant="standard"
fullWidth
{...props}
/>
)}
/>
<FormControlLabel
sx={{ mt: 2 }}
label={"Single Use"}
control={
<Checkbox
name="singleUse"
value={values.singleUse}
onChange={handleChange}
onBlur={handleBlur}
/>
}
/>
<FormControlLabel
sx={{ mt: 2 }}
label={"New members join as editors"}
control={
<Checkbox
name="joinAsEditor"
value={values.joinAsEditor}
onChange={handleChange}
onBlur={handleBlur}
/>
}
/>
{isSubmitting && <LinearProgress />}
<DialogActions>
<Button type="submit" color="primary" disabled={isSubmitting}>
Save
</Button>
<Button color="error" onClick={onClose}>
Cancel
</Button>
</DialogActions>
</Form>
)}
</Formik>
</DialogContent>
</Dialog>
);
}