submit 'type' fixes
This commit is contained in:
parent
c0b9e017f0
commit
e1b1f3cb34
2 changed files with 12 additions and 23 deletions
0
app/api/directus/fields/route.ts
Normal file
0
app/api/directus/fields/route.ts
Normal file
|
|
@ -107,38 +107,28 @@ function useOptions(path: string) {
|
|||
});
|
||||
};
|
||||
}
|
||||
|
||||
} else if (rawPath === "repeater-choices") {
|
||||
// target=<collection>, group=<repeater field>, field=<child field>
|
||||
const group = params.get("group") || "";
|
||||
const field = params.get("field") || "";
|
||||
const collection = params.get("target") || "";
|
||||
|
||||
// 1) Preferred: /fields/{collection}
|
||||
let fieldsUrl = `${API}/fields/${encodeURIComponent(collection)}`;
|
||||
let rows: any[] = [];
|
||||
|
||||
// Fetch with NO credentials (public-readable)
|
||||
let metaRes = await fetch(fieldsUrl, { cache: "no-store" });
|
||||
if (metaRes.ok) {
|
||||
const j = await metaRes.json().catch(() => ({}));
|
||||
rows = Array.isArray(j?.data) ? j.data : Array.isArray(j) ? j : [];
|
||||
} else {
|
||||
// 2) Fallback: /fields?filter[collection][_eq]=...
|
||||
fieldsUrl = `${API}/fields?filter[collection][_eq]=${encodeURIComponent(collection)}`;
|
||||
metaRes = await fetch(fieldsUrl, { cache: "no-store" });
|
||||
if (!metaRes.ok) throw new Error(`Directus ${metaRes.status} fetching ${fieldsUrl}`);
|
||||
const j = await metaRes.json().catch(() => ({}));
|
||||
rows = Array.isArray(j?.data) ? j.data : Array.isArray(j) ? j : [];
|
||||
}
|
||||
// 🔁 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}`);
|
||||
const metaJson = await metaRes.json().catch(() => ({}));
|
||||
const rows: any[] = Array.isArray(metaJson?.data) ? metaJson.data : [];
|
||||
|
||||
// Try nested child first: parent.meta.options.fields -> child where field === <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)
|
||||
nestedChildren.find((f: any) => f?.field === field) ||
|
||||
// Flat fallback: "group.field"
|
||||
|| rows.find((r: any) => r?.field === `${group}.${field}`);
|
||||
rows.find((r: any) => r?.field === `${group}.${field}`);
|
||||
|
||||
// Choices can live on child.options.choices or child.meta.options.choices
|
||||
const choices: any[] =
|
||||
|
|
@ -158,9 +148,8 @@ function useOptions(path: string) {
|
|||
setLoading(false);
|
||||
}
|
||||
return; // short-circuit
|
||||
|
||||
} else {
|
||||
|
||||
// unknown path → empty
|
||||
setOpts([]);
|
||||
setLoading(false);
|
||||
return;
|
||||
|
|
@ -315,7 +304,7 @@ export default function SettingsSubmit({ initialTarget }: { initialTarget?: Targ
|
|||
|
||||
// Options
|
||||
const mats = useOptions("material");
|
||||
const coats = useOptions("material_coating");
|
||||
the coats = useOptions("material_coating");
|
||||
const colors = useOptions("material_color");
|
||||
const opacs = useOptions("material_opacity");
|
||||
const soft = useOptions("laser_software"); // required for ALL targets
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue