neat
This commit is contained in:
parent
690adf5a86
commit
98ac17d478
@ -1,8 +1,9 @@
|
||||
import { Button, ButtonOwnProps } from "@mui/material";
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
type Actions = "Completed" | "Submit" | "Reject" | "Revoke"
|
||||
type ApiActions = Lowercase<Actions> | "trigger-validate" | "retry-validate" | "trigger-upload" | "reset-uploading" | "reset-validating"
|
||||
type Review = Actions | "Accept" | "Validate" | "Upload" | "Reset Uploading (fix softlocked status)" | "Reset Validating (fix softlocked status)" | "Request Changes"
|
||||
type ApiActions = Lowercase<Actions> | "request-changes" | "trigger-validate" | "retry-validate" | "trigger-upload" | "reset-uploading" | "reset-validating"
|
||||
type Review = Actions | "Request Changes" | "Accept" | "Validate" | "Upload" | "Reset Uploading (fix softlocked status)" | "Reset Validating (fix softlocked status)" | "Request Changes"
|
||||
|
||||
interface ReviewButton {
|
||||
name: Review,
|
||||
@ -58,78 +59,79 @@ export default function ReviewButtons(props: ReviewId) {
|
||||
// RequestChanges | Reviewer | Validated, Accepted, Submitted
|
||||
// Upload | MapAdmin | Validated
|
||||
// ResetUploading | MapAdmin | Uploading
|
||||
const { submissionId } = props;
|
||||
const [roles, setRoles] = useState<string[]>([]);
|
||||
const [status, setStatus] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const { submissionId } = props;
|
||||
const [roles, setRoles] = useState<string[]>([]);
|
||||
const [status, setStatus] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
try {
|
||||
// Fetch user roles
|
||||
const rolesResponse = await fetch("/api/session/roles");
|
||||
const rolesData = await rolesResponse.json();
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
try {
|
||||
// Fetch user roles
|
||||
const rolesResponse = await fetch("/api/session/roles");
|
||||
const rolesData = await rolesResponse.json();
|
||||
|
||||
// Fetch submission status
|
||||
const statusResponse = await fetch(
|
||||
`/api/submissions/${submissionId}/status`
|
||||
);
|
||||
const statusData = await statusResponse.json();
|
||||
// Fetch submission status
|
||||
const statusResponse = await fetch(
|
||||
`/api/submissions/${submissionId}/status`
|
||||
);
|
||||
const statusData = await statusResponse.json();
|
||||
|
||||
setRoles(rolesData);
|
||||
setStatus(statusData.status);
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
setRoles(rolesData);
|
||||
setStatus(statusData.status);
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
fetchData();
|
||||
}, [submissionId]);
|
||||
fetchData();
|
||||
}, [submissionId]);
|
||||
|
||||
if (loading) return <p>Loading...</p>;
|
||||
if (loading) return <p>Loading...</p>;
|
||||
|
||||
const visibleButtons: ReviewButtonProps[] = [];
|
||||
const visibleButtons: ReviewButton[] = [];
|
||||
|
||||
if (roles.includes("Submitter")) {
|
||||
if (["UnderConstruction", "ChangesRequested"].includes(status!)) {
|
||||
visibleButtons.push({ name: "Submit", action: "submit", color: "info", submissionId });
|
||||
}
|
||||
if (["Submitted", "ChangesRequested"].includes(status!)) {
|
||||
visibleButtons.push({ name: "Revoke", action: "revoke", color: "info", submissionId });
|
||||
}
|
||||
}
|
||||
if (roles.includes("Submitter")) {
|
||||
if (["UnderConstruction", "ChangesRequested"].includes(status!)) {
|
||||
visibleButtons.push({ name: "Submit", action: "submit", color: "info", submissionId });
|
||||
}
|
||||
if (["Submitted", "ChangesRequested"].includes(status!)) {
|
||||
visibleButtons.push({ name: "Revoke", action: "revoke", color: "info", submissionId });
|
||||
}
|
||||
}
|
||||
|
||||
if (roles.includes("Reviewer")) {
|
||||
if (status === "Submitted") {
|
||||
visibleButtons.push({ name: "Accept", action: "trigger-validate", color: "info", submissionId });
|
||||
visibleButtons.push({ name: "Reject", action: "reject", color: "error", submissionId });
|
||||
}
|
||||
if (status === "Accepted") {
|
||||
visibleButtons.push({ name: "Validate", action: "retry-validate", color: "info", submissionId });
|
||||
}
|
||||
if (status === "Validating") {
|
||||
visibleButtons.push({ name: "Reset Validating (fix softlocked status)", action: "reset-validating", color: "error", submissionId });
|
||||
}
|
||||
if (["Validated", "Accepted", "Submitted"].includes(status!)) {
|
||||
visibleButtons.push({ name: "Request Changes", action: "request-changes", color: "error", submissionId });
|
||||
}
|
||||
}
|
||||
if (roles.includes("Reviewer")) {
|
||||
if (status === "Submitted") {
|
||||
visibleButtons.push({ name: "Accept", action: "trigger-validate", color: "info", submissionId });
|
||||
visibleButtons.push({ name: "Reject", action: "reject", color: "error", submissionId });
|
||||
}
|
||||
if (status === "Accepted") {
|
||||
visibleButtons.push({ name: "Validate", action: "retry-validate", color: "info", submissionId });
|
||||
}
|
||||
if (status === "Validating") {
|
||||
visibleButtons.push({ name: "Reset Validating (fix softlocked status)", action: "reset-validating", color: "error", submissionId });
|
||||
}
|
||||
if (["Validated", "Accepted", "Submitted"].includes(status!)) {
|
||||
visibleButtons.push({ name: "Request Changes", action: "request-changes", color: "error", submissionId });
|
||||
}
|
||||
}
|
||||
|
||||
if (roles.includes("MapAdmin")) {
|
||||
if (status === "Validated") {
|
||||
visibleButtons.push({ name: "Upload", action: "trigger-upload", color: "info", submissionId });
|
||||
}
|
||||
if (status === "Uploading") {
|
||||
visibleButtons.push({ name: "Reset Uploading (fix softlocked status)", action: "reset-uploading", color: "error", submissionId });
|
||||
}
|
||||
}
|
||||
if (roles.includes("MapAdmin")) {
|
||||
if (status === "Validated") {
|
||||
visibleButtons.push({ name: "Upload", action: "trigger-upload", color: "info", submissionId });
|
||||
}
|
||||
if (status === "Uploading") {
|
||||
visibleButtons.push({ name: "Reset Uploading (fix softlocked status)", action: "reset-uploading", color: "error", submissionId });
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="review-set">
|
||||
{visibleButtons.map((btn) => (
|
||||
<ReviewButton key={btn.action} {...btn} />
|
||||
))}
|
||||
</section>
|
||||
);
|
||||
return (
|
||||
<section className="review-set">
|
||||
{visibleButtons.map((btn) => (
|
||||
<ReviewButton key={btn.action} {...btn} />
|
||||
))}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user