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") {
|
} else if (rawPath === "repeater-choices") {
|
||||||
// target=<collection>, group=<repeater field>, field=<child field>
|
// target=<collection>, group=<repeater field>, field=<child field>
|
||||||
const group = params.get("group") || "";
|
const group = params.get("group") || "";
|
||||||
const field = params.get("field") || "";
|
const field = params.get("field") || "";
|
||||||
const collection = params.get("target") || "";
|
const collection = params.get("target") || "";
|
||||||
|
|
||||||
// 1) Preferred: /fields/{collection}
|
// 🔁 CHANGE: fetch fields via server proxy (uses Directus token server-side)
|
||||||
let fieldsUrl = `${API}/fields/${encodeURIComponent(collection)}`;
|
const metaRes = await fetch(
|
||||||
let rows: any[] = [];
|
`/api/directus/fields?collection=${encodeURIComponent(collection)}`,
|
||||||
|
{ cache: "no-store" }
|
||||||
// Fetch with NO credentials (public-readable)
|
);
|
||||||
let metaRes = await fetch(fieldsUrl, { cache: "no-store" });
|
if (!metaRes.ok) throw new Error(`Fields ${metaRes.status}`);
|
||||||
if (metaRes.ok) {
|
const metaJson = await metaRes.json().catch(() => ({}));
|
||||||
const j = await metaRes.json().catch(() => ({}));
|
const rows: any[] = Array.isArray(metaJson?.data) ? metaJson.data : [];
|
||||||
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 : [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try nested child first: parent.meta.options.fields -> child where field === <field>
|
// Try nested child first: parent.meta.options.fields -> child where field === <field>
|
||||||
const parent = rows.find((r: any) => r?.field === group);
|
const parent = rows.find((r: any) => r?.field === group);
|
||||||
const nestedChildren = parent?.meta?.options?.fields || [];
|
const nestedChildren = parent?.meta?.options?.fields || [];
|
||||||
let child =
|
let child =
|
||||||
nestedChildren.find((f: any) => f?.field === field)
|
nestedChildren.find((f: any) => f?.field === field) ||
|
||||||
// Flat fallback: "group.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
|
// Choices can live on child.options.choices or child.meta.options.choices
|
||||||
const choices: any[] =
|
const choices: any[] =
|
||||||
|
|
@ -158,9 +148,8 @@ function useOptions(path: string) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
return; // short-circuit
|
return; // short-circuit
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
// unknown path → empty
|
||||||
setOpts([]);
|
setOpts([]);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
|
|
@ -315,7 +304,7 @@ export default function SettingsSubmit({ initialTarget }: { initialTarget?: Targ
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
const mats = useOptions("material");
|
const mats = useOptions("material");
|
||||||
const coats = useOptions("material_coating");
|
the coats = useOptions("material_coating");
|
||||||
const colors = useOptions("material_color");
|
const colors = useOptions("material_color");
|
||||||
const opacs = useOptions("material_opacity");
|
const opacs = useOptions("material_opacity");
|
||||||
const soft = useOptions("laser_software"); // required for ALL targets
|
const soft = useOptions("laser_software"); // required for ALL targets
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue