diff --git a/packages/nextjs/app/admin/_components/SubmissionCard.tsx b/packages/nextjs/app/admin/_components/SubmissionCard.tsx index f37200a..0e12ba4 100644 --- a/packages/nextjs/app/admin/_components/SubmissionCard.tsx +++ b/packages/nextjs/app/admin/_components/SubmissionCard.tsx @@ -2,18 +2,15 @@ import { useRouter } from "next/navigation"; import { SubmissionComments } from "./SubmissionComments"; +import { SubmissionEligible } from "./SubmissionEligible"; import "./submission-rating.css"; import { useMutation } from "@tanstack/react-query"; import { useAccount } from "wagmi"; -import { QuestionMarkCircleIcon } from "@heroicons/react/24/outline"; import { Address } from "~~/components/scaffold-eth"; import { Submission } from "~~/services/database/repositories/submissions"; -import { getFormattedDateTime } from "~~/utils/date"; import { postMutationFetcher } from "~~/utils/react-query"; import { notification } from "~~/utils/scaffold-eth"; -const eligibleLabelStyles = "label cursor-pointer text-sm justify-start gap-2"; - export const SubmissionCard = ({ submission }: { submission: Submission }) => { const { address: connectedAddress } = useAccount(); @@ -21,10 +18,6 @@ export const SubmissionCard = ({ submission }: { submission: Submission }) => { mutationFn: (newVote: { score: number }) => postMutationFetcher(`/api/submissions/${submission.id}/votes`, { body: newVote }), }); - const { mutateAsync: postNewEligible } = useMutation({ - mutationFn: (newEligible: { eligible: boolean; clear: boolean }) => - postMutationFetcher(`/api/submissions/${submission.id}/eligible`, { body: newEligible }), - }); const { refresh } = useRouter(); const vote = async (newScore: number) => { @@ -47,36 +40,6 @@ export const SubmissionCard = ({ submission }: { submission: Submission }) => { } }; - const setEligible = async (newEligible: boolean) => { - try { - const result = await postNewEligible({ eligible: newEligible, clear: false }); - - notification.success(result.message); - refresh(); - } catch (error: any) { - if (error instanceof Error) { - notification.error(error.message); - return; - } - notification.error("Something went wrong"); - } - }; - - const clearEligible = async () => { - try { - const result = await postNewEligible({ eligible: false, clear: true }); - - notification.success(result.message); - refresh(); - } catch (error: any) { - if (error instanceof Error) { - notification.error(error.message); - return; - } - notification.error("Something went wrong"); - } - }; - const scoreAvg = submission.votes.length > 0 ? (submission.votes.map(vote => vote.score).reduce((a, b) => a + b, 0) / submission.votes.length).toFixed(2) @@ -88,7 +51,8 @@ export const SubmissionCard = ({ submission }: { submission: Submission }) => { return (
-
+ +

{submission.title}

@@ -117,62 +81,6 @@ export const SubmissionCard = ({ submission }: { submission: Submission }) => {
-
-
- -
-
- -
-
- {submission.eligible === false && ( -
- -
- )} - - {submission.eligible === true && ( -
- -
- )} - - {submission.eligible !== undefined && ( - - )} -
-
- -
-
{ + const { mutateAsync: postNewEligible } = useMutation({ + mutationFn: (newEligible: { eligible: boolean; clear: boolean }) => + postMutationFetcher(`/api/submissions/${submission.id}/eligible`, { body: newEligible }), + }); + const { refresh } = useRouter(); + + const setEligible = async (newEligible: boolean) => { + try { + const result = await postNewEligible({ eligible: newEligible, clear: false }); + + notification.success(result.message); + refresh(); + } catch (error: any) { + if (error instanceof Error) { + notification.error(error.message); + return; + } + notification.error("Something went wrong"); + } + }; + + const clearEligible = async () => { + try { + const result = await postNewEligible({ eligible: false, clear: true }); + + notification.success(result.message); + refresh(); + } catch (error: any) { + if (error instanceof Error) { + notification.error(error.message); + return; + } + notification.error("Something went wrong"); + } + }; + + let buttonLabel = "Eligibility"; + if (submission.eligible === false) { + buttonLabel = "Not Eligible"; + } + if (submission.eligible === true) { + buttonLabel = "Eligible"; + } + + console.log("submission", submission.eligible); + + return ( +
+ + {buttonLabel} + +
+
+
+ +
+
+ +
+
+ {submission.eligible !== undefined && ( + + )} + + {submission.eligible === false && ( +
+ +
+ )} + + {submission.eligible === true && ( +
+ +
+ )} +
+
+
+
+ ); +};