From aa8436da93e069a9d2e3a09c04f72bfebf9828f4 Mon Sep 17 00:00:00 2001 From: makearmy Date: Sun, 28 Sep 2025 23:53:17 -0400 Subject: [PATCH] submit 'type' fixes --- app/components/forms/SettingsSubmit.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/components/forms/SettingsSubmit.tsx b/app/components/forms/SettingsSubmit.tsx index 1525047e..cfaf94f4 100644 --- a/app/components/forms/SettingsSubmit.tsx +++ b/app/components/forms/SettingsSubmit.tsx @@ -113,21 +113,19 @@ function useOptions(path: string) { const field = params.get("field") || ""; const collection = params.get("target") || ""; - // 🔁 CHANGE: fetch fields via server proxy (uses Directus token server-side) - const metaRes = await fetch( - `/api/directus/fields?collection=${encodeURIComponent(collection)}`, - { cache: "no-store" } - ); - if (!metaRes.ok) throw new Error(`Fields ${metaRes.status}`); + // Call our server proxy so it can use the server token + const proxyUrl = `/api/directus/fields?collection=${encodeURIComponent(collection)}`; + const metaRes = await fetch(proxyUrl, { cache: "no-store" }); + if (!metaRes.ok) throw new Error(`Proxy ${metaRes.status} fetching ${proxyUrl}`); + const metaJson = await metaRes.json().catch(() => ({})); - const rows: any[] = Array.isArray(metaJson?.data) ? metaJson.data : []; + const rows: any[] = Array.isArray(metaJson?.data) ? metaJson.data : Array.isArray(metaJson) ? metaJson : []; // Try nested child first: parent.meta.options.fields -> child where field === const parent = rows.find((r: any) => r?.field === group); const nestedChildren = parent?.meta?.options?.fields || []; let child = nestedChildren.find((f: any) => f?.field === field) || - // Flat fallback: "group.field" rows.find((r: any) => r?.field === `${group}.${field}`); // Choices can live on child.options.choices or child.meta.options.choices @@ -148,6 +146,8 @@ function useOptions(path: string) { setLoading(false); } return; // short-circuit + } + } else { // unknown path → empty setOpts([]);