parent
ee5b3331b4
commit
04817ad72c
@ -45,7 +45,6 @@ function ReviewButton(props: ReviewButton) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ReviewButtons(props: ReviewId) {
|
export default function ReviewButtons(props: ReviewId) {
|
||||||
const submissionId = props.submissionId
|
|
||||||
// When is each button visible?
|
// When is each button visible?
|
||||||
// Multiple buttons can be visible at once.
|
// Multiple buttons can be visible at once.
|
||||||
// Action | Role | When Current Status is One of:
|
// Action | Role | When Current Status is One of:
|
||||||
@ -59,16 +58,78 @@ export default function ReviewButtons(props: ReviewId) {
|
|||||||
// RequestChanges | Reviewer | Validated, Accepted, Submitted
|
// RequestChanges | Reviewer | Validated, Accepted, Submitted
|
||||||
// Upload | MapAdmin | Validated
|
// Upload | MapAdmin | Validated
|
||||||
// ResetUploading | MapAdmin | Uploading
|
// ResetUploading | MapAdmin | Uploading
|
||||||
return (
|
const { submissionId } = props;
|
||||||
<section className="review-set">
|
const [roles, setRoles] = useState<string[]>([]);
|
||||||
<ReviewButton color="info" name="Submit" action="submit" submissionId={submissionId}/>
|
const [status, setStatus] = useState<string | null>(null);
|
||||||
<ReviewButton color="info" name="Revoke" action="revoke" submissionId={submissionId}/>
|
const [loading, setLoading] = useState(true);
|
||||||
<ReviewButton color="info" name="Accept" action="trigger-validate" submissionId={submissionId}/>
|
|
||||||
<ReviewButton color="info" name="Validate" action="retry-validate" submissionId={submissionId}/>
|
useEffect(() => {
|
||||||
<ReviewButton color="error" name="Reject" action="reject" submissionId={submissionId}/>
|
async function fetchData() {
|
||||||
<ReviewButton color="info" name="Upload" action="trigger-upload" submissionId={submissionId}/>
|
try {
|
||||||
<ReviewButton color="error" name="Reset Uploading (fix softlocked status)" action="reset-uploading" submissionId={submissionId}/>
|
// Fetch user roles
|
||||||
<ReviewButton color="error" name="Reset Validating (fix softlocked status)" action="reset-validating" submissionId={submissionId}/>
|
const rolesResponse = await fetch("/api/session/roles");
|
||||||
</section>
|
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