web: submit page navigates to newly created submission
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f629ac2998
commit
d584ee2c03
@ -17,6 +17,9 @@ interface SubmissionPayload {
|
|||||||
AssetVersion: number;
|
AssetVersion: number;
|
||||||
SubmissionType: number;
|
SubmissionType: number;
|
||||||
}
|
}
|
||||||
|
interface IdResponse {
|
||||||
|
ID: number;
|
||||||
|
}
|
||||||
|
|
||||||
export default function SubmissionInfoPage() {
|
export default function SubmissionInfoPage() {
|
||||||
const [game, setGame] = useState(1);
|
const [game, setGame] = useState(1);
|
||||||
@ -24,10 +27,10 @@ export default function SubmissionInfoPage() {
|
|||||||
|
|
||||||
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
const form = event.currentTarget;
|
const form = event.currentTarget;
|
||||||
const formData = new FormData(form);
|
const formData = new FormData(form);
|
||||||
|
|
||||||
const payload: SubmissionPayload = {
|
const payload: SubmissionPayload = {
|
||||||
DisplayName: (formData.get("display-name") as string) ?? "unknown", // TEMPORARY! TODO: Change
|
DisplayName: (formData.get("display-name") as string) ?? "unknown", // TEMPORARY! TODO: Change
|
||||||
Creator: (formData.get("creator") as string) ?? "unknown", // TEMPORARY! TODO: Change
|
Creator: (formData.get("creator") as string) ?? "unknown", // TEMPORARY! TODO: Change
|
||||||
@ -39,7 +42,7 @@ export default function SubmissionInfoPage() {
|
|||||||
|
|
||||||
console.log(payload)
|
console.log(payload)
|
||||||
console.log(JSON.stringify(payload))
|
console.log(JSON.stringify(payload))
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Send the POST request
|
// Send the POST request
|
||||||
const response = await fetch("/api/submissions", {
|
const response = await fetch("/api/submissions", {
|
||||||
@ -47,16 +50,18 @@ export default function SubmissionInfoPage() {
|
|||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Allow any HTTP status
|
// Allow any HTTP status
|
||||||
const responseText = await response.text();
|
const id_response:IdResponse = await response.json();
|
||||||
|
|
||||||
console.log("Response Text:", responseText);
|
// navigate to newly created submission
|
||||||
|
window.location.assign(`/submissions/${id_response.ID}`)
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error submitting data:", error);
|
console.error("Error submitting data:", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Webpage>
|
<Webpage>
|
||||||
<main>
|
<main>
|
||||||
@ -90,4 +95,4 @@ export default function SubmissionInfoPage() {
|
|||||||
</main>
|
</main>
|
||||||
</Webpage>
|
</Webpage>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user