Generally fix up inactivity notices
This commit is contained in:
@ -26,23 +26,22 @@ export default function (props: {
|
|||||||
}) {
|
}) {
|
||||||
const [departments, setDepartments] = useState([] as string[]);
|
const [departments, setDepartments] = useState([] as string[]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [start, setStart] = useState("");
|
||||||
|
const [end, setEnd] = useState("");
|
||||||
|
const [reason, setReason] = useState("");
|
||||||
const [isHiatus, setIsHiatus] = useState(false);
|
const [isHiatus, setIsHiatus] = useState(false);
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
(document.getElementById("start") as HTMLInputElement).value = "";
|
setEnd("");
|
||||||
(document.getElementById("end") as HTMLInputElement).value = "";
|
setReason("");
|
||||||
(document.getElementById("reason") as HTMLTextAreaElement).value = "";
|
setStart("");
|
||||||
|
|
||||||
props.onClose();
|
props.onClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const start = (document.getElementById("start") as HTMLInputElement).value;
|
|
||||||
const end = (document.getElementById("end") as HTMLInputElement).value;
|
|
||||||
const reason = (document.getElementById("reason") as HTMLTextAreaElement)
|
|
||||||
.value;
|
|
||||||
|
|
||||||
if (!departments.length) {
|
if (!departments.length) {
|
||||||
toast({
|
toast({
|
||||||
@ -55,6 +54,17 @@ export default function (props: {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!start || !end || !reason) {
|
||||||
|
toast({
|
||||||
|
description: "One or more fields are missing",
|
||||||
|
status: "error",
|
||||||
|
title: "Validation Error",
|
||||||
|
});
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const inactivityPost = await fetch("/api/inactivity/new", {
|
const inactivityPost = await fetch("/api/inactivity/new", {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
departments,
|
departments,
|
||||||
@ -90,7 +100,7 @@ export default function (props: {
|
|||||||
title: "Success",
|
title: "Success",
|
||||||
});
|
});
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(false);
|
||||||
props.onClose();
|
props.onClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,16 +113,26 @@ export default function (props: {
|
|||||||
<ModalCloseButton />
|
<ModalCloseButton />
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<Text>Start Date</Text>
|
<Text>Start Date</Text>
|
||||||
<input id="start" type="date" />
|
<input
|
||||||
|
id="start"
|
||||||
|
onChange={(e) => setStart(e.target.value)}
|
||||||
|
type="date"
|
||||||
|
/>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<Text>End Date</Text>
|
<Text>End Date</Text>
|
||||||
<input id="end" type="date" />
|
<input
|
||||||
|
id="end"
|
||||||
|
onChange={(e) => setEnd(e.target.value)}
|
||||||
|
type="date"
|
||||||
|
/>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<Text>Reason</Text>
|
<Text>Reason</Text>
|
||||||
<Textarea
|
<Textarea
|
||||||
id="reason"
|
id="reason"
|
||||||
|
maxLength={500}
|
||||||
|
onChange={(e) => setReason(e.target.value)}
|
||||||
placeholder="Your reason for making this inactivity notice"
|
placeholder="Your reason for making this inactivity notice"
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
@ -127,20 +147,21 @@ export default function (props: {
|
|||||||
))}
|
))}
|
||||||
</VStack>
|
</VStack>
|
||||||
</CheckboxGroup>
|
</CheckboxGroup>
|
||||||
<RadioGroup
|
{departments.includes("DM") ? (
|
||||||
onChange={(v) => setIsHiatus(JSON.parse(v))}
|
<>
|
||||||
style={{
|
<br />
|
||||||
display: departments.includes("DM") ? undefined : "none",
|
<br />
|
||||||
}}
|
<RadioGroup
|
||||||
value={JSON.stringify(isHiatus)}
|
onChange={(v) => setIsHiatus(JSON.parse(v))}
|
||||||
>
|
value={JSON.stringify(isHiatus)}
|
||||||
<br />
|
>
|
||||||
<br />
|
<HStack>
|
||||||
<HStack>
|
<Radio value="false">Inactivity</Radio>
|
||||||
<Radio value="false">Inactivity</Radio>
|
<Radio value="true">Hiatus</Radio>
|
||||||
<Radio value="true">Hiatus</Radio>
|
</HStack>
|
||||||
</HStack>
|
</RadioGroup>
|
||||||
</RadioGroup>
|
</>
|
||||||
|
) : null}
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button onClick={reset}>Cancel</Button>
|
<Button onClick={reset}>Cancel</Button>
|
||||||
|
@ -67,7 +67,7 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
if (Object.values(decisions).length === requestedNotice.departments.length) {
|
if (Object.values(decisions).length === requestedNotice.departments.length) {
|
||||||
requestedNotice.open = false;
|
requestedNotice.open = false;
|
||||||
|
|
||||||
const approved = !Object.values(decisions).find((d) => !d);
|
const approved = !Object.values(decisions).filter((d) => !d).length;
|
||||||
|
|
||||||
await context.env.D1.prepare(
|
await context.env.D1.prepare(
|
||||||
"UPDATE inactivity_notices SET approved = ?, open = 0 WHERE id = ?;",
|
"UPDATE inactivity_notices SET approved = ?, open = 0 WHERE id = ?;",
|
||||||
@ -81,7 +81,7 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
`Inactivity Request ${approved ? "Approved" : "Denied"}`,
|
`Inactivity Request ${approved ? "Approved" : "Denied"}`,
|
||||||
accepted
|
accepted
|
||||||
? "Your inactivity request was approved."
|
? "Your inactivity request was approved."
|
||||||
: "Your inactivity request was denied, please reach to management if you require more details.",
|
: "Your inactivity request was denied, please reach out to management if you require more details.",
|
||||||
requestedNotice.fcm_token,
|
requestedNotice.fcm_token,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user