Add game night certification to events team page
This commit is contained in:
parent
a64e94981f
commit
4ea4053235
@ -8,14 +8,22 @@ import {
|
|||||||
Flex,
|
Flex,
|
||||||
Heading,
|
Heading,
|
||||||
Link,
|
Link,
|
||||||
|
Modal,
|
||||||
|
ModalBody,
|
||||||
|
ModalCloseButton,
|
||||||
|
ModalContent,
|
||||||
|
ModalFooter,
|
||||||
|
ModalHeader,
|
||||||
|
ModalOverlay,
|
||||||
Stack,
|
Stack,
|
||||||
StackDivider,
|
StackDivider,
|
||||||
Text,
|
Text,
|
||||||
|
useDisclosure,
|
||||||
useToast,
|
useToast,
|
||||||
VStack,
|
VStack,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import { useLoaderData } from "@remix-run/react";
|
import { useLoaderData } from "@remix-run/react";
|
||||||
import { type ReactNode } from "react";
|
import { type ReactNode, useState } from "react";
|
||||||
|
|
||||||
export async function loader({ context }: { context: RequestContext }) {
|
export async function loader({ context }: { context: RequestContext }) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
@ -47,7 +55,9 @@ export default function () {
|
|||||||
events: { [k: string]: any }[];
|
events: { [k: string]: any }[];
|
||||||
} = useLoaderData<typeof loader>();
|
} = useLoaderData<typeof loader>();
|
||||||
const eventCards: ReactNode[] = [];
|
const eventCards: ReactNode[] = [];
|
||||||
|
const { isOpen, onClose, onOpen } = useDisclosure();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
const [selectedEvent, setSelectedEvent] = useState("");
|
||||||
|
|
||||||
async function decide(approved: boolean, eventId: string) {
|
async function decide(approved: boolean, eventId: string) {
|
||||||
const decisionResp = await fetch(
|
const decisionResp = await fetch(
|
||||||
@ -83,6 +93,40 @@ export default function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function certify(eventId: string) {
|
||||||
|
const certifyResp = await fetch(
|
||||||
|
`/api/events-team/events/${eventId}/certify`,
|
||||||
|
{
|
||||||
|
body: "{}",
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!certifyResp.ok) {
|
||||||
|
let errorMsg = "Unknown error";
|
||||||
|
|
||||||
|
try {
|
||||||
|
errorMsg = ((await certifyResp.json()) as { error: string }).error;
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
description: errorMsg,
|
||||||
|
status: "error",
|
||||||
|
title: "Failed to certify game night",
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
description: "Game night certified",
|
||||||
|
title: "Success",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
eventCards.push(
|
eventCards.push(
|
||||||
<Card w="100%">
|
<Card w="100%">
|
||||||
@ -126,6 +170,22 @@ export default function () {
|
|||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
|
{can_approve &&
|
||||||
|
event.approved &&
|
||||||
|
event.type === "gamenight" &&
|
||||||
|
!event.reached_minimum_player_count ? (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
colorScheme="blue"
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedEvent(event.id);
|
||||||
|
onOpen();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Certify Game Night
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
</Flex>
|
</Flex>
|
||||||
<Text alignSelf="center" fontSize="sm">
|
<Text alignSelf="center" fontSize="sm">
|
||||||
Status:{" "}
|
Status:{" "}
|
||||||
@ -138,6 +198,31 @@ export default function () {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Container maxW="container.lg">
|
<Container maxW="container.lg">
|
||||||
|
<Modal isOpen={isOpen} onClose={onClose}>
|
||||||
|
<ModalOverlay />
|
||||||
|
<ModalContent>
|
||||||
|
<ModalHeader>Certify Game Night</ModalHeader>
|
||||||
|
<ModalCloseButton />
|
||||||
|
<ModalBody>
|
||||||
|
<Text>
|
||||||
|
By certifying this game night, you confirm that the minimum number
|
||||||
|
of players was met and you were provided proof.
|
||||||
|
</Text>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button colorScheme="red" onClick={onClose}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
colorScheme="blue"
|
||||||
|
mr="8px"
|
||||||
|
onClick={async () => await certify(selectedEvent)}
|
||||||
|
>
|
||||||
|
Certify
|
||||||
|
</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
<VStack spacing="8">{eventCards}</VStack>
|
<VStack spacing="8">{eventCards}</VStack>
|
||||||
<Link color="#646cff" href="/book-event" mt="16px">
|
<Link color="#646cff" href="/book-event" mt="16px">
|
||||||
Book an Event
|
Book an Event
|
||||||
|
Loading…
x
Reference in New Issue
Block a user