Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create new "admin application"
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent a3eca56 commit f37b680
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
87 changes: 87 additions & 0 deletions app/routes/admin-application.tsx
@@ -0,0 +1,87 @@
import {
Button,
Container,
Heading,
Input,
Text,
Textarea,
useToast,
} from "@chakra-ui/react";

export default function () {
async function submit() {
const submitReq = await fetch("/api/admin-apps/submit");

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 (
<Container maxW="container.md" pt="4vh" textAlign="start">
<Heading size="xl">Admin Application</Heading>
<br />
<br />
<Text fontSize="md">Why do you want to be an admin?</Text>
<br />
<Textarea
maxLength={2000}
placeholder="Explain why you want to be an admin. This should be at least a few sentences."
/>
<br />
<br />
<br />
<Text fontSize="md">
How long have you been in the Car Crushers community?
</Text>
<br />
<Input maxLength={40} placeholder="Your response" />
<br />
<br />
<br />
<Text fontSize="md">
Explain why you are a better candidate than someone else.
</Text>
<br />
<Textarea
maxLength={2000}
placeholder="Explain why you are a better candidate. This should be at least a few sentences."
/>
<br />
<br />
<br />
<Text fontSize="md">
Describe yourself from a third-person point-of-view.
</Text>
<br />
<Textarea
maxLength={1000}
placeholder="Describe yourself from a third-person view in a few sentences."
/>
<br />
<br />
<br />
<Text fontSize="md">
If you have any comments or questions, type them here.
</Text>
<br />
<Textarea maxLength={1000} placeholder="Comments and questions go here" />
<br />
<br />
<br />
<span>
By submitting this form, you agree to the{" "}
<a href="/terms">Terms of Service</a> and{" "}
<a href="/privacy">Privacy Policy</a>.
</span>
<br />
<Button onClick={async () => await submit()}>Submit</Button>
</Container>
);
}
34 changes: 34 additions & 0 deletions functions/api/admin-apps/submit.ts
@@ -0,0 +1,34 @@
export async function onRequest(context: RequestContext) {
const { current_user: currentUser } = context.data;

if (!currentUser.email)
return new Response(null, {
status: 204,
});

const deliveryDate = new Date(
Date.now() + 86400000 + Math.round(Math.random() * 172800000)
)
.toUTCString()
.replace("GMT", "+0000");

const emailData = new FormData();
emailData.append("from", "totallyrealadminapplication@mail.carcrushers.cc");
emailData.append("to", currentUser.email);
emailData.append("subject", "Your admin application has been approved");
emailData.append("o:deliverytime", deliveryDate);
emailData.append("v:username", currentUser.username);
emailData.append("template", "admin_application");

await fetch("https://api.mailgun.net/v3/mail.carcrushers.cc/messages", {
body: emailData,
headers: {
authorization: `Basic ${btoa(`api:${context.env.MAILGUN_API_KEY}`)}`,
},
method: "POST",
});

return new Response(null, {
status: 204,
});
}

0 comments on commit f37b680

Please sign in to comment.