Skip to content

Commit

Permalink
Get submission type from schema
Browse files Browse the repository at this point in the history
  • Loading branch information
damianmarti committed Aug 1, 2024
1 parent 9d2ee17 commit a777476
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
11 changes: 3 additions & 8 deletions packages/nextjs/app/api/submissions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NextResponse } from "next/server";
import { recoverTypedDataAddress } from "viem";
import { createBuilder, getBuilderById } from "~~/services/database/repositories/builders";
import { createSubmission, getAllSubmissions } from "~~/services/database/repositories/submissions";
import { SubmissionInsert } from "~~/services/database/repositories/submissions";
import { EIP_712_DOMAIN, EIP_712_TYPES__SUBMISSION } from "~~/utils/eip712";

export async function GET() {
Expand All @@ -14,17 +15,11 @@ export async function GET() {
}
}

type ReqBody = {
title?: string;
description?: string;
linkToRepository?: string;
signature?: `0x${string}`;
signer?: string;
};
export type CreateNewSubmissionBody = SubmissionInsert & { signature: `0x${string}`; signer: string };

export async function POST(req: Request) {
try {
const { title, description, linkToRepository, signature, signer } = (await req.json()) as ReqBody;
const { title, description, linkToRepository, signature, signer } = (await req.json()) as CreateNewSubmissionBody;

if (
!title ||
Expand Down
13 changes: 3 additions & 10 deletions packages/nextjs/app/submit/_component/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@ import { useRouter } from "next/navigation";
import SubmitButton from "./SubmitButton";
import { useMutation } from "@tanstack/react-query";
import { useAccount, useSignTypedData } from "wagmi";
import { CreateNewSubmissionBody } from "~~/app/api/submissions/route";
import { EIP_712_DOMAIN, EIP_712_TYPES__SUBMISSION } from "~~/utils/eip712";
import { postMutationFetcher } from "~~/utils/react-query";
import { notification } from "~~/utils/scaffold-eth";

// TODO: move to a shared location
type ReqBody = {
title?: string;
description?: string;
linkToRepository?: string;
signature?: `0x${string}`;
signer?: string;
};

const MAX_DESCRIPTION_LENGTH = 750;

const Form = () => {
Expand All @@ -26,7 +18,8 @@ const Form = () => {
const { signTypedDataAsync } = useSignTypedData();
const router = useRouter();
const { mutateAsync: postNewSubmission } = useMutation({
mutationFn: (newSubmission: ReqBody) => postMutationFetcher("/api/submissions", { body: newSubmission }),
mutationFn: (newSubmission: CreateNewSubmissionBody) =>
postMutationFetcher("/api/submissions", { body: newSubmission }),
});

const clientFormAction = async (formData: FormData) => {
Expand Down

0 comments on commit a777476

Please sign in to comment.