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 -