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;
|
||||
SubmissionType: number;
|
||||
}
|
||||
interface IdResponse {
|
||||
ID: number;
|
||||
}
|
||||
|
||||
export default function SubmissionInfoPage() {
|
||||
const [game, setGame] = useState(1);
|
||||
@ -24,10 +27,10 @@ export default function SubmissionInfoPage() {
|
||||
|
||||
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
|
||||
|
||||
const form = event.currentTarget;
|
||||
const formData = new FormData(form);
|
||||
|
||||
|
||||
const payload: SubmissionPayload = {
|
||||
DisplayName: (formData.get("display-name") 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(JSON.stringify(payload))
|
||||
|
||||
|
||||
try {
|
||||
// Send the POST request
|
||||
const response = await fetch("/api/submissions", {
|
||||
@ -47,16 +50,18 @@ export default function SubmissionInfoPage() {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
|
||||
// Allow any HTTP status
|
||||
const responseText = await response.text();
|
||||
|
||||
console.log("Response Text:", responseText);
|
||||
const id_response:IdResponse = await response.json();
|
||||
|
||||
// navigate to newly created submission
|
||||
window.location.assign(`/submissions/${id_response.ID}`)
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error submitting data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<Webpage>
|
||||
<main>
|
||||
@ -90,4 +95,4 @@ export default function SubmissionInfoPage() {
|
||||
</main>
|
||||
</Webpage>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user