Skip to content

Commit

Permalink
chore(web): fix the date time component (#752)
Browse files Browse the repository at this point in the history
Co-authored-by: nina992 <nouralali992@gmail.com>
  • Loading branch information
nina992 and nina992 committed Oct 23, 2023
1 parent c1c3dee commit 615682e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
18 changes: 5 additions & 13 deletions web/src/beta/components/fields/DateTimeField/index.tsx
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from "react";
import { useCallback, useState } from "react";

import { styled } from "@reearth/services/theme";

Expand All @@ -13,8 +13,8 @@ export type Props = {
};

const DateTimeField: React.FC<Props> = ({ name, description, value, onChange }) => {
const [time, setTime] = useState<string>();
const [date, setDate] = useState<string>();
const [time, setTime] = useState<string>(value?.split(" ")[1] ?? "HH:MM:SS");
const [date, setDate] = useState<string>(value?.split(" ")[0] ?? "YYYY-MM-DD");

const handleTimeChange = useCallback(
(newValue: string | undefined) => {
Expand All @@ -36,19 +36,11 @@ const DateTimeField: React.FC<Props> = ({ name, description, value, onChange })
[time, onChange],
);

useEffect(() => {
if (value) {
const [dateString, timeString] = value.split(" ");
setTime(timeString);
setDate(dateString);
}
}, [value]);

return (
<Property name={name} description={description}>
<Wrapper>
<TextInput type="date" value={value} onChange={handleDateChange} />
<TextInput type="time" value={value} onChange={handleTimeChange} />
<TextInput type="date" value={date} onChange={handleDateChange} />
<TextInput type="time" value={time} onChange={handleTimeChange} />
</Wrapper>
</Property>
);
Expand Down
2 changes: 2 additions & 0 deletions web/src/services/api/propertyApi/utils.ts
Expand Up @@ -279,6 +279,8 @@ export const toUi = (ui: PropertySchemaFieldUi | null | undefined): SchemaField[
return "margin";
case PropertySchemaFieldUi.Padding:
return "padding";
case PropertySchemaFieldUi.Datetime:
return "datetime";
}
return undefined;
};
Expand Down

0 comments on commit 615682e

Please sign in to comment.