diff --git a/app/routes/admin-application.tsx b/app/routes/admin-application.tsx index 2acea87..3808dab 100644 --- a/app/routes/admin-application.tsx +++ b/app/routes/admin-application.tsx @@ -7,6 +7,9 @@ import { Textarea, useToast, } from "@chakra-ui/react"; +import { useState } from "react"; +import Success from "../../components/Success.js"; +import { useLoaderData } from "@remix-run/react"; export function meta() { return [ @@ -16,80 +19,131 @@ export function meta() { ]; } +export async function loader({ context }: { context: RequestContext }) { + const user: { [k: string]: any } = context.data.current_user; + + if (!user) + throw new Response(null, { + status: 401, + }); + + return null; +} + export default function () { + const [loading, setLoading] = useState(false); + const [success, setSuccess] = useState(false); + const toast = useToast(); + useLoaderData(); + async function submit() { + setLoading(true); + const submitReq = await fetch("/api/admin-apps/submit"); + if (!submitReq.ok) { + toast({ + title: "Error", + description: + "Something went wrong while submitting your application. Try again.", + status: "error", + }); - useToast()({ - description: submitReq.ok - ? "Your application was submitted" - : "Try again later", - duration: 10000, - isClosable: true, - status: submitReq.ok ? "success" : "error", - title: submitReq.ok ? "Success" : "Unknown Error", - }); + return; + } + + setLoading(false); + setSuccess(true); } return ( - - Admin Application -
-
- Why do you want to be an admin? -
-