Skip to content

Date field revamp #2562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ca057b8
date field initial commit
jomarmontuya Feb 15, 2024
edd65ba
updates
jomarmontuya Feb 20, 2024
a3c053d
Date field Revamp initial commit
jomarmontuya Feb 21, 2024
939b993
sync master
jomarmontuya Feb 21, 2024
058536f
update component to enforce Mon placeholder and keep the component un…
jomarmontuya Feb 22, 2024
52f5638
update popper margin
jomarmontuya Feb 22, 2024
7720330
open picker on textfield click
jomarmontuya Feb 29, 2024
f1a238a
open the picker when textfield is click and refocus to the textfield
jomarmontuya Mar 4, 2024
c9c4657
clear logs
jomarmontuya Mar 4, 2024
3475ba4
keep button default styling
jomarmontuya Mar 5, 2024
4216f0e
update textfield with current data
jomarmontuya Mar 6, 2024
fb1ffe8
setSelection range to be month instead of year
jomarmontuya Mar 7, 2024
4ebef0a
use the open props instead of manual trigger
jomarmontuya Mar 10, 2024
3739497
remove day highlights overrides and update material theme instead
jomarmontuya Mar 11, 2024
3b3b4c9
fix lock file version
jomarmontuya Mar 11, 2024
2d39c66
Merge branch 'master' into enhancement/datefield-revamp
jomarmontuya Mar 11, 2024
e849c45
update mui theme version
jomarmontuya Mar 12, 2024
757f668
replace datepicker field to use custom field
jomarmontuya Mar 21, 2024
76bd8bc
add comments and clean up
jomarmontuya Mar 21, 2024
7b93450
refactor parsedate function
jomarmontuya Mar 21, 2024
df4bd12
fix conde conflicts
jomarmontuya Mar 21, 2024
37b804f
resolve conflicts
jomarmontuya Mar 25, 2024
19b56e2
Merge branch 'dev' into enhancement/datefield-revamp
finnar-bin Apr 2, 2024
c66a5c7
chore: fix broken lock file
finnar-bin Apr 2, 2024
3116f57
task: fix failing tests
finnar-bin Apr 2, 2024
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
49 changes: 34 additions & 15 deletions src/apps/content-editor/src/app/components/Editor/Field/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ export const Field = ({
*/
const onDateChange = useCallback(
(value, name, datatype) => {
console.log(value, name, datatype);
/**
* Flatpickr emits a utc timestamp, offset from users local time.
* Legacy behavior did not send utc but sent the value as is selected by the user
Expand All @@ -910,23 +911,41 @@ export const Field = ({
[onChange]
);

// return (
// <FieldShell settings={fieldData} errors={errors}>
// <Box maxWidth={360}>
// <FieldTypeDate
// name={name}
// required={required}
// // use moment to create a UTC date object
// value={
// value
// ? new Date(moment(value).format("YYYY-MM-DD HH:mm:ss"))
// : null
// }
// inputFormat="MM-dd-yyyy"
// onChange={(date) => onDateChange(date, name, datatype)}
// error={errors && Object.values(errors)?.some((error) => !!error)}
// />
// </Box>
// </FieldShell>
// );

return (
<FieldShell settings={fieldData} errors={errors}>
<Box maxWidth={360}>
<FieldTypeDate
name={name}
required={required}
// use moment to create a UTC date object
value={
value
? new Date(moment(value).format("YYYY-MM-DD HH:mm:ss"))
: null
}
inputFormat="yyyy-MM-dd"
onChange={(date) => onDateChange(date, name, datatype)}
error={errors && Object.values(errors)?.some((error) => !!error)}
/>
</Box>
<FieldTypeDate
name={name}
required={required}
// use moment to create a UTC date object
value={
value
? new Date(moment(value).format("YYYY-MM-DD HH:mm:ss"))
: null
}
format="MMM dd, yyyy"
onChange={(date) => onDateChange(date, name, datatype)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this emitting a UTC date or localized date?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Here's the sample date value, it's actually localized on my location since i'm on GMT+8 is this what you're pertaining?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question still stands

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agalin920 It is emitting localize date

error={errors && Object.values(errors)?.some((error) => !!error)}
/>
</FieldShell>
);

Expand Down
108 changes: 94 additions & 14 deletions src/shell/components/FieldTypeDate/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFns";
import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
import { DesktopDatePicker, DesktopDatePickerProps } from "@mui/x-date-pickers";
import { TextField } from "@mui/material";
import {
DatePicker,
LocalizationProvider,
DatePickerProps,
} from "@mui/x-date-pickers-pro";
import { AdapterDateFns } from "@mui/x-date-pickers-pro/AdapterDateFns";
import { useEffect, useState } from "react";
import Button from "@mui/material/Button";
import { Typography, Stack, Box } from "@mui/material";

export interface FieldTypeDateProps
extends Omit<DesktopDatePickerProps<Date, Date>, "renderInput"> {
export interface FieldTypeDateProps extends DatePickerProps<Date> {
name: string;
required?: boolean;
error?: boolean;
Expand All @@ -13,18 +17,94 @@ export interface FieldTypeDateProps
export const FieldTypeDate = ({
required,
error,
value,
...props
}: FieldTypeDateProps) => {
const [dateValue, setValue] = useState<Date | null>(null);

useEffect(() => {
setValue(value);
}, [value]);

return (
<LocalizationProvider dateAdapter={AdapterDateFns}>
<DesktopDatePicker
data-testid="zds-date-picker"
renderInput={(params) => (
<TextField {...params} fullWidth size="small" error={error} />
)}
// Spread props at the end to allow prop overrides
{...props}
/>
<Stack direction={"row"}>
<Box maxWidth={160}>
<DatePicker
value={dateValue}
{...props}
disableHighlightToday={!!value}
slotProps={{
day: {
// sx: {
// "&.MuiPickersDay-today": {
// background: "#FF5D0A",
// border: "none",
// color: "white",
// },
// },
},
textField: {
placeholder: "Mon DD YYYY",
},
inputAdornment: {
position: "start",
},
}}
/>
</Box>

<Button
sx={{
"&:hover": {
background: "transparent",
},
minWidth: 54,
}}
variant="text"
size="small"
disableRipple
onClick={() => {
setValue(null);
}}
>
<Typography
color={"text.secondary"}
fontWeight={500}
variant="caption"
>
Clear
</Typography>
</Button>
</Stack>
</LocalizationProvider>
);
};

// export interface FieldTypeDateProps
// extends Omit<DesktopDatePickerProps<Date, Date>, "renderInput"> {
// name: string;
// required?: boolean;
// error?: boolean;
// }

// export const FieldTypeDate = ({
// required,
// error,
// ...props
// }: FieldTypeDateProps) => {
// return (
// <LocalizationProvider dateAdapter={AdapterDateFns}>
// <DesktopDatePicker
// InputAdornmentProps={{ position: "start" }}
// data-testid="zds-date-picker"
// renderInput={(params) => {
// params.inputProps.placeholder = "Mon DD YYYY";
// return <TextField {...params} fullWidth size="small" error={error} />;
// }}
// // Spread props at the end to allow prop overrides
// {...props}
// />
// </LocalizationProvider>
// );
// };