Create new "admin application"
This commit is contained in:
parent
a3eca56fec
commit
f37b68015a
87
app/routes/admin-application.tsx
Normal file
87
app/routes/admin-application.tsx
Normal file
@ -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
functions/api/admin-apps/submit.ts
Normal file
34
functions/api/admin-apps/submit.ts
Normal file
@ -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,
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user