Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions src/components/Measurements/widgets/EntryForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Stack, TextField } from "@mui/material";
import { DatePicker, LocalizationProvider } from "@mui/x-date-pickers";
import { DateTimePicker, LocalizationProvider } from "@mui/x-date-pickers";
import { AdapterLuxon } from "@mui/x-date-pickers/AdapterLuxon";
import { LoadingPlaceholder } from "components/Core/LoadingWidget/LoadingWidget";
import { MeasurementEntry } from "components/Measurements/models/Entry";
Expand All @@ -13,7 +13,6 @@ import { DateTime, Settings } from "luxon";
import React from 'react';
import { useTranslation } from "react-i18next";
import { TIMEZONE } from "utils/consts";
import { dateToYYYYMMDD } from "utils/date";
import * as yup from 'yup';

Settings.defaultZone = TIMEZONE;
Expand Down Expand Up @@ -87,32 +86,17 @@ export const EntryForm = ({ entry, closeFn, categoryId }: EntryFormProps) => {
{categoryQuery.isLoading
? <LoadingPlaceholder />
: <LocalizationProvider dateAdapter={AdapterLuxon} adapterLocale={i18n.language}>
<DatePicker
format="yyyy-MM-dd"
<DateTimePicker
label={t('date')}
value={dateValue}
slotProps={{ textField: { variant: 'outlined' } }}
disableFuture={true}

onChange={(newValue) => {
if (newValue) {
formik.setFieldValue('date', newValue.toJSDate());
}
setDateValue(newValue);
}}
shouldDisableDate={(date) => {
// Allow the date of the current weight entry, since we are editing it
if (entry && dateToYYYYMMDD(entry.date) === dateToYYYYMMDD(date.toJSDate())) {
return false;
}

// if date is in list of existing entries, disable it
if (date) {
return categoryQuery.data!.entries.some(entry => dateToYYYYMMDD(entry.date) === dateToYYYYMMDD(date.toJSDate()));
}

// all other dates are allowed
return false;
}}
/>
</LocalizationProvider>}

Expand All @@ -136,4 +120,4 @@ export const EntryForm = ({ entry, closeFn, categoryId }: EntryFormProps) => {
)}
</Formik>)
);
};
};
Loading