From 7e16f500cb7bc0cfd8bafbf6bb1555704f771231 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 29 Apr 2022 12:13:34 +0200 Subject: chore: remove old pages, components, helpers and types Since I'm using new components, I will also rewrite the GraphQL queries so it is easier to start from scratch. --- src/components/CommentForm/CommentForm.module.scss | 25 --- src/components/CommentForm/CommentForm.tsx | 240 --------------------- 2 files changed, 265 deletions(-) delete mode 100644 src/components/CommentForm/CommentForm.module.scss delete mode 100644 src/components/CommentForm/CommentForm.tsx (limited to 'src/components/CommentForm') diff --git a/src/components/CommentForm/CommentForm.module.scss b/src/components/CommentForm/CommentForm.module.scss deleted file mode 100644 index d19a1ef..0000000 --- a/src/components/CommentForm/CommentForm.module.scss +++ /dev/null @@ -1,25 +0,0 @@ -@use "@styles/abstracts/functions" as fun; - -.wrapper { - width: min(calc(100vw - (var(--spacing-md) * 2)), fun.convert-px(500)); - margin: auto; - - &--reply { - width: 100%; - margin-top: var(--spacing-sm); - padding: var(--spacing-md); - position: relative; - background: var(--color-bg); - border: fun.convert-px(1) solid var(--color-border); - box-shadow: fun.convert-px(3) fun.convert-px(3) 0 0 - var(--color-shadow-light), - fun.convert-px(4) fun.convert-px(4) fun.convert-px(3) fun.convert-px(-2) - var(--color-shadow); - } -} - -.title { - width: max-content; - margin-left: auto; - margin-right: auto; -} diff --git a/src/components/CommentForm/CommentForm.tsx b/src/components/CommentForm/CommentForm.tsx deleted file mode 100644 index 128dc58..0000000 --- a/src/components/CommentForm/CommentForm.tsx +++ /dev/null @@ -1,240 +0,0 @@ -import { ButtonSubmit } from '@components/Buttons'; -import { Field, Form, FormItem, Label } from '@components/FormElements'; -import Notice from '@components/Notice/Notice'; -import Spinner from '@components/Spinner/Spinner'; -import { createComment } from '@services/graphql/mutations'; -import { NoticeType } from '@ts/types/app'; -import { useEffect, useRef, useState } from 'react'; -import { useIntl } from 'react-intl'; -import styles from './CommentForm.module.scss'; - -const CommentForm = ({ - articleId, - parentId = 0, -}: { - articleId: number; - parentId?: number; -}) => { - const intl = useIntl(); - const [name, setName] = useState(''); - const [email, setEmail] = useState(''); - const [website, setWebsite] = useState(''); - const [comment, setComment] = useState(''); - const [isSubmitting, setIsSubmitting] = useState(false); - const [notice, setNotice] = useState(); - const [noticeType, setNoticeType] = useState('success'); - const nameFieldRef = useRef(null); - - useEffect(() => { - if (parentId === 0) return; - nameFieldRef.current && nameFieldRef.current.focus(); - }); - - const resetForm = () => { - setName(''); - setEmail(''); - setWebsite(''); - setComment(''); - setIsSubmitting(false); - }; - - const isEmptyString = (value: string): boolean => value.trim() === ''; - const areRequiredFieldsSet = (): boolean => - !isEmptyString(name) && !isEmptyString(email) && !isEmptyString(comment); - - const sendComment = async () => { - const data = { - author: name, - authorEmail: email, - authorUrl: website, - content: comment, - parent: parentId, - commentOn: articleId, - mutationId: 'createComment', - }; - - const createdComment = await createComment(data); - - if (createdComment.success) { - resetForm(); - setNoticeType('success'); - if (createdComment.comment?.approved) { - setNotice( - intl.formatMessage({ - defaultMessage: 'Thanks for your comment!', - description: 'CommentForm: success notice', - id: 'AVUUgG', - }) - ); - } else { - setNotice( - intl.formatMessage({ - defaultMessage: - 'Thanks for your comment! It is now awaiting moderation.', - description: 'CommentForm: success notice but awaiting moderation', - id: 'Ul2NIl', - }) - ); - } - - setTimeout(() => { - setNotice(undefined); - }, 10000); - } else { - setNoticeType('error'); - setNotice( - intl.formatMessage({ - defaultMessage: - 'An unexpected error happened. Comment cannot be submitted.', - description: 'CommentForm: error notice', - id: 'cjK9Ad', - }) - ); - } - }; - - const submitHandler = async (e: SubmitEvent) => { - e.preventDefault(); - setNotice(undefined); - setIsSubmitting(true); - - if (areRequiredFieldsSet()) { - sendComment(); - } else { - setIsSubmitting(false); - setNoticeType('warning'); - setNotice( - intl.formatMessage({ - defaultMessage: - 'Some required fields are empty. Comment cannot be submitted.', - description: 'CommentForm: missing required fields', - id: 'Rle+UK', - }) - ); - } - }; - - const isReply = parentId !== 0; - const wrapperClasses = `${styles.wrapper} ${ - isReply ? styles['wrapper--reply'] : '' - }`; - - const getLabel = ( - body: string, - htmlFor: string, - required: boolean = false - ) => { - return