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 HTMLInput from '../common/HTMLInput';
8 import { getTranslation } from '../../helpers/Technique';
9 import yup from '../../schema/yup';
11 const ContentForm = ({
20 const { t } = useTranslation();
22 return <Form noValidate onSubmit={handleSubmit}>
25 <Form.Group as={Col} md={6} controlId="content.title">
26 <Form.Label>{t('content.title')}</Form.Label>
28 isInvalid={!!(touched.title && errors.title)}
31 onChange={handleChange}
33 value={values.title || ''}
37 <Form.Group controlId="content.short">
38 <Form.Label>{t('content.short')}</Form.Label>
41 isInvalid={!!(touched.short && errors.short)}
44 onChange={handleChange}
46 value={values.short || ''}
49 <Form.Group controlId="content.description">
50 <Form.Label>{t('content.description')}</Form.Label>
53 isInvalid={!!(touched.description && errors.description)}
56 onChange={handleChange}
58 value={values.description || ''}
61 <Form.Group controlId="content.attribution">
62 <Form.Label>{t('content.attribution')}</Form.Label>
65 isInvalid={!!(touched.attribution && errors.attribution)}
68 onChange={handleChange}
70 value={values.attribution || ''}
76 <Button onClick={onCancel} variant="secondary">
80 <Button type="submit" variant="primary">
87 ContentForm.propTypes = {
88 errors: PropTypes.shape({
89 attribution: PropTypes.string,
90 description: PropTypes.string,
91 short: PropTypes.string,
92 title: PropTypes.string,
94 handleBlur: PropTypes.func,
95 handleChange: PropTypes.func,
96 handleSubmit: PropTypes.func,
97 onCancel: PropTypes.func,
98 touched: PropTypes.shape({
99 attribution: PropTypes.bool,
100 description: PropTypes.bool,
101 short: PropTypes.bool,
102 title: PropTypes.bool,
104 values: PropTypes.shape({
105 attribution: PropTypes.string,
106 description: PropTypes.string,
107 short: PropTypes.string,
108 title: PropTypes.string,
112 export default withFormik({
113 displayName: 'ContentForm',
114 enableReinitialize: true,
115 handleSubmit: async (values, actions) => {
116 const { onSubmit } = actions.props;
117 await onSubmit(values);
119 mapPropsToValues: ({ content, language }) => ({
120 attribution: getTranslation(content, 'attribution', language),
121 description: getTranslation(content, 'description', language),
122 id: (content && content.id) || null,
124 short: getTranslation(content, 'short', language),
125 title: getTranslation(content, 'title', language),
127 validationSchema: yup.object().shape({
128 attribution: yup.string(),
129 description: yup.string(),