Add mark forgotten button
This commit is contained in:
parent
2b7c08dbd0
commit
d4cc357cc0
@ -23,7 +23,7 @@ import {
|
||||
Text,
|
||||
useDisclosure,
|
||||
useToast,
|
||||
VStack
|
||||
VStack,
|
||||
} from "@chakra-ui/react";
|
||||
import { useLoaderData } from "@remix-run/react";
|
||||
import { useState } from "react";
|
||||
@ -34,62 +34,62 @@ import { type LinksFunction } from "@remix-run/cloudflare";
|
||||
export const links: LinksFunction = () => {
|
||||
return [
|
||||
{ href: stylesheet, rel: "stylesheet" },
|
||||
{ href: calendarStyles, rel: "stylesheet" }
|
||||
{ href: calendarStyles, rel: "stylesheet" },
|
||||
];
|
||||
};
|
||||
|
||||
export async function loader({ context }: { context: RequestContext }) {
|
||||
if (!context.data.current_user)
|
||||
throw new Response(null, {
|
||||
status: 401
|
||||
status: 401,
|
||||
});
|
||||
|
||||
if (
|
||||
![1 << 3, 1 << 4, 1 << 12].find(
|
||||
(p) => context.data.current_user.permissions & p
|
||||
(p) => context.data.current_user.permissions & p,
|
||||
)
|
||||
)
|
||||
throw new Response(null, {
|
||||
status: 403
|
||||
status: 403,
|
||||
});
|
||||
|
||||
const now = new Date();
|
||||
const monthEventList = await context.env.D1.prepare(
|
||||
"SELECT answer, approved, created_by, day, details, id, month, pending, performed_at, reached_minimum_player_count, type, year FROM events WHERE month = ? AND year = ? ORDER BY day ASC;"
|
||||
"SELECT answer, approved, created_by, day, details, id, month, pending, performed_at, reached_minimum_player_count, type, year FROM events WHERE month = ? AND year = ? ORDER BY day ASC;",
|
||||
)
|
||||
.bind(now.getUTCMonth() + 1, now.getUTCFullYear())
|
||||
.all();
|
||||
|
||||
if (monthEventList.error)
|
||||
throw new Response(null, {
|
||||
status: 500
|
||||
status: 500,
|
||||
});
|
||||
|
||||
const membersList = await context.env.D1.prepare(
|
||||
"SELECT id, name FROM et_members WHERE id IN (SELECT created_by FROM events WHERE month = ? AND year = ?);"
|
||||
"SELECT id, name FROM et_members WHERE id IN (SELECT created_by FROM events WHERE month = ? AND year = ?);",
|
||||
)
|
||||
.bind(now.getUTCMonth() + 1, now.getUTCFullYear())
|
||||
.all();
|
||||
|
||||
if (membersList.error)
|
||||
throw new Response(null, {
|
||||
status: 500
|
||||
status: 500,
|
||||
});
|
||||
|
||||
return {
|
||||
can_approve: Boolean(
|
||||
[1 << 4, 1 << 12].find((p) => context.data.current_user.permissions & p)
|
||||
[1 << 4, 1 << 12].find((p) => context.data.current_user.permissions & p),
|
||||
),
|
||||
events: monthEventList.results,
|
||||
members: membersList.results as { id: string; name: string }[]
|
||||
members: membersList.results as { id: string; name: string }[],
|
||||
};
|
||||
}
|
||||
|
||||
export default function() {
|
||||
export default function () {
|
||||
const {
|
||||
can_approve,
|
||||
events,
|
||||
members
|
||||
members,
|
||||
}: {
|
||||
can_approve: boolean;
|
||||
events: { [k: string]: any }[];
|
||||
@ -100,17 +100,17 @@ export default function() {
|
||||
const {
|
||||
isOpen: isCompleteOpen,
|
||||
onClose: closeComplete,
|
||||
onOpen: openComplete
|
||||
onOpen: openComplete,
|
||||
} = useDisclosure();
|
||||
const {
|
||||
isOpen: isAnsweredOpen,
|
||||
onClose: closeAnswered,
|
||||
onOpen: openAnswered
|
||||
onOpen: openAnswered,
|
||||
} = useDisclosure();
|
||||
const {
|
||||
isOpen: isForgottenOpen,
|
||||
onClose: onForgottenClose,
|
||||
onOpen: onForgottenOpen
|
||||
onOpen: onForgottenOpen,
|
||||
} = useDisclosure();
|
||||
const toast = useToast();
|
||||
const [selectedEvent, setSelectedEvent] = useState("");
|
||||
@ -122,10 +122,10 @@ export default function() {
|
||||
{
|
||||
body: JSON.stringify({ approved }),
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
"content-type": "application/json",
|
||||
},
|
||||
method: "POST"
|
||||
}
|
||||
method: "POST",
|
||||
},
|
||||
);
|
||||
|
||||
if (!decisionResp.ok) {
|
||||
@ -133,13 +133,12 @@ export default function() {
|
||||
|
||||
try {
|
||||
errorMsg = ((await decisionResp.json()) as { error: string }).error;
|
||||
} catch {
|
||||
}
|
||||
} catch {}
|
||||
|
||||
toast({
|
||||
description: errorMsg,
|
||||
status: "error",
|
||||
title: "Oops!"
|
||||
title: "Oops!",
|
||||
});
|
||||
|
||||
return;
|
||||
@ -148,7 +147,7 @@ export default function() {
|
||||
toast({
|
||||
description: `Event ${approved ? "approved" : "rejected"}`,
|
||||
status: "success",
|
||||
title: "Success"
|
||||
title: "Success",
|
||||
});
|
||||
|
||||
const newEventData = eventData;
|
||||
@ -166,10 +165,10 @@ export default function() {
|
||||
{
|
||||
body: "{}",
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
"content-type": "application/json",
|
||||
},
|
||||
method: "POST"
|
||||
}
|
||||
method: "POST",
|
||||
},
|
||||
);
|
||||
|
||||
if (!certifyResp.ok) {
|
||||
@ -177,13 +176,12 @@ export default function() {
|
||||
|
||||
try {
|
||||
errorMsg = ((await certifyResp.json()) as { error: string }).error;
|
||||
} catch {
|
||||
}
|
||||
} catch {}
|
||||
|
||||
toast({
|
||||
description: errorMsg,
|
||||
status: "error",
|
||||
title: "Failed to certify game night"
|
||||
title: "Failed to certify game night",
|
||||
});
|
||||
|
||||
return;
|
||||
@ -192,13 +190,13 @@ export default function() {
|
||||
toast({
|
||||
description: "Game night certified",
|
||||
status: "success",
|
||||
title: "Success"
|
||||
title: "Success",
|
||||
});
|
||||
|
||||
const newEventData = eventData;
|
||||
newEventData[
|
||||
eventData.findIndex((e) => e.id === eventId)
|
||||
].reached_minimum_player_count = true;
|
||||
].reached_minimum_player_count = true;
|
||||
|
||||
setEventData([...newEventData]);
|
||||
setSelectedEvent("");
|
||||
@ -208,9 +206,9 @@ export default function() {
|
||||
const answerResp = await fetch(`/api/events-team/events/${eventId}/solve`, {
|
||||
body: "{}",
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
"content-type": "application/json",
|
||||
},
|
||||
method: "POST"
|
||||
method: "POST",
|
||||
});
|
||||
|
||||
closeAnswered();
|
||||
@ -219,7 +217,7 @@ export default function() {
|
||||
toast({
|
||||
description: "Failed to mark as solved",
|
||||
status: "error",
|
||||
title: "Oops"
|
||||
title: "Oops",
|
||||
});
|
||||
|
||||
return;
|
||||
@ -239,10 +237,10 @@ export default function() {
|
||||
{
|
||||
body: "{}",
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
"content-type": "application/json",
|
||||
},
|
||||
method: "POST"
|
||||
}
|
||||
method: "POST",
|
||||
},
|
||||
);
|
||||
|
||||
closeComplete();
|
||||
@ -252,13 +250,12 @@ export default function() {
|
||||
|
||||
try {
|
||||
msg = ((await completeResp.json()) as { error: string }).error;
|
||||
} catch {
|
||||
}
|
||||
} catch {}
|
||||
|
||||
toast({
|
||||
description: msg,
|
||||
status: "error",
|
||||
title: "Failed to complete"
|
||||
title: "Failed to complete",
|
||||
});
|
||||
|
||||
return;
|
||||
@ -267,7 +264,7 @@ export default function() {
|
||||
toast({
|
||||
description: "Event marked as completed",
|
||||
status: "success",
|
||||
title: "Success"
|
||||
title: "Success",
|
||||
});
|
||||
|
||||
const newEventData = eventData;
|
||||
@ -286,10 +283,10 @@ export default function() {
|
||||
{
|
||||
body: "{}",
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
"content-type": "application/json",
|
||||
},
|
||||
method: "POST"
|
||||
}
|
||||
method: "POST",
|
||||
},
|
||||
);
|
||||
|
||||
onForgottenClose();
|
||||
@ -299,13 +296,12 @@ export default function() {
|
||||
|
||||
try {
|
||||
msg = ((await forgottenResp.json()) as { error: string }).error;
|
||||
} catch {
|
||||
}
|
||||
} catch {}
|
||||
|
||||
toast({
|
||||
description: msg,
|
||||
status: "error",
|
||||
title: "Failed to forget"
|
||||
title: "Failed to forget",
|
||||
});
|
||||
|
||||
return;
|
||||
@ -396,11 +392,19 @@ export default function() {
|
||||
<ModalContent>
|
||||
<ModalHeader>Mark as Forgotten</ModalHeader>
|
||||
<ModalCloseButton />
|
||||
<ModalBody>Are you sure you want to mark this event as forgotten? The creator will be given a 5 point
|
||||
penalty.</ModalBody>
|
||||
<ModalBody>
|
||||
Are you sure you want to mark this event as forgotten? The creator
|
||||
will be given a 5 point penalty.
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button onClick={onForgottenClose}>Cancel</Button>
|
||||
<Button colorScheme="blue" ml="8px" onClick={async () => await markForgotten(selectedEvent)}
|
||||
<Button
|
||||
colorScheme="blue"
|
||||
ml="8px"
|
||||
onClick={async () => await markForgotten(selectedEvent)}
|
||||
>
|
||||
Mark Forgotten
|
||||
</Button>
|
||||
</ModalFooter>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
@ -410,14 +414,14 @@ export default function() {
|
||||
if (!showOld && event.day < new Date().getUTCDate()) return;
|
||||
|
||||
const eventCreatorName = members.find(
|
||||
(member) => member.id === event.created_by
|
||||
(member) => member.id === event.created_by,
|
||||
)?.name;
|
||||
|
||||
const eventColors: { [k: string]: string } = {
|
||||
fotd: "cyan",
|
||||
gamenight: "blue",
|
||||
rotw: "magenta",
|
||||
qotd: "#9900FF"
|
||||
qotd: "#9900FF",
|
||||
};
|
||||
|
||||
return (
|
||||
@ -491,7 +495,15 @@ export default function() {
|
||||
>
|
||||
Mark as Completed
|
||||
</Button>
|
||||
<Button colorScheme="red">Mark as Forgotten</Button>
|
||||
<Button
|
||||
colorScheme="red"
|
||||
onClick={() => {
|
||||
setSelectedEvent(event.id);
|
||||
onForgottenOpen();
|
||||
}}
|
||||
>
|
||||
Mark as Forgotten
|
||||
</Button>
|
||||
</>
|
||||
) : null}
|
||||
{can_approve &&
|
||||
@ -576,6 +588,7 @@ export default function() {
|
||||
</Link>
|
||||
) : null}
|
||||
</VStack>
|
||||
;
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user