Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3719 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3719 Rev 3748
Línea 4... Línea 4...
4
import Datetime from 'react-datetime';
4
import Datetime from 'react-datetime';
Línea 5... Línea 5...
5
 
5
 
Línea 6... Línea 6...
6
import FormErrorFeedback from '@components/UI/form/FormErrorFeedback';
6
import FormErrorFeedback from '@components/UI/form/FormErrorFeedback';
-
 
7
 
Línea 7... Línea 8...
7
 
8
import 'react-datetime/css/react-datetime.css';
8
import 'react-datetime/css/react-datetime.css';
9
import Input from '@components/UI/inputs/Input';
9
 
10
 
10
export default function DatetimePicker({
11
export default function DatetimePicker({
11
  control,
12
  control,
12
  rules,
13
  rules,
13
  name = '',
14
  name = '',
14
  label = '',
15
  label = '',
15
  displayTime = false,
16
  displayTime = false,
16
  dateFormat = 'DD-MM-YYYY',
17
  dateFormat = 'DD-MM-YYYY',
17
  parseFormat = 'YYYY-MM-DD',
18
  parseFormat = 'YYYY-MM-DD',
18
  defaultValue
19
  color = 'primary'
19
}) {
20
}) {
20
  return (
21
  return (
21
    <Controller
22
    <Controller
22
      name={name}
23
      name={name}
-
 
24
      control={control}
-
 
25
      rules={rules}
-
 
26
      render={({ field: { onChange, ref, name, value }, fieldState: { error } }) => {
-
 
27
        const handleChange = (e) => {
-
 
28
          onChange(e.format(parseFormat));
-
 
29
        };
-
 
30
 
23
      control={control}
31
        const parsedValue = value ? new Date(value) : null;
24
      rules={rules}
32
 
25
      render={({ field: { onChange, ref, value, name }, fieldState: { error } }) => (
33
        return (
26
        <>
34
          <>
27
          {label && <InputLabel>{label}</InputLabel>}
35
            {label && <InputLabel>{label}</InputLabel>}
28
          <Datetime
36
            <Datetime
-
 
37
              dateFormat={dateFormat}
29
            dateFormat={dateFormat}
38
              onChange={handleChange}
30
            onChange={(e) => onChange(e.format(parseFormat))}
39
              timeFormat={displayTime}
31
            timeFormat={displayTime}
40
              renderInput={(props) => <Input {...props} color={color} />}
32
            inputProps={{
41
              inputProps={{
33
              className: 'form-control',
42
                className: 'form-control',
34
              ref,
43
                ref,
35
              name,
44
                name,
36
              autoComplete: 'off'
-
 
37
            }}
45
                autoComplete: 'off'
38
            value={value}
46
              }}
39
            initialValue={defaultValue}
47
              value={parsedValue}
40
            closeOnSelect
48
              closeOnSelect
-
 
49
            />
41
          />
50
            {error && <FormErrorFeedback>{error.message}</FormErrorFeedback>}
42
          {error && <FormErrorFeedback>{error.message}</FormErrorFeedback>}
51
          </>
43
        </>
52
        );
44
      )}
53
      }}