feat: integrate submit form answer with backend
Docker Build and Push / build-and-push (push) Successful in 5m22s

This commit is contained in:
2026-02-22 14:41:52 +07:00
parent 2e28656a93
commit 4014ec802a
5 changed files with 470 additions and 5 deletions
+14 -1
View File
@@ -6,7 +6,7 @@ import {
isTokenExpired,
decodeJWT,
} from "@/lib/auth"
import type { FormSummary, FormDetail, CreateFormPayload, UpdateFormPayload } from "@/lib/types"
import type { FormSummary, FormDetail, CreateFormPayload, UpdateFormPayload, SubmitFormPayload } from "@/lib/types"
export async function refreshAccessToken(): Promise<string | null> {
if (typeof window === "undefined") return null
@@ -210,6 +210,19 @@ export async function updateForm(id: string, payload: UpdateFormPayload): Promis
return res.json()
}
export async function submitFormResponse(id: string, payload: SubmitFormPayload): Promise<void> {
const res = await fetch(`${import.meta.env.VITE_API_BASE_URL}/api/form/${id}/response`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
})
if (!res.ok) {
const data = await res.json().catch(() => null)
throw new Error(data?.message ?? "Failed to submit form response")
}
}
export async function deleteForm(id: string): Promise<void> {
const res = await fetchWithAuth(`${import.meta.env.VITE_API_BASE_URL}/api/form/${id}`, {
method: "DELETE",