diff --git a/integrations/evaluations/app/actions/manage/actions.ts b/integrations/evaluations/app/actions/manage/actions.ts index 08dfdf8379..2d021ffd7b 100644 --- a/integrations/evaluations/app/actions/manage/actions.ts +++ b/integrations/evaluations/app/actions/manage/actions.ts @@ -6,8 +6,9 @@ import { findInstance } from "~/lib/instance"; import { makePubFromDoi, makePubFromTitle, makePubFromUrl } from "~/lib/metadata"; import { client } from "~/lib/pubpub"; -export const manage = async (instanceId: string) => { +export const manage = async (instanceId: string, pubId: string, email: Create) => { try { + console.log(`Instance: ${instanceId}, pubId: ${pubId}, email: ${email}`); return {}; } catch (error) { return { error: error.message }; diff --git a/integrations/evaluations/app/actions/manage/emailForm.tsx b/integrations/evaluations/app/actions/manage/emailForm.tsx new file mode 100644 index 0000000000..c79bdae60c --- /dev/null +++ b/integrations/evaluations/app/actions/manage/emailForm.tsx @@ -0,0 +1,130 @@ +"use client"; + +import { zodResolver } from "@hookform/resolvers/zod"; +import { useEffect } from "react"; +import { useForm } from "react-hook-form"; +import { + Button, + Card, + CardContent, + CardDescription, + CardFooter, + CardHeader, + CardTitle, + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, + Icon, + Input, + Textarea, + useLocalStorage, + useToast, +} from "ui"; +import { cn } from "utils"; +import * as z from "zod"; +import { manage } from "./actions"; + +type Props = { + instanceId: string; + pubId: string; +}; + +// TODO: generate fields using instance's configured PubType +const schema = z.object({ + Email: z.string().email("Enter a valid email address"), +}); + +export function EmailForm(props: Props) { + const { pubId } = props; + const { toast } = useToast(); + const form = useForm>({ + mode: "onChange", + reValidateMode: "onChange", + // TODO: generate fields using instance's configured PubType + resolver: zodResolver(schema), + defaultValues: { + Email: "", + }, + }); + const [persistedValues, persist] = useLocalStorage>(props.instanceId); + + const onSubmit = async (email: z.infer) => { + const result = await manage(props.instanceId, props.pubId, email); + if ("error" in result && typeof result.error === "string") { + toast({ + title: "Error", + description: result.error, + variant: "destructive", + }); + } else { + toast({ + title: "Success", + description: "The email was sent successfully", + }); + form.reset(); + } + }; + + // Load the persisted values. + const { reset } = form; + useEffect(() => { + // `keepDefaultValues` is set to true to prevent the form from + // validating fields that were not filled during the previous session. + reset(persistedValues, { keepDefaultValues: true }); + }, [reset]); + + // Persist form values to local storage. This operation is debounced by + // the timeout passed to . + const values = form.watch(); + useEffect(() => { + persist(values); + }, [values]); + + return ( +
+ + + + ( + + Email Address + + + + + The email of the evaluator you'd like to invite. + + + + )} + /> + + + + + + +
+ + ); +} diff --git a/integrations/evaluations/app/actions/manage/page.tsx b/integrations/evaluations/app/actions/manage/page.tsx index 04afb22792..86c7812e0d 100644 --- a/integrations/evaluations/app/actions/manage/page.tsx +++ b/integrations/evaluations/app/actions/manage/page.tsx @@ -1,10 +1,18 @@ +import { EmailForm } from "./emailForm"; + type Props = { searchParams: { instanceId: string; + pubId: any; }; }; export default async function Page(props: Props) { - const { instanceId } = props.searchParams; - return

Evaluation Integration

; + const { instanceId, pubId } = props.searchParams; + return ( + <> +

Evaluation Integration

+ + + ); }