From a6ff5eee45215effb3344cb5d631a27a7c0369aa Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 22 Sep 2023 19:34:01 +0200 Subject: refactor(components): rewrite form components --- src/components/organisms/forms/contact-form.tsx | 154 ------------------------ 1 file changed, 154 deletions(-) delete mode 100644 src/components/organisms/forms/contact-form.tsx (limited to 'src/components/organisms/forms/contact-form.tsx') diff --git a/src/components/organisms/forms/contact-form.tsx b/src/components/organisms/forms/contact-form.tsx deleted file mode 100644 index ca84c25..0000000 --- a/src/components/organisms/forms/contact-form.tsx +++ /dev/null @@ -1,154 +0,0 @@ -import { FC, ReactNode, useState } from 'react'; -import { useIntl } from 'react-intl'; -import { Button, Form, Spinner } from '../../atoms'; -import { LabelledField } from '../../molecules'; -import styles from './contact-form.module.scss'; - -export type ContactFormData = { - email: string; - message: string; - name: string; - subject: string; -}; - -export type ContactFormProps = { - /** - * Set additional classnames to the form wrapper. - */ - className?: string; - /** - * Pass a component to print a success/error message. - */ - Notice?: ReactNode; - /** - * A callback function to send mail. - */ - sendMail: (data: ContactFormData, reset: () => void) => Promise; -}; - -/** - * ContactForm component - * - * Render a contact form. - */ -export const ContactForm: FC = ({ - className = '', - Notice, - sendMail, -}) => { - const intl = useIntl(); - const [name, setName] = useState(''); - const [email, setEmail] = useState(''); - const [object, setObject] = useState(''); - const [message, setMessage] = useState(''); - const [isSubmitting, setIsSubmitting] = useState(false); - - /** - * Reset all the form fields. - */ - const resetForm = () => { - setName(''); - setEmail(''); - setObject(''); - setMessage(''); - setIsSubmitting(false); - }; - - const formName = intl.formatMessage({ - defaultMessage: 'Contact form', - description: 'ContactForm: form accessible name', - id: 'HFdzae', - }); - - const nameLabel = intl.formatMessage({ - defaultMessage: 'Name:', - description: 'ContactForm: name label', - id: '1dCuCx', - }); - - const emailLabel = intl.formatMessage({ - defaultMessage: 'Email:', - description: 'ContactForm: email label', - id: 'w4B5PA', - }); - - const objectLabel = intl.formatMessage({ - defaultMessage: 'Object:', - description: 'ContactForm: object label', - id: 's8/tyz', - }); - - const messageLabel = intl.formatMessage({ - defaultMessage: 'Message:', - description: 'ContactForm: message label', - id: 'yN5P+m', - }); - - const submitHandler = async () => { - setIsSubmitting(true); - sendMail({ email, message, name, subject: object }, resetForm).then(() => - setIsSubmitting(false) - ); - }; - - return ( -
- - - - - - {isSubmitting && ( - - )} - {Notice} - - ); -}; -- cgit v1.2.3