From c80f9cb9db2c8f9e74fbbd055334d24a73ec62c4 Mon Sep 17 00:00:00 2001 From: Kathryn Beaty Date: Wed, 1 Nov 2023 11:50:10 -0400 Subject: [PATCH] refactor reportmakedecisionmodal into own component --- .../Reports/ReportMakeDecisionModal.css | 11 + .../Reports/ReportMakeDecisionModal.tsx | 197 ++++++++++++++++++ .../admin/routes/Reports/ReportStatusMenu.css | 1 + .../routes/Reports/SingleReportRoute.css | 18 +- .../routes/Reports/SingleReportRoute.tsx | 163 +-------------- 5 files changed, 224 insertions(+), 166 deletions(-) create mode 100644 client/src/core/client/admin/routes/Reports/ReportMakeDecisionModal.css create mode 100644 client/src/core/client/admin/routes/Reports/ReportMakeDecisionModal.tsx diff --git a/client/src/core/client/admin/routes/Reports/ReportMakeDecisionModal.css b/client/src/core/client/admin/routes/Reports/ReportMakeDecisionModal.css new file mode 100644 index 0000000000..33c48638a2 --- /dev/null +++ b/client/src/core/client/admin/routes/Reports/ReportMakeDecisionModal.css @@ -0,0 +1,11 @@ +.decisionModalThisComment { + margin-right: var(--spacing-2); +} + +.decisionModalTextArea { + flex-grow: 1; +} + +.yesButton { + margin-right: var(--spacing-2); +} diff --git a/client/src/core/client/admin/routes/Reports/ReportMakeDecisionModal.tsx b/client/src/core/client/admin/routes/Reports/ReportMakeDecisionModal.tsx new file mode 100644 index 0000000000..586d196212 --- /dev/null +++ b/client/src/core/client/admin/routes/Reports/ReportMakeDecisionModal.tsx @@ -0,0 +1,197 @@ +import { FormApi } from "final-form"; +import React, { FunctionComponent, useCallback, useState } from "react"; +import { Field, Form } from "react-final-form"; +import { graphql } from "react-relay"; + +import ModalHeader from "coral-admin/components/ModalHeader"; +import { useMutation, withFragmentContainer } from "coral-framework/lib/relay"; +import { required } from "coral-framework/lib/validation"; +import { + Button, + Card, + CardCloseButton, + Flex, + HorizontalGutter, + Modal, + Textarea, +} from "coral-ui/components/v2"; + +import MakeReportDecisionMutation from "./MakeReportDecisionMutation"; + +import { ReportMakeDecisionModal_dsaReport } from "coral-admin/__generated__/ReportMakeDecisionModal_dsaReport.graphql"; + +import styles from "./ReportMakeDecisionModal.css"; + +interface Props { + dsaReport: ReportMakeDecisionModal_dsaReport; + showDecisionModal: boolean; + setShowDecisionModal: (show: boolean) => void; + userID?: string; +} + +const ReportMakeDecisionModal: FunctionComponent = ({ + dsaReport, + showDecisionModal, + setShowDecisionModal, + userID, +}) => { + const makeReportDecision = useMutation(MakeReportDecisionMutation); + const [makeDecisionSelection, setMakeDecisionSelection] = useState< + null | string + >(null); + const onClickMakeDecisionContainsIllegal = useCallback(() => { + setMakeDecisionSelection("YES"); + }, [setMakeDecisionSelection]); + + const onClickMakeDecisionDoesNotContainIllegal = useCallback(() => { + setMakeDecisionSelection("NO"); + }, [setMakeDecisionSelection]); + + const onSubmitDecision = useCallback( + async (input: any, form: FormApi) => { + if (dsaReport && userID && dsaReport.comment?.revision) { + try { + await makeReportDecision({ + userID, + reportID: dsaReport.id, + legality: makeDecisionSelection === "YES" ? "ILLEGAL" : "LEGAL", + legalGrounds: + makeDecisionSelection === "YES" ? input.legalGrounds : undefined, + detailedExplanation: + makeDecisionSelection === "YES" ? input.explanation : undefined, + commentID: dsaReport.comment?.id, + commentRevisionID: dsaReport.comment.revision.id, + storyID: dsaReport.comment.story.id, + }); + setShowDecisionModal(false); + } catch (e) { + // eslint-disable-next-line no-console + console.error(e); + } + } + }, + [ + makeReportDecision, + userID, + dsaReport, + makeDecisionSelection, + setShowDecisionModal, + ] + ); + const onCloseDecisionModal = useCallback(() => { + setShowDecisionModal(false); + }, [setShowDecisionModal]); + return ( + + {({ firstFocusableRef }) => ( + + + + + Decision + {/* TODO: Localize all of this */} +
+ {({ handleSubmit, hasValidationErrors }) => ( + + + + +
+ Does this comment appear to contain illegal content? +
+ + + + +
+ {makeDecisionSelection === "YES" && ( + <> + + + {({ input }) => ( +