1 import { withFormik } from 'formik';
2 import PropTypes from 'prop-types';
3 import React from 'react';
4 import { Button, Col, Form, Modal, Row } from 'react-bootstrap';
5 import { useTranslation } from 'react-i18next';
7 import { getTranslation } from '../../helpers/Technique';
8 import yup from '../../schema/yup';
10 const ContentForm = ({
19 const { t } = useTranslation();
21 return <Form noValidate onSubmit={handleSubmit}>
24 <Form.Group as={Col} md={6} controlId="content.title">
25 <Form.Label>{t('content.title')}</Form.Label>
27 isInvalid={!!(touched.title && errors.title)}
30 onChange={handleChange}
32 value={values.title || ''}
36 <Form.Group controlId="content.short">
37 <Form.Label>{t('content.short')}</Form.Label>
40 isInvalid={!!(touched.short && errors.short)}
43 onChange={handleChange}
45 value={values.short || ''}
48 <Form.Group controlId="content.description">
49 <Form.Label>{t('content.description')}</Form.Label>
52 isInvalid={!!(touched.description && errors.description)}
55 onChange={handleChange}
57 value={values.description || ''}
60 <Form.Group controlId="content.attribution">
61 <Form.Label>{t('content.attribution')}</Form.Label>
64 isInvalid={!!(touched.attribution && errors.attribution)}
67 onChange={handleChange}
69 value={values.attribution || ''}
75 <Button onClick={onCancel} variant="secondary">
79 <Button type="submit" variant="primary">
86 ContentForm.propTypes = {
87 errors: PropTypes.shape({
88 attribution: PropTypes.string,
89 description: PropTypes.string,
90 short: PropTypes.string,
91 title: PropTypes.string,
93 handleBlur: PropTypes.func,
94 handleChange: PropTypes.func,
95 handleSubmit: PropTypes.func,
96 onCancel: PropTypes.func,
97 touched: PropTypes.shape({
98 attribution: PropTypes.bool,
99 description: PropTypes.bool,
100 short: PropTypes.bool,
101 title: PropTypes.bool,
103 values: PropTypes.shape({
104 attribution: PropTypes.string,
105 description: PropTypes.string,
106 short: PropTypes.string,
107 title: PropTypes.string,
111 export default withFormik({
112 displayName: 'ContentForm',
113 enableReinitialize: true,
114 handleSubmit: async (values, actions) => {
115 const { onSubmit } = actions.props;
116 await onSubmit(values);
118 mapPropsToValues: ({ content, language }) => ({
119 attribution: getTranslation(content, 'attribution', language),
120 description: getTranslation(content, 'description', language),
121 id: (content && content.id) || null,
123 short: getTranslation(content, 'short', language),
124 title: getTranslation(content, 'title', language),
126 validationSchema: yup.object().shape({
127 attribution: yup.string(),
128 description: yup.string(),