diff --git a/package.json b/package.json index 40644d8..82fb6be 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "copy-to-clipboard": "^3.3.1", "date-fns": "^2.16.1", "material-table": "^1.69.1", + "material-ui-color": "^0.4.6", "react": "^16.14.0", "react-dom": "^16.14.0", "react-redux": "^7.2.1", @@ -19,7 +20,6 @@ "react-scripts": "^3.4.4", "redux": "^4.0.5", "redux-promise-middleware": "^6.1.0", - "redux-thunk": "^2.3.0", "use-deep-compare-effect": "^1.4.0" }, "scripts": { diff --git a/src/components/common/FieldGenerator.jsx b/src/components/common/FieldGenerator.jsx index 43ae477..7aacfa2 100644 --- a/src/components/common/FieldGenerator.jsx +++ b/src/components/common/FieldGenerator.jsx @@ -1,147 +1,165 @@ -import React from 'react'; -import { - TextField, Checkbox, FormControlLabel, - FormControl, InputLabel, Select, MenuItem, Chip -} from '@material-ui/core'; -import { KeyboardDateTimePicker } from '@material-ui/pickers'; -// import CheckInput from './CheckInput'; - -class FieldGenerator { - - // TODO Finish error texts - - constructor(store, errors, onChange, keyPrefix = null, defaultProps = null) { - this.store = store; - this.errors = errors; - this.onChange = onChange; - this.keyPrefix = keyPrefix; - this.defaultProps = defaultProps; - } - - onChangeDatetime = name => value => { - const fakeEvent = { target: { name, value } }; - return this.onChange(fakeEvent); - } - - getKey = (key) => (this.keyPrefix ? `${this.keyPrefix}.${key}` : key) - - getValue = (key, params) => ( - key.split('.').reduce((props, step) => props[step], this.store) || params.default - ) - - getProps = (props) => ( - this.defaultProps ? { ...this.defaultProps, ...props } : props - ) - - displayErrors = (key) => ( - this.errors[key] ? this.errors[key].join('
') : '' - ) - - text = (key, label, props = {}) => ( - - ) - - number = (key, label, props = {}) => ( - - ) - - boolean = (key, label, props = {}) => ( - - } - /> - ) - - datetime = (key, label, props = {}) => ( - - ) - - select = (key, label, choices, props = {}) => ( - - {label} - - - ) - - selectChips = (key, label, choices, props = {}) => ( - - {label} - - - ) -} - -export default FieldGenerator; +import React from 'react'; +import { + TextField, Checkbox, FormControlLabel, + FormControl, InputLabel, Select, MenuItem, Chip +} from '@material-ui/core'; +import { KeyboardDateTimePicker } from '@material-ui/pickers'; +import { ColorPicker } from 'material-ui-color'; +// import CheckInput from './CheckInput'; + +class FieldGenerator { + + // TODO Finish error texts + + constructor(store, errors, onChange, keyPrefix = null, defaultProps = null) { + this.store = store; + this.errors = errors; + this.onChange = onChange; + this.keyPrefix = keyPrefix; + this.defaultProps = defaultProps; + } + + onChangeDatetime = name => value => { + const fakeEvent = { target: { name, value } }; + return this.onChange(fakeEvent); + } + + onChangeColor = name => color => { + const fakeEvent = { target: { name, value: `#${color.hex}` } }; + return this.onChange(fakeEvent); + } + + getKey = (key) => (this.keyPrefix ? `${this.keyPrefix}.${key}` : key) + + getValue = (key, params) => ( + key.split('.').reduce((props, step) => props[step], this.store) || params.default + ) + + getProps = (props) => ( + this.defaultProps ? { ...this.defaultProps, ...props } : props + ) + + displayErrors = (key) => ( + this.errors[key] ? this.errors[key].join('
') : '' + ) + + text = (key, label, props = {}) => ( + + ) + + number = (key, label, props = {}) => ( + + ) + + boolean = (key, label, props = {}) => ( + + } + /> + ) + + datetime = (key, label, props = {}) => ( + + ) + + select = (key, label, choices, props = {}) => ( + + {label} + + + ) + + selectChips = (key, label, choices, props = {}) => ( + + {label} + + + ) + + color = (key, label, props = {}) => ( + + {label} +
+ +
+
+ ) +} + +export default FieldGenerator; diff --git a/src/pages/admin/SaleEditor/DetailsEditor.jsx b/src/pages/admin/SaleEditor/DetailsEditor.jsx index fd31626..a3bb540 100644 --- a/src/pages/admin/SaleEditor/DetailsEditor.jsx +++ b/src/pages/admin/SaleEditor/DetailsEditor.jsx @@ -1,8 +1,8 @@ import React from 'react'; import { Box, Paper, Grid, Button } from '@material-ui/core'; -import { LoadingButton } from 'components/common/Buttons'; import FieldGenerator from 'components/common/FieldGenerator'; +import { LoadingButton } from 'components/common/Buttons'; import { mergeClasses, useFormStyles } from 'utils/styles'; export default function DetailsEditor({ disabled, editing, isCreator, ...props }) { @@ -20,6 +20,7 @@ export default function DetailsEditor({ disabled, editing, isCreator, ...props } {Field.text('id', 'ID', onlyCreate)} {Field.select('association', 'Association', props.assos, onlyCreate)} {Field.text('description', 'Description', { required: true, multiline: true, rows: 4 })} + {Field.color('color', 'Couleur')} diff --git a/src/utils/constants.js b/src/utils/constants.js index 7acc20d..82d647f 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -65,6 +65,8 @@ export const BLANK_SALE_DETAILS = { begin_at: null, end_at: null, + + color:"", }; export const BLANK_ITEMGROUP = {