parent
ee5b3331b4
commit
04817ad72c
@ -45,7 +45,6 @@ function ReviewButton(props: ReviewButton) {
|
||||
}
|
||||
|
||||
export default function ReviewButtons(props: ReviewId) {
|
||||
const submissionId = props.submissionId
|
||||
// When is each button visible?
|
||||
// Multiple buttons can be visible at once.
|
||||
// Action | Role | When Current Status is One of:
|
||||
@ -59,16 +58,78 @@ export default function ReviewButtons(props: ReviewId) {
|
||||
// RequestChanges | Reviewer | Validated, Accepted, Submitted
|
||||
// Upload | MapAdmin | Validated
|
||||
// ResetUploading | MapAdmin | Uploading
|
||||
return (
|
||||
<section className="review-set">
|
||||
<ReviewButton color="info" name="Submit" action="submit" submissionId={submissionId}/>
|
||||
<ReviewButton color="info" name="Revoke" action="revoke" submissionId={submissionId}/>
|
||||
<ReviewButton color="info" name="Accept" action="trigger-validate" submissionId={submissionId}/>
|
||||
<ReviewButton color="info" name="Validate" action="retry-validate" submissionId={submissionId}/>
|
||||
<ReviewButton color="error" name="Reject" action="reject" submissionId={submissionId}/>
|
||||
<ReviewButton color="info" name="Upload" action="trigger-upload" submissionId={submissionId}/>
|
||||
<ReviewButton color="error" name="Reset Uploading (fix softlocked status)" action="reset-uploading" submissionId={submissionId}/>
|
||||
<ReviewButton color="error" name="Reset Validating (fix softlocked status)" action="reset-validating" submissionId={submissionId}/>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
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();
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
fetchData();
|
||||
}, [submissionId]);
|
||||
|
||||
if (loading) return <p>Loading...</p>;
|
||||
|
||||
const visibleButtons: ReviewButtonProps[] = [];
|
||||
|
||||
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("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>
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user