summaryrefslogtreecommitdiffstats
path: root/front/odiparpack/app/components/Forms/ReduxFormMUI.js
blob: 285543f8ad70397946699add95fad7398d9445d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import React from 'react';
import PropTypes from 'prop-types';
import TextField from '@material-ui/core/TextField';
import Select from '@material-ui/core/Select';
import Checkbox from '@material-ui/core/Checkbox';
import Switch from '@material-ui/core/Switch';
import { DateTimePicker, MuiPickersUtilsProvider } from '@material-ui/pickers';

import { etiqueta } from '../Odipar/common';
import { Chip } from '@material-ui/core';
import MomentUtils from '@date-io/moment';
import moment from 'moment'
import 'moment/locale/es'
moment.locale('es');

/* Textfield */
export const TextFieldRedux = ({ meta: { touched, error }, input, ...rest }) => (
  <TextField
    {...rest}
    {...input}
    error={touched && Boolean(error)}
  />
);

TextFieldRedux.propTypes = {
  input: PropTypes.object.isRequired,
  meta: PropTypes.object,
};

TextFieldRedux.defaultProps = {
  meta: null,
};
/* End */

/* Select */
export const SelectRedux = ({ input, children, ...rest }) => (
  <Select
    {...input}
    {...rest}
  >
    {children}
  </Select>
);

SelectRedux.propTypes = {
  input: PropTypes.object.isRequired,
  children: PropTypes.node.isRequired,
};
/* End */

/* Checkbox */
export const CheckboxRedux = ({ input, ...rest }) => (
  <Checkbox
    checked={input.value === '' ? false : input.value}
    {...input}
    {...rest}
  />
);

CheckboxRedux.propTypes = {
  input: PropTypes.object.isRequired,
};
/* End */

/* Switch */
export const SwitchRedux = ({ input, ...rest }) => (
  <Switch
    checked={input.value === '' ? false : input.value}
    {...input}
    {...rest}
  />
);

SwitchRedux.propTypes = {
  input: PropTypes.object.isRequired,
};
/* End */

export const DatePickerRedux = ({ input, label, readonly}) => (
  
  <MuiPickersUtilsProvider locale={'es'} utils={MomentUtils}>
  <DateTimePicker
      format="DD/MM/YYYY hh:mm A"
      autoOk
      onChange={date => input.onChange(moment(date).format("DD/MM/YYYY hh:mm A"))}
      value={input.value ? moment(input.value,"DD/MM/YYYY hh:mm A"): null}
      label={label}
      readOnly = {readonly}
      disabled = {readonly}
  />
  </MuiPickersUtilsProvider>
);

export const EstadoRedux = ({input, label}) => {
  const value = input.value? input.value : 0
  return etiqueta("etiq_pedido", value)
}