Files
portal/src/lib/svelte-admin/form-data.ts
T
NeilClack 38d1752f5b admin: Superforms + Zod validation, three-address-defaults schema, profiles toast fix
- Add Superforms + Zod 4 for all admin form validation
- Replace address isDefault with three separate boolean defaults (Mailing, Billing, Shipping)
- Update profiles page with three-checkbox address form and toast improvements
- Convert all admin page server actions to pass request directly to crud
- Export superFormErrorsToFieldErrors helper for profiles server actions
- Regenerate Prisma client for new schema fields
2026-07-07 13:36:23 -05:00

47 lines
1.0 KiB
TypeScript

import type { PrismaScalarType } from './types';
export function extractFormData(
formData: FormData,
formFields: string[],
fieldTypes: Record<string, PrismaScalarType>
): Record<string, unknown> {
const data: Record<string, unknown> = {};
for (const field of formFields) {
const type = fieldTypes[field] ?? 'String';
const raw = formData.get(field);
switch (type) {
case 'Int': {
const val = raw?.toString() ?? '';
data[field] = val === '' ? null : parseInt(val, 10);
break;
}
case 'Float': {
const val = raw?.toString() ?? '';
data[field] = val === '' ? null : parseFloat(val);
break;
}
case 'Boolean': {
data[field] = raw === 'on' || raw === 'true';
break;
}
case 'DateTime': {
const val = raw?.toString() ?? '';
data[field] = val === '' ? null : new Date(val);
break;
}
case 'Tiptap': {
data[field] = raw?.toString() ?? '';
break;
}
default: {
data[field] = raw?.toString() ?? '';
break;
}
}
}
return data;
}