Skip to content

Commit 7ee1486

Browse files
committed
date type widget
1 parent e25cd85 commit 7ee1486

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/components/Widgets/EditableTable.jsx

+26-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '@plone/volto/components/manage/Widgets/SelectStyling';
99
import { Input, Pagination, Table } from 'semantic-ui-react';
1010
import { usePagination, useTable } from 'react-table';
11-
11+
import { useSelector } from 'react-redux';
1212
import { Icon } from '@plone/volto/components';
1313
import React from 'react';
1414
import { compose } from 'redux';
@@ -20,13 +20,15 @@ import paginationLeftSVG from '@plone/volto/icons/left-key.svg';
2020
import paginationRightSVG from '@plone/volto/icons/right-key.svg';
2121
import plusSVG from '@plone/volto/icons/circle-plus.svg';
2222
import { useIntl } from 'react-intl';
23-
23+
import DatetimeWidget from '@plone/volto/components/manage/Widgets/DatetimeWidget';
24+
import moment from 'moment';
2425
const FieldEditor = (props) => {
2526
const {
2627
fieldSchema,
2728
value,
2829
onChange,
2930
onChangeSelect,
31+
onChangeDate,
3032
onBlur,
3133
reactSelect,
3234
} = props;
@@ -88,6 +90,17 @@ const FieldEditor = (props) => {
8890
/>
8991
);
9092
}
93+
if (type === 'date') {
94+
return (
95+
<DatetimeWidget
96+
id={`field-${id}`}
97+
title="date"
98+
value={value || defaultValue}
99+
onChange={onChangeDate}
100+
onBlur={onBlur}
101+
/>
102+
);
103+
}
91104
return (
92105
<Input
93106
id={`field-${id}`}
@@ -113,6 +126,9 @@ const EditableCell = ({
113126
state: { pageIndex, pageSize },
114127
}) => {
115128
const fieldSchema = { ...schema?.properties?.[id], id: id };
129+
const locale = useSelector((state) => state.intl.locale);
130+
moment.locale(locale);
131+
116132
const [value, setValue] = React.useState(initialValue);
117133
const onChange = (e) => {
118134
setValue(e.target.value);
@@ -126,6 +142,12 @@ const EditableCell = ({
126142
}
127143
};
128144

145+
const onChangeDate = (e, dateValue) => {
146+
// console.log(dateValue);
147+
setValue(dateValue);
148+
149+
};
150+
129151
const onBlur = () => {
130152
updateCell(index, id, value);
131153
};
@@ -140,6 +162,7 @@ const EditableCell = ({
140162
value={value}
141163
onChange={onChange}
142164
onChangeSelect={onChangeSelect}
165+
onChangeDate={onChangeDate}
143166
onBlur={onBlur}
144167
reactSelect={reactSelect}
145168
/>
@@ -158,7 +181,7 @@ const EditableCell = ({
158181
setSelectedRow(index);
159182
}}
160183
>
161-
{!fieldSchema.isMulti ? (
184+
{fieldSchema.type === 'date' && value ? (moment(value).format('LLL')) : !fieldSchema.isMulti ? (
162185
value || <>&nbsp;</>
163186
) : value ? (
164187
value.join(', ')

0 commit comments

Comments
 (0)