forked from LAION-AI/Open-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add paper acknowledgement form (LAION-AI#3637)
I know all of this is suboptimal, but I'd like to get people to sign up to be mentioned asap. Feel free to improve (or to tell me how to improve) now or in subsequent PRs. I anticipate this form will be going away in the future, so I'm not sure a lot of work will be really worth it. --------- Co-authored-by: AbdBarho <ka70911@gmail.com>
- Loading branch information
Showing
6 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
website/prisma/migrations/20230805220637_paperack/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- AlterTable | ||
ALTER TABLE "User" ADD COLUMN "paperackName" TEXT NOT NULL DEFAULT '', | ||
ADD COLUMN "paperackYes" BOOLEAN NOT NULL DEFAULT false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { Button, FormControl, FormLabel, Input, InputGroup, useToast } from "@chakra-ui/react"; | ||
import Head from "next/head"; | ||
import React, { useEffect, useMemo } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
export { getStaticProps } from "src/lib/defaultServerSideProps"; | ||
import { get, post } from "src/lib/api"; | ||
import useSWRImmutable from "swr/immutable"; | ||
import useSWRMutation from "swr/mutation"; | ||
|
||
interface AckData { | ||
paperackYes: boolean; | ||
paperackName: string; | ||
} | ||
|
||
export default function PaperAck() { | ||
const toast = useToast(); | ||
|
||
const { data: defaultValues } = useSWRImmutable<AckData>("/api/paperack", get); | ||
const { trigger } = useSWRMutation<AckData, any, any, AckData>("/api/paperack", post, { | ||
onSuccess() { | ||
toast({ | ||
title: "Successfully updated your preferences", | ||
status: "success", | ||
}); | ||
}, | ||
onError(err) { | ||
console.error(err); | ||
toast({ | ||
title: "An error occurred!", | ||
status: "error", | ||
}); | ||
}, | ||
}); | ||
|
||
const { | ||
register, | ||
formState: { errors }, | ||
handleSubmit, | ||
reset, | ||
watch, | ||
} = useForm<AckData>({ defaultValues }); | ||
|
||
useEffect(() => { | ||
reset(defaultValues); | ||
}, [defaultValues, reset]); | ||
|
||
const updatePaperAck = useMemo(() => handleSubmit((data: AckData) => trigger(data)), [handleSubmit, trigger]); | ||
|
||
const { paperackYes, paperackName } = watch(); | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>Open Assistant</title> | ||
</Head> | ||
<main className="oa-basic-theme h-3/4 z-0 flex flex-col items-center justify-center"> | ||
<div className="max-w-3xl"> | ||
<div className="m-4"> | ||
<p className="mb-8"> | ||
If you want to be considered for acknowledgements in the paper for your contributions, tick the box below | ||
AND enter your (real) name. | ||
</p> | ||
<form onSubmit={updatePaperAck}> | ||
<InputGroup className="flex flex-col gap-6"> | ||
<FormControl className="flex flex-row gap-2"> | ||
<input | ||
id="paperackYes" | ||
type="checkbox" | ||
name="paperackYes" | ||
{...register("paperackYes")} | ||
className="mb-2" | ||
/> | ||
<FormLabel htmlFor="paperackYes">I want to be mentioned in the acknowledgements</FormLabel> | ||
</FormControl> | ||
<FormControl isInvalid={errors.paperackName ? true : false}> | ||
<FormLabel>Write the name by which you want to be mentioned in the acknowledgements</FormLabel> | ||
<Input placeholder="Name" type="text" {...register("paperackName")}></Input> | ||
</FormControl> | ||
<Button isDisabled={paperackYes && !paperackName} type="submit"> | ||
Submit | ||
</Button> | ||
</InputGroup> | ||
</form> | ||
</div> | ||
</div> | ||
</main> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { withoutRole } from "src/lib/auth"; | ||
import prisma from "src/lib/prismadb"; | ||
|
||
/** | ||
* Updates the user's paper ack info | ||
*/ | ||
const handler = withoutRole("banned", async (req, res, token) => { | ||
// handle GET | ||
if (req.method === "GET") { | ||
const user = await prisma.user.findUnique({ | ||
where: { | ||
id: token.sub, | ||
}, | ||
select: { | ||
paperackYes: true, | ||
paperackName: true, | ||
}, | ||
}); | ||
return res.status(200).json(user); | ||
} | ||
|
||
const { paperackYes, paperackName } = req.body; | ||
|
||
const user = await prisma.user.update({ | ||
where: { | ||
id: token.sub, | ||
}, | ||
data: { | ||
paperackYes, | ||
paperackName, | ||
}, | ||
select: { | ||
paperackYes: true, | ||
paperackName: true, | ||
}, | ||
}); | ||
return res.status(200).json(user); | ||
}); | ||
|
||
export default handler; |