mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
feat(web/input): returnString for date inputs (#411)
* feat(interface/input): useFormat field * feat(interface/input): useFormat field * feat(types/dialog): useFormat field * feat(components/date): format date conversion * tweak(components/date): forgot other data type * chore(interface/input): more descriptive name * chore(interface/input): more descriptive name * chore(types/dialog): more descriptive name * tweak(components/date): reset things * feat(dialog/input): date conversion with returnString * refactor(web/input): remove unnecessary state --------- Co-authored-by: Luke <39926192+LukeWasTakenn@users.noreply.github.com>
This commit is contained in:
@@ -29,6 +29,7 @@ interface InputDialogRowProps {
|
|||||||
step?: number;
|
step?: number;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
format?: string;
|
format?: string;
|
||||||
|
returnString?: boolean;
|
||||||
description?: string;
|
description?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ local input
|
|||||||
---@field autosize? boolean
|
---@field autosize? boolean
|
||||||
---@field required? boolean
|
---@field required? boolean
|
||||||
---@field format? string
|
---@field format? string
|
||||||
|
---@field returnString? boolean
|
||||||
---@field clearable? string
|
---@field clearable? string
|
||||||
---@field description? string
|
---@field description? string
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ import ColorField from './components/fields/color';
|
|||||||
import DateField from './components/fields/date';
|
import DateField from './components/fields/date';
|
||||||
import TextareaField from './components/fields/textarea';
|
import TextareaField from './components/fields/textarea';
|
||||||
import TimeField from './components/fields/time';
|
import TimeField from './components/fields/time';
|
||||||
import type { InputProps } from '../../typings';
|
import type { IDateInput, InputProps } from '../../typings';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
export type FormValues = {
|
export type FormValues = {
|
||||||
test: {
|
test: {
|
||||||
@@ -80,6 +81,14 @@ const InputDialog: React.FC = () => {
|
|||||||
const onSubmit = form.handleSubmit(async (data) => {
|
const onSubmit = form.handleSubmit(async (data) => {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
const values: any[] = [];
|
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));
|
Object.values(data.test).forEach((obj: { value: any }) => values.push(obj.value));
|
||||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||||
form.reset();
|
form.reset();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { IDateInput } from '../../../../typings/dialog';
|
import { IDateInput } from '../../../../typings/dialog';
|
||||||
import { Control, useController } from 'react-hook-form';
|
import { Control, useController } from 'react-hook-form';
|
||||||
import { FormValues } from '../../InputDialog';
|
import { FormValues } from '../../InputDialog';
|
||||||
import { DatePicker, DateRangePicker, TimeInput } from '@mantine/dates';
|
import { DatePicker, DateRangePicker } from '@mantine/dates';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -51,9 +51,7 @@ const DateField: React.FC<Props> = (props) => {
|
|||||||
name={controller.field.name}
|
name={controller.field.name}
|
||||||
ref={controller.field.ref}
|
ref={controller.field.ref}
|
||||||
onBlur={controller.field.onBlur}
|
onBlur={controller.field.onBlur}
|
||||||
onChange={(dates) =>
|
onChange={(dates) => controller.field.onChange(dates.map((date: Date | null) => date ? date.getTime() : null))}
|
||||||
controller.field.onChange(dates.map((date: Date | null) => (date ? date.getTime() : null)))
|
|
||||||
}
|
|
||||||
label={props.row.label}
|
label={props.row.label}
|
||||||
description={props.row.description}
|
description={props.row.description}
|
||||||
placeholder={props.row.format}
|
placeholder={props.row.format}
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ export interface IColorInput extends BaseField<'color', string> {
|
|||||||
export interface IDateInput
|
export interface IDateInput
|
||||||
extends Omit<BaseField<'date' | 'date-range', string | [string, string] | true>, 'placeholder'> {
|
extends Omit<BaseField<'date' | 'date-range', string | [string, string] | true>, 'placeholder'> {
|
||||||
format?: string;
|
format?: string;
|
||||||
|
returnString?: boolean;
|
||||||
clearable?: boolean;
|
clearable?: boolean;
|
||||||
min?: string;
|
min?: string;
|
||||||
max?: string;
|
max?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user