This commit is contained in:
Vitalii Kiiko
2024-08-20 12:57:23 +02:00
parent e0399608ee
commit 74d2da78d6
10 changed files with 519 additions and 299 deletions

View File

@@ -1,7 +1,9 @@
import React from 'react';
import { classNames } from 'primereact/utils';
import { isEmpty, isNil } from 'ramda';
// components
import { Controller } from 'react-hook-form';
import { isNil } from 'ramda';
import { Calendar } from 'primereact/calendar';
const DatepickerRange = ({
@@ -15,6 +17,7 @@ const DatepickerRange = ({
minDate = null,
maxDate = null
}) => {
const datesDefaultValue = !isNil(defaultValue) && !isEmpty(defaultValue) && defaultValue.length ? defaultValue.map(v => new Date(v)) : [];
return (
<>
<label htmlFor={fieldName} className={classNames({ 'p-error': errors[fieldName] })}>
@@ -23,16 +26,24 @@ const DatepickerRange = ({
<Controller
name={fieldName}
control={control}
defaultValue={defaultValue}
defaultValue={datesDefaultValue}
rules={config}
render={({ field, fieldState }) => (
<Calendar id={field.name}
value={field.value}
onChange={(e) => field.onChange(e.value)}
dateFormat="dd/mm/yy" mask="99/99/9999"
onChange={(e) => {
const formattedValues = e.value.map(d => d ? d.toISOString() : d);
console.log('formattedValues', formattedValues);
field.onChange(formattedValues)
}}
dateFormat="dd/mm/yy"
mask="99/99/9999"
showIcon
minDate={minDate} maxDate={maxDate}
selectionMode="range" readOnlyInput hideOnRangeSelection
minDate={minDate}
maxDate={maxDate}
selectionMode="range"
readOnlyInput
hideOnRangeSelection
className={classNames({ 'p-invalid': fieldState.invalid })}/>
)}/>
{infoText ? <small>{infoText}</small> : null}

View File

@@ -15,7 +15,8 @@ const Fileupload = ({
accept = 'image/*',
api = '/api/upload',
emptyText = __('Trascina qui il tuo file', 'gepafin'),
chooseLabel = __('Aggiungi immagine', 'gepafin')
chooseLabel = __('Aggiungi immagine', 'gepafin'),
multiple = false
}) => {
return (
<>
@@ -32,7 +33,7 @@ const Fileupload = ({
id={field.name}
name={`${field.name}[]`}
url={api}
multiple
multiple={multiple}
accept={accept}
maxFileSize={1000000}
emptyTemplate={<p>{emptyText}</p>}