295 lines
7.4 KiB
TypeScript
295 lines
7.4 KiB
TypeScript
import { z } from "zod";
|
||
import { flattenFieldDefinitions } from "@/eventRouters/schemas/zodSchemas";
|
||
|
||
interface ServiceData {
|
||
uu_id: string;
|
||
module_uu_id: string;
|
||
service_name: string;
|
||
service_description?: string;
|
||
service_code: string;
|
||
related_responsibility?: string;
|
||
is_confirmed: boolean;
|
||
active: boolean;
|
||
deleted?: boolean;
|
||
created_at?: string;
|
||
updated_at?: string;
|
||
}
|
||
|
||
const errorMessages = {
|
||
en: {
|
||
moduleUuIdRequired: "Module UUID is required",
|
||
serviceNameRequired: "Service name is required",
|
||
serviceCodeRequired: "Service code is required",
|
||
},
|
||
tr: {
|
||
moduleUuIdRequired: "Modül UUID'si gereklidir",
|
||
serviceNameRequired: "Servis adı gereklidir",
|
||
serviceCodeRequired: "Servis kodu gereklidir",
|
||
},
|
||
};
|
||
|
||
const getServiceBaseSchema = (lang: "en" | "tr" = "en") =>
|
||
z.object({
|
||
uu_id: z.string().optional(),
|
||
module_uu_id: z.string().min(1, errorMessages[lang].moduleUuIdRequired),
|
||
service_name: z.string().min(1, errorMessages[lang].serviceNameRequired),
|
||
service_description: z.string().optional(),
|
||
service_code: z.string().min(1, errorMessages[lang].serviceCodeRequired),
|
||
related_responsibility: z.string().optional(),
|
||
is_confirmed: z.boolean().default(false),
|
||
active: z.boolean().default(true),
|
||
deleted: z.boolean().default(false),
|
||
created_at: z.string().optional(),
|
||
updated_at: z.string().optional(),
|
||
});
|
||
|
||
const ServiceBaseSchema = getServiceBaseSchema("en");
|
||
const ServiceBaseTranslationTr = {
|
||
uu_id: "UUID",
|
||
module_uu_id: "Modül UUID'si",
|
||
service_name: "Servis Adı",
|
||
service_description: "Servis Açıklaması",
|
||
service_code: "Servis Kodu",
|
||
related_responsibility: "İlgili Sorumluluk",
|
||
is_confirmed: "Onaylandı",
|
||
active: "Active",
|
||
deleted: "Deleted",
|
||
created_at: "Created At",
|
||
updated_at: "Updated At",
|
||
};
|
||
const ServiceBaseTranslationEn = {
|
||
uu_id: "UUID",
|
||
module_uu_id: "Module UUID",
|
||
service_name: "Service Name",
|
||
service_description: "Service Description",
|
||
service_code: "Service Code",
|
||
related_responsibility: "Related Responsibility",
|
||
is_confirmed: "Confirmed",
|
||
active: "Active",
|
||
deleted: "Deleted",
|
||
created_at: "Created At",
|
||
updated_at: "Updated At",
|
||
};
|
||
const ViewServiceSchema = ServiceBaseSchema;
|
||
const ServiceSchema = ServiceBaseSchema;
|
||
const serviceBaseFieldDefinitions = {
|
||
identificationInfo: {
|
||
title: "Service Information",
|
||
order: 1,
|
||
fields: {
|
||
uu_id: {
|
||
type: "text",
|
||
label: {
|
||
tr: ServiceBaseTranslationTr.uu_id,
|
||
en: ServiceBaseTranslationEn.uu_id,
|
||
},
|
||
readOnly: true,
|
||
required: false,
|
||
},
|
||
module_uu_id: {
|
||
type: "text",
|
||
label: {
|
||
tr: ServiceBaseTranslationTr.module_uu_id,
|
||
en: ServiceBaseTranslationEn.module_uu_id,
|
||
},
|
||
readOnly: false,
|
||
required: true,
|
||
},
|
||
service_name: {
|
||
type: "text",
|
||
label: {
|
||
tr: ServiceBaseTranslationTr.service_name,
|
||
en: ServiceBaseTranslationEn.service_name,
|
||
},
|
||
readOnly: false,
|
||
required: true,
|
||
},
|
||
service_description: {
|
||
type: "text",
|
||
label: {
|
||
tr: ServiceBaseTranslationTr.service_description,
|
||
en: ServiceBaseTranslationEn.service_description,
|
||
},
|
||
readOnly: false,
|
||
required: true,
|
||
},
|
||
service_code: {
|
||
type: "text",
|
||
label: {
|
||
tr: ServiceBaseTranslationTr.service_code,
|
||
en: ServiceBaseTranslationEn.service_code,
|
||
},
|
||
readOnly: false,
|
||
required: true,
|
||
},
|
||
related_responsibility: {
|
||
type: "text",
|
||
label: {
|
||
tr: ServiceBaseTranslationTr.related_responsibility,
|
||
en: ServiceBaseTranslationEn.related_responsibility,
|
||
},
|
||
readOnly: false,
|
||
required: false,
|
||
},
|
||
},
|
||
},
|
||
|
||
statusInfo: {
|
||
title: "Status Information",
|
||
order: 3,
|
||
fields: {
|
||
active: {
|
||
type: "checkbox",
|
||
label: {
|
||
tr: ServiceBaseTranslationTr.active,
|
||
en: ServiceBaseTranslationEn.active,
|
||
},
|
||
readOnly: false,
|
||
required: false,
|
||
defaultValue: true,
|
||
},
|
||
deleted: {
|
||
type: "checkbox",
|
||
label: {
|
||
tr: ServiceBaseTranslationTr.deleted,
|
||
en: ServiceBaseTranslationEn.deleted,
|
||
},
|
||
readOnly: true,
|
||
required: false,
|
||
defaultValue: false,
|
||
},
|
||
is_confirmed: {
|
||
type: "checkbox",
|
||
label: {
|
||
tr: ServiceBaseTranslationTr.is_confirmed,
|
||
en: ServiceBaseTranslationEn.is_confirmed,
|
||
},
|
||
readOnly: false,
|
||
required: true,
|
||
},
|
||
},
|
||
},
|
||
|
||
systemInfo: {
|
||
title: "System Information",
|
||
order: 4,
|
||
fields: {
|
||
created_at: {
|
||
type: "date",
|
||
label: {
|
||
tr: ServiceBaseTranslationTr.created_at,
|
||
en: ServiceBaseTranslationEn.created_at,
|
||
},
|
||
readOnly: true,
|
||
required: false,
|
||
},
|
||
updated_at: {
|
||
type: "date",
|
||
label: {
|
||
tr: ServiceBaseTranslationTr.updated_at,
|
||
en: ServiceBaseTranslationEn.updated_at,
|
||
},
|
||
readOnly: true,
|
||
required: false,
|
||
},
|
||
},
|
||
},
|
||
};
|
||
const serviceFlatFieldDefinitions = flattenFieldDefinitions(
|
||
serviceBaseFieldDefinitions
|
||
);
|
||
const serviceViewFieldDefinitions = {
|
||
uu_id: {
|
||
...serviceFlatFieldDefinitions.uu_id,
|
||
readOnly: true,
|
||
required: false,
|
||
defaultValue: 0,
|
||
},
|
||
module_uu_id: {
|
||
...serviceFlatFieldDefinitions.module_uu_id,
|
||
readOnly: true,
|
||
required: false,
|
||
defaultValue: "",
|
||
},
|
||
service_name: {
|
||
...serviceFlatFieldDefinitions.service_name,
|
||
readOnly: true,
|
||
required: false,
|
||
defaultValue: "",
|
||
},
|
||
service_description: {
|
||
...serviceFlatFieldDefinitions.service_description,
|
||
readOnly: true,
|
||
required: false,
|
||
defaultValue: "",
|
||
},
|
||
service_code: {
|
||
...serviceFlatFieldDefinitions.service_code,
|
||
readOnly: true,
|
||
required: false,
|
||
defaultValue: "",
|
||
},
|
||
related_responsibility: {
|
||
...serviceFlatFieldDefinitions.related_responsibility,
|
||
readOnly: true,
|
||
required: false,
|
||
defaultValue: "",
|
||
},
|
||
active: {
|
||
...serviceFlatFieldDefinitions.active,
|
||
readOnly: true,
|
||
required: false,
|
||
defaultValue: true,
|
||
},
|
||
is_confirmed: {
|
||
...serviceFlatFieldDefinitions.is_confirmed,
|
||
readOnly: true,
|
||
required: false,
|
||
defaultValue: true,
|
||
},
|
||
deleted: {
|
||
...serviceFlatFieldDefinitions.deleted,
|
||
readOnly: true,
|
||
required: false,
|
||
defaultValue: false,
|
||
},
|
||
created_at: {
|
||
...serviceFlatFieldDefinitions.created_at,
|
||
readOnly: true,
|
||
required: false,
|
||
defaultValue: "",
|
||
},
|
||
updated_at: {
|
||
...serviceFlatFieldDefinitions.updated_at,
|
||
readOnly: true,
|
||
required: false,
|
||
defaultValue: "",
|
||
},
|
||
};
|
||
const serviceFieldDefinitions = {
|
||
...serviceBaseFieldDefinitions,
|
||
getDefinitionsByMode: (mode: "view") => {
|
||
switch (mode) {
|
||
case "view":
|
||
return serviceViewFieldDefinitions;
|
||
default:
|
||
return serviceBaseFieldDefinitions;
|
||
}
|
||
},
|
||
};
|
||
const serviceFieldsByMode = {
|
||
view: Object.keys(serviceViewFieldDefinitions),
|
||
};
|
||
|
||
type ServiceFormData = z.infer<typeof ServiceSchema>;
|
||
type ServiceViewFormData = z.infer<typeof ViewServiceSchema>;
|
||
type ServiceFieldDefinitionsType = typeof serviceViewFieldDefinitions;
|
||
|
||
export type { ServiceData, ServiceFieldDefinitionsType };
|
||
export {
|
||
ServiceSchema,
|
||
serviceViewFieldDefinitions,
|
||
ServiceBaseTranslationEn,
|
||
ServiceBaseTranslationTr,
|
||
};
|