mirror of
https://github.com/faiztyanirh/clqms-shadcn-v1.git
synced 2026-04-22 17:19:52 +07:00
fix ubah url parameter dari parent jadi ProvinceID fix tampilan input bisa fullWidth atau tidak dari form config
196 lines
5.7 KiB
JavaScript
196 lines
5.7 KiB
JavaScript
import { API } from "$lib/config/api";
|
|
import EraserIcon from "@lucide/svelte/icons/eraser";
|
|
import { z } from "zod";
|
|
|
|
export const locationSchema = z.object({
|
|
LocCode: z.string().min(1, "Required"),
|
|
LocFull: z.string().min(1, "Required"),
|
|
Email: z.string().trim().optional().refine((val) => !val || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val),"Invalid email format"),
|
|
Phone: z.string().max(14, "Max 14 chars").regex(/^$|^[0-9]+$/, "Can only contain numbers"),
|
|
ZIP: z.string().regex(/^$|^[0-9]+$/, "Can only contain numbers"),
|
|
});
|
|
|
|
export const locationInitialForm = {
|
|
LocationID: '',
|
|
LocCode: '',
|
|
LocType: '',
|
|
LocFull: '',
|
|
SiteID: '',
|
|
Street1: '',
|
|
Street2: '',
|
|
Phone: '',
|
|
Email: '',
|
|
City: '',
|
|
Province: '',
|
|
ZIP: '',
|
|
GeoLocationSystem: '',
|
|
GeoLocationData: '',
|
|
};
|
|
|
|
export const locationDefaultErrors = {
|
|
LocCode: "Required",
|
|
LocFull: "Required",
|
|
Email: null,
|
|
Phone: null,
|
|
ZIP: null,
|
|
};
|
|
|
|
export const locationFormFields = [
|
|
{
|
|
title: "Basic Information",
|
|
rows: [
|
|
{
|
|
type: "row",
|
|
columns: [
|
|
{
|
|
key: "SiteID",
|
|
label: "Site ID",
|
|
required: false,
|
|
type: "select",
|
|
optionsEndpoint: `${API.BASE_URL}${API.SITE}`,
|
|
valueKey: "SiteID",
|
|
labelKey: (item) => `${item.SiteCode} - ${item.SiteName}`,
|
|
},
|
|
{
|
|
key: "LocCode",
|
|
label: "Location Code",
|
|
required: true,
|
|
type: "text",
|
|
validateOn: ["input"]
|
|
},
|
|
]
|
|
},
|
|
{
|
|
type: "row",
|
|
columns: [
|
|
{
|
|
key: "LocType",
|
|
label: "Location Type",
|
|
required: false,
|
|
type: "select",
|
|
optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/location_type`,
|
|
},
|
|
{
|
|
key: "LocFull",
|
|
label: "Location Name",
|
|
required: true,
|
|
type: "text",
|
|
validateOn: ["input"]
|
|
}
|
|
]
|
|
},
|
|
]
|
|
},
|
|
{
|
|
title: "Address Detail",
|
|
rows: [
|
|
{
|
|
type: "row",
|
|
columns: [
|
|
{
|
|
key: "Province",
|
|
label: "Province",
|
|
required: false,
|
|
type: "select",
|
|
optionsEndpoint: `${API.BASE_URL}${API.PROVINCE}`,
|
|
},
|
|
{
|
|
key: "Street1",
|
|
label: "Street 1",
|
|
required: false,
|
|
type: "text",
|
|
},
|
|
]
|
|
},
|
|
{
|
|
type: "row",
|
|
columns: [
|
|
{
|
|
key: "City",
|
|
label: "City",
|
|
required: false,
|
|
type: "select",
|
|
optionsEndpoint: `${API.BASE_URL}${API.CITY}`,
|
|
dependsOn: "Province",
|
|
endpointParamKey: "ProvinceID"
|
|
},
|
|
{
|
|
key: "Street2",
|
|
label: "Street 2",
|
|
required: false,
|
|
type: "text",
|
|
}
|
|
]
|
|
},
|
|
{
|
|
type: "row",
|
|
columns: [
|
|
{
|
|
key: "ZIP",
|
|
label: "ZIP",
|
|
required: false,
|
|
type: "text",
|
|
validateOn: ["input"],
|
|
fullWidth: false
|
|
},
|
|
]
|
|
},
|
|
]
|
|
},
|
|
{
|
|
title: "Contact Information",
|
|
rows: [
|
|
{
|
|
type: "row",
|
|
columns: [
|
|
{
|
|
key: "Phone",
|
|
label: "Phone",
|
|
required: false,
|
|
type: "text",
|
|
validateOn: ["input"]
|
|
},
|
|
{
|
|
key: "Email",
|
|
label: "Email",
|
|
required: false,
|
|
type: "text",
|
|
validateOn: ["input"]
|
|
}
|
|
]
|
|
},
|
|
]
|
|
},
|
|
{
|
|
title: "Geographic Data",
|
|
rows: [
|
|
{
|
|
type: "row",
|
|
columns: [
|
|
{
|
|
key: "GeoLocationSystem",
|
|
label: "Geo Location System",
|
|
required: false,
|
|
type: "text",
|
|
},
|
|
{
|
|
key: "GeoLocationData",
|
|
label: "Geo Location Data",
|
|
required: false,
|
|
type: "text",
|
|
},
|
|
]
|
|
},
|
|
]
|
|
},
|
|
];
|
|
|
|
export function getLocationFormActions(handlers) {
|
|
return [
|
|
{
|
|
Icon: EraserIcon,
|
|
label: 'Clear Form',
|
|
onClick: handlers.clearForm,
|
|
},
|
|
];
|
|
} |