Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Create new "admin application"
- Loading branch information
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
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,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> | ||
); | ||
} |
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,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, | ||
}); | ||
} |