Add upsert tournament team write API

Closes #3294
This commit is contained in:
Kalle
2026-08-05 21:49:35 +03:00
parent 82c6a4b850
commit 3d4ac9f452
5 changed files with 221 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import type { ActionFunction, ActionFunctionArgs } from "react-router";
* The existing actions use:
* - `successToast(message)` which returns `redirect("?__success=message")`
* - `errorToastIfFalsy/errorToastIfErr` which throw `redirect("?__error=message")`
* - `{ fieldErrors }` returns for form validation failures
*/
export async function wrapActionForApi(
actionFn: ActionFunction,
@@ -19,6 +20,19 @@ export async function wrapActionForApi(
return new Response(null, { status: 200 });
}
if (response && typeof response === "object" && "fieldErrors" in response) {
return new Response(
JSON.stringify({
error: "Validation failed",
fieldErrors: response.fieldErrors,
}),
{
status: 400,
headers: { "Content-Type": "application/json" },
},
);
}
return response as Response;
} catch (e) {
if (e instanceof Response && e.status === 302) {