From 4d2908b9a88bc39e460cbc16136a203941fd4d3d Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Thu, 25 Feb 2021 15:40:30 +0200 Subject: [PATCH] can add suggestion comment + tests --- components/plus/PlusHomePage.tsx | 4 +-- components/plus/Suggestion.tsx | 42 ++++++++++++++++-------- components/plus/SuggestionVouchModal.tsx | 36 +++++++++++++++----- cypress/integration/plus.spec.ts | 42 ++++++++++++++++++++++-- cypress/support/index.ts | 4 +++ hooks/useMutation.ts | 6 ++-- lib/validators/suggestion.ts | 7 +++- prisma/mocks/plus.ts | 2 +- services/plus.ts | 11 +++++-- 9 files changed, 119 insertions(+), 35 deletions(-) diff --git a/components/plus/PlusHomePage.tsx b/components/plus/PlusHomePage.tsx index 8b3e6e6c1..0483c5da4 100644 --- a/components/plus/PlusHomePage.tsx +++ b/components/plus/PlusHomePage.tsx @@ -30,7 +30,7 @@ const PlusHomePage: React.FC = () => { <> {plusStatusData && plusStatusData.membershipTier && ( @@ -63,7 +63,7 @@ const PlusHomePage: React.FC = () => { +2 ({suggestionCounts.TWO}) - + +3 ({suggestionCounts.THREE}) diff --git a/components/plus/Suggestion.tsx b/components/plus/Suggestion.tsx index 19b5ebc63..ed7f36aaa 100644 --- a/components/plus/Suggestion.tsx +++ b/components/plus/Suggestion.tsx @@ -16,7 +16,7 @@ import useMutation from "hooks/useMutation"; import { getFullUsername } from "lib/strings"; import { Unpacked } from "lib/types"; import { - suggestionSchema, + resuggestionSchema, SUGGESTION_DESCRIPTION_LIMIT, } from "lib/validators/suggestion"; import { useState } from "react"; @@ -24,7 +24,7 @@ import { useForm } from "react-hook-form"; import { Suggestions } from "services/plus"; import * as z from "zod"; -type FormData = z.infer; +type FormData = z.infer; const Suggestion = ({ suggestion, @@ -34,19 +34,14 @@ const Suggestion = ({ canSuggest: boolean; }) => { const [showTextarea, setShowTextarea] = useState(false); - const { handleSubmit, errors, register, watch, control } = useForm({ - resolver: zodResolver(suggestionSchema), - defaultValues: { - // region doesn't matter as it is not updated after the first suggestion - region: "NA", - tier: suggestion.tier, - suggestedId: suggestion.suggestedUser.id, - }, + const { handleSubmit, errors, register, watch } = useForm({ + resolver: zodResolver(resuggestionSchema), }); const { onSubmit, sending } = useMutation({ route: "plus/suggestions", mutationKey: "plus/suggestions", successText: "Comment added", + onSuccess: () => setShowTextarea(false), }); const watchDescription = watch("description", ""); @@ -92,23 +87,44 @@ const Suggestion = ({ size="sm" onClick={() => setShowTextarea(!showTextarea)} mt={4} + data-cy="comment-button" > Add comment )} {showTextarea && ( -
+ + onSubmit({ + ...values, + // region doesn't matter as it is not updated after the first suggestion + region: "NA", + tier: suggestion.tier, + suggestedId: suggestion.suggestedUser.id, + }) + )} + > Comment to suggestion -