Commit e9d08265 authored by Rémy Huet's avatar Rémy Huet 💻

Add Category form for Edit. TODO : pass default values

parent 3f538894
Pipeline #30921 passed with stage
in 53 seconds
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { Confirm, Button, Header } from 'semantic-ui-react';
import { submit } from 'redux-form';
import CategoryForm from '../../forms/Category';
function CategoryEdit({ id, dispatch }) {
const handleFormSubmit = (values) => {
// Todo :
dispatch({ type: 'VALUES', payload: values });
};
export default function CategoryEdit({ id }) {
return (
<Confirm
open
cancelButton={<Button as={Link} to={`/categories/show/${id}`}>Retour</Button>}
confirmButton={<Button primary onClick={() => (dispatch(submit('category')))}> OK </Button>}
header={<Header as="h1">Éditer</Header>}
content={
<>
</>
}
<CategoryForm onSubmit={handleFormSubmit} />
}
/>
);
}
CategoryEdit.propTypes = {
id: PropTypes.number.isRequired,
dispatch: PropTypes.func.isRequired,
};
export default connect()(CategoryEdit);
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Field, reduxForm } from 'redux-form';
import {
Form, Input, Container, Segment,
} from 'semantic-ui-react';
import Dropdown from './CustomDropdown';
function CategoryForm({ handleSubmit, categories }) {
const parentOptions = categories.map(({ name, id }) => ({
key: id,
value: id,
text: name,
}));
return (
<Container>
<Segment>
<Form onSubmit={handleSubmit}>
<Form.Field>
<Field name="name" component={Input} placeholder="Nom" />
</Form.Field>
<Form.Field>
<Field name="parentId" component={Dropdown} search selection clearable options={parentOptions} />
</Form.Field>
</Form>
</Segment>
</Container>
);
}
CategoryForm.propTypes = {
handleSubmit: PropTypes.func.isRequired,
categories: PropTypes.arrayOf(PropTypes.shape({
name: PropTypes.string.isRequired,
id: PropTypes.number.isRequired,
})).isRequired,
};
const form = reduxForm({
form: 'category',
})(CategoryForm);
export default connect(store => ({
categories: store.categories.categories,
}))(form);
......@@ -70,6 +70,8 @@ function Categories({
edit: (
<CategoryEdit
id={id}
name={name}
parentId={parentId}
/>
),
delete: (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment