diff --git a/package/client/resource/interface/input.ts b/package/client/resource/interface/input.ts index a03ddbb..00895b4 100644 --- a/package/client/resource/interface/input.ts +++ b/package/client/resource/interface/input.ts @@ -29,6 +29,7 @@ interface InputDialogRowProps { step?: number; required?: boolean; format?: string; + returnString?: boolean; description?: string; } diff --git a/resource/interface/client/input.lua b/resource/interface/client/input.lua index 6b61f34..ace10f7 100644 --- a/resource/interface/client/input.lua +++ b/resource/interface/client/input.lua @@ -17,6 +17,7 @@ local input ---@field autosize? boolean ---@field required? boolean ---@field format? string +---@field returnString? boolean ---@field clearable? string ---@field description? string diff --git a/web/src/features/dialog/InputDialog.tsx b/web/src/features/dialog/InputDialog.tsx index 8e204fc..580c5df 100644 --- a/web/src/features/dialog/InputDialog.tsx +++ b/web/src/features/dialog/InputDialog.tsx @@ -14,7 +14,8 @@ import ColorField from './components/fields/color'; import DateField from './components/fields/date'; import TextareaField from './components/fields/textarea'; import TimeField from './components/fields/time'; -import type { InputProps } from '../../typings'; +import type { IDateInput, InputProps } from '../../typings'; +import dayjs from 'dayjs'; export type FormValues = { test: { @@ -80,6 +81,14 @@ const InputDialog: React.FC = () => { const onSubmit = form.handleSubmit(async (data) => { setVisible(false); const values: any[] = []; + for (let i = 0; i < fields.rows.length; i++) { + const row = fields.rows[i]; + + if ((row.type === 'date' || row.type === 'date-range') && row.returnString) { + if (!data.test[i]) continue; + data.test[i].value = dayjs(data.test[i].value).format(row.format || 'DD/MM/YYYY'); + } + } Object.values(data.test).forEach((obj: { value: any }) => values.push(obj.value)); await new Promise((resolve) => setTimeout(resolve, 200)); form.reset(); diff --git a/web/src/features/dialog/components/fields/date.tsx b/web/src/features/dialog/components/fields/date.tsx index ec05f9c..30dca2e 100644 --- a/web/src/features/dialog/components/fields/date.tsx +++ b/web/src/features/dialog/components/fields/date.tsx @@ -1,7 +1,7 @@ import { IDateInput } from '../../../../typings/dialog'; import { Control, useController } from 'react-hook-form'; import { FormValues } from '../../InputDialog'; -import { DatePicker, DateRangePicker, TimeInput } from '@mantine/dates'; +import { DatePicker, DateRangePicker } from '@mantine/dates'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; interface Props { @@ -51,9 +51,7 @@ const DateField: React.FC = (props) => { name={controller.field.name} ref={controller.field.ref} onBlur={controller.field.onBlur} - onChange={(dates) => - controller.field.onChange(dates.map((date: Date | null) => (date ? date.getTime() : null))) - } + onChange={(dates) => controller.field.onChange(dates.map((date: Date | null) => date ? date.getTime() : null))} label={props.row.label} description={props.row.description} placeholder={props.row.format} diff --git a/web/src/typings/dialog.ts b/web/src/typings/dialog.ts index c90ec37..c535449 100644 --- a/web/src/typings/dialog.ts +++ b/web/src/typings/dialog.ts @@ -59,6 +59,7 @@ export interface IColorInput extends BaseField<'color', string> { export interface IDateInput extends Omit, 'placeholder'> { format?: string; + returnString?: boolean; clearable?: boolean; min?: string; max?: string;