mirror of
https://github.com/faiztyanirh/clqms-shadcn-v1.git
synced 2026-04-25 18:42:05 +07:00
fix rule val factor to config
This commit is contained in:
parent
9851697c52
commit
3f482fdecc
@ -8,8 +8,8 @@ export const testSchema = z
|
|||||||
.object({
|
.object({
|
||||||
TestSiteCode: z.string().min(1, 'Required'),
|
TestSiteCode: z.string().min(1, 'Required'),
|
||||||
TestSiteName: z.string().min(1, 'Required'),
|
TestSiteName: z.string().min(1, 'Required'),
|
||||||
Factor: z.string().optional(),
|
Factor: z.preprocess((val) => (val === '' || val === null || val === undefined ? undefined : Number(val)), z.number().optional()),
|
||||||
Unit2: z.string().optional(),
|
Unit2: z.preprocess((val) => (val === null ? undefined : val), z.string().optional()),
|
||||||
Decimal: z.preprocess(
|
Decimal: z.preprocess(
|
||||||
(val) => {
|
(val) => {
|
||||||
if (val === '' || val === null || val === undefined) return undefined;
|
if (val === '' || val === null || val === undefined) return undefined;
|
||||||
@ -79,37 +79,37 @@ export const testGroupSchema = z
|
|||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
id: z.number(),
|
id: z.number(),
|
||||||
value: z.string(),
|
value: z.string()
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.optional()
|
.optional()
|
||||||
})
|
})
|
||||||
.superRefine((data, ctx) => {
|
.superRefine((data, ctx) => {
|
||||||
if (!data.Members) return;
|
if (!data.Members) return;
|
||||||
|
|
||||||
const values = data.Members.map(m => m.value).filter(Boolean);
|
const values = data.Members.map((m) => m.value).filter(Boolean);
|
||||||
const duplicates = values.filter((v, i) => values.indexOf(v) !== i);
|
const duplicates = values.filter((v, i) => values.indexOf(v) !== i);
|
||||||
|
|
||||||
if (duplicates.length) {
|
if (duplicates.length) {
|
||||||
const uniqueDuplicates = [...new Set(duplicates)];
|
const uniqueDuplicates = [...new Set(duplicates)];
|
||||||
|
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: `Duplicate member : ${uniqueDuplicates.join(", ")}`,
|
message: `Duplicate member : ${uniqueDuplicates.join(', ')}`,
|
||||||
path: ["Members"]
|
path: ['Members']
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export const refNumSchema = z
|
export const refNumSchema = z
|
||||||
.object({
|
.object({
|
||||||
AgeStart: z.coerce.string().optional(),
|
AgeStart: z.coerce.string().optional(),
|
||||||
AgeEnd: z.coerce.string().optional(),
|
AgeEnd: z.coerce.string().optional(),
|
||||||
Low: z.coerce.string().optional(),
|
Low: z.coerce.string().optional(),
|
||||||
High: z.coerce.string().optional(),
|
High: z.coerce.string().optional(),
|
||||||
LowSign: z.string().optional(),
|
LowSign: z.string().optional(),
|
||||||
HighSign: z.string().optional(),
|
HighSign: z.string().optional(),
|
||||||
NumRefType: z.string().optional()
|
NumRefType: z.string().optional()
|
||||||
})
|
})
|
||||||
.superRefine((data, ctx) => {
|
.superRefine((data, ctx) => {
|
||||||
const start = toDays(data.AgeStart);
|
const start = toDays(data.AgeStart);
|
||||||
@ -150,7 +150,7 @@ export const refNumSchema = z
|
|||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: 'Low sign must be =, > or >=',
|
message: 'Low sign must be =, > or >=',
|
||||||
path: ['LowSign'],
|
path: ['LowSign']
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (data.High && !data.HighSign) {
|
if (data.High && !data.HighSign) {
|
||||||
@ -164,7 +164,7 @@ export const refNumSchema = z
|
|||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: 'High sign must be =, < or <=',
|
message: 'High sign must be =, < or <=',
|
||||||
path: ['HighSign'],
|
path: ['HighSign']
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (data.LowSign && data.HighSign && data.LowSign === data.HighSign) {
|
if (data.LowSign && data.HighSign && data.LowSign === data.HighSign) {
|
||||||
@ -245,7 +245,7 @@ export const testInitialForm = {
|
|||||||
isVisibleRpt: 1,
|
isVisibleRpt: 1,
|
||||||
isCountStat: 1,
|
isCountStat: 1,
|
||||||
Level: '',
|
Level: '',
|
||||||
isRequestable: 1,
|
isRequestable: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
export const testCalInitialForm = {
|
export const testCalInitialForm = {
|
||||||
@ -258,8 +258,8 @@ export const testCalInitialForm = {
|
|||||||
export const testGroupInitialForm = {
|
export const testGroupInitialForm = {
|
||||||
TestGrpID: '',
|
TestGrpID: '',
|
||||||
TestSiteID: '',
|
TestSiteID: '',
|
||||||
Members: [],
|
Members: []
|
||||||
}
|
};
|
||||||
|
|
||||||
export const refNumInitialForm = {
|
export const refNumInitialForm = {
|
||||||
RefNumID: '',
|
RefNumID: '',
|
||||||
@ -319,12 +319,12 @@ export const testDefaultErrors = {
|
|||||||
|
|
||||||
export const testCalDefaultErrors = {
|
export const testCalDefaultErrors = {
|
||||||
FormulaInput: null,
|
FormulaInput: null,
|
||||||
FormulaCode: null,
|
FormulaCode: null
|
||||||
};
|
};
|
||||||
|
|
||||||
export const testGroupDefaultErrors = {
|
export const testGroupDefaultErrors = {
|
||||||
Members: null,
|
Members: null
|
||||||
}
|
};
|
||||||
|
|
||||||
export const refNumDefaultErrors = {
|
export const refNumDefaultErrors = {
|
||||||
AgeStart: null,
|
AgeStart: null,
|
||||||
@ -479,7 +479,9 @@ export const testFormFields = [
|
|||||||
key: 'Factor',
|
key: 'Factor',
|
||||||
label: 'Factor',
|
label: 'Factor',
|
||||||
required: false,
|
required: false,
|
||||||
type: 'number'
|
type: 'number',
|
||||||
|
validateOn: ['input'],
|
||||||
|
triggerFields: ['Unit2']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -490,7 +492,8 @@ export const testFormFields = [
|
|||||||
key: 'Unit2',
|
key: 'Unit2',
|
||||||
label: 'Unit 2',
|
label: 'Unit 2',
|
||||||
required: false,
|
required: false,
|
||||||
type: 'text'
|
type: 'text',
|
||||||
|
validateOn: ['input']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'Decimal',
|
key: 'Decimal',
|
||||||
@ -571,7 +574,7 @@ export const testFormFields = [
|
|||||||
label: 'Sequence on Report',
|
label: 'Sequence on Report',
|
||||||
required: false,
|
required: false,
|
||||||
type: 'text'
|
type: 'text'
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -584,8 +587,8 @@ export const testFormFields = [
|
|||||||
type: 'toggle',
|
type: 'toggle',
|
||||||
optionsToggle: [
|
optionsToggle: [
|
||||||
{ value: 0, label: 'Disabled' },
|
{ value: 0, label: 'Disabled' },
|
||||||
{ value: 1, label: 'Enabled' },
|
{ value: 1, label: 'Enabled' }
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'isVisibleRpt',
|
key: 'isVisibleRpt',
|
||||||
@ -594,8 +597,8 @@ export const testFormFields = [
|
|||||||
type: 'toggle',
|
type: 'toggle',
|
||||||
optionsToggle: [
|
optionsToggle: [
|
||||||
{ value: 0, label: 'Disabled' },
|
{ value: 0, label: 'Disabled' },
|
||||||
{ value: 1, label: 'Enabled' },
|
{ value: 1, label: 'Enabled' }
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -609,8 +612,8 @@ export const testFormFields = [
|
|||||||
type: 'toggle',
|
type: 'toggle',
|
||||||
optionsToggle: [
|
optionsToggle: [
|
||||||
{ value: 0, label: 'Disabled' },
|
{ value: 0, label: 'Disabled' },
|
||||||
{ value: 1, label: 'Enabled' },
|
{ value: 1, label: 'Enabled' }
|
||||||
],
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'isRequestable',
|
key: 'isRequestable',
|
||||||
@ -619,14 +622,14 @@ export const testFormFields = [
|
|||||||
type: 'toggle',
|
type: 'toggle',
|
||||||
optionsToggle: [
|
optionsToggle: [
|
||||||
{ value: 0, label: 'Disabled' },
|
{ value: 0, label: 'Disabled' },
|
||||||
{ value: 1, label: 'Enabled' },
|
{ value: 1, label: 'Enabled' }
|
||||||
],
|
],
|
||||||
fullWidth: false
|
fullWidth: false
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
export const testCalFormFields = [
|
export const testCalFormFields = [
|
||||||
@ -679,7 +682,7 @@ export const testGroupFormFields = [
|
|||||||
validateOn: ['input']
|
validateOn: ['input']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@ -764,7 +767,7 @@ export const refNumFormFields = [
|
|||||||
label: 'Range Type',
|
label: 'Range Type',
|
||||||
required: false,
|
required: false,
|
||||||
type: 'select',
|
type: 'select',
|
||||||
optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/range_type`,
|
optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/range_type`
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -1049,7 +1052,14 @@ export function getTestFormActions(handlers) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildTestPayload({ mainForm, activeFormStates, testType, refNumData, refTxtData, mapData }) {
|
export function buildTestPayload({
|
||||||
|
mainForm,
|
||||||
|
activeFormStates,
|
||||||
|
testType,
|
||||||
|
refNumData,
|
||||||
|
refTxtData,
|
||||||
|
mapData
|
||||||
|
}) {
|
||||||
let payload = {
|
let payload = {
|
||||||
...mainForm
|
...mainForm
|
||||||
};
|
};
|
||||||
@ -1059,22 +1069,24 @@ export function buildTestPayload({ mainForm, activeFormStates, testType, refNumD
|
|||||||
|
|
||||||
if (key === 'refNum' && refNumData?.length > 0) {
|
if (key === 'refNum' && refNumData?.length > 0) {
|
||||||
// payload[key] = refNumData;
|
// payload[key] = refNumData;
|
||||||
payload.refnum = refNumData.map(row => ({
|
payload.refnum = refNumData.map((row) => ({
|
||||||
...row,
|
...row,
|
||||||
AgeStart: toDays(row.AgeStart),
|
AgeStart: toDays(row.AgeStart),
|
||||||
AgeEnd: toDays(row.AgeEnd),
|
AgeEnd: toDays(row.AgeEnd)
|
||||||
}))
|
}));
|
||||||
} else if (key === 'refTxt' && refTxtData?.length > 0) {
|
} else if (key === 'refTxt' && refTxtData?.length > 0) {
|
||||||
// payload[key] = refTxtData;
|
// payload[key] = refTxtData;
|
||||||
payload.reftxt = refTxtData.map(row => ({
|
payload.reftxt = refTxtData.map((row) => ({
|
||||||
...row,
|
...row,
|
||||||
AgeStart: toDays(row.AgeStart),
|
AgeStart: toDays(row.AgeStart),
|
||||||
AgeEnd: toDays(row.AgeEnd),
|
AgeEnd: toDays(row.AgeEnd)
|
||||||
}))
|
}));
|
||||||
} else if(key === 'group' && state.form?.Members?.length > 0) {
|
} else if (key === 'group' && state.form?.Members?.length > 0) {
|
||||||
payload.testdefgrp = {
|
payload.testdefgrp = {
|
||||||
...state.form,
|
...state.form,
|
||||||
Members: state.form?.Members?.filter((m) => m.value).map((m) => ({ TestSiteID: Number(m.value) }))
|
Members: state.form?.Members?.filter((m) => m.value).map((m) => ({
|
||||||
|
TestSiteID: Number(m.value)
|
||||||
|
}))
|
||||||
};
|
};
|
||||||
} else if (key === 'map' && mapData?.length > 0) {
|
} else if (key === 'map' && mapData?.length > 0) {
|
||||||
payload.testmap = mapData;
|
payload.testmap = mapData;
|
||||||
@ -1082,7 +1094,7 @@ export function buildTestPayload({ mainForm, activeFormStates, testType, refNumD
|
|||||||
payload.testdefcal = {
|
payload.testdefcal = {
|
||||||
...state.form,
|
...state.form,
|
||||||
FormulaInput: state.form?.FormulaInput?.map((m) => ({ TestSiteID: Number(m.testid) }))
|
FormulaInput: state.form?.FormulaInput?.map((m) => ({ TestSiteID: Number(m.testid) }))
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
// else if ((key === 'cal' || key === 'map') && state?.form) {
|
// else if ((key === 'cal' || key === 'map') && state?.form) {
|
||||||
// payload[key] = {
|
// payload[key] = {
|
||||||
|
|||||||
@ -347,13 +347,13 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$effect(() => {
|
// $effect(() => {
|
||||||
if (formState.form.Factor && !formState.form.Unit2) {
|
// if (formState.form.Factor && !formState.form.Unit2) {
|
||||||
formState.errors.Unit2 = 'Required';
|
// formState.errors.Unit2 = 'Required';
|
||||||
} else {
|
// } else {
|
||||||
formState.errors.Unit2 = null;
|
// formState.errors.Unit2 = null;
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const allColumns = formFields.flatMap((section) =>
|
const allColumns = formFields.flatMap((section) =>
|
||||||
|
|||||||
@ -451,6 +451,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// $effect(() => {
|
||||||
|
// if (formState.form.Factor && !formState.form.Unit2) {
|
||||||
|
// formState.errors.Unit2 = 'Required';
|
||||||
|
// } else {
|
||||||
|
// formState.errors.Unit2 = null;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const refType = formState.form.RefType;
|
const refType = formState.form.RefType;
|
||||||
if (refType === 'RANGE' || refType === 'THOLD') {
|
if (refType === 'RANGE' || refType === 'THOLD') {
|
||||||
|
|||||||
@ -118,6 +118,7 @@
|
|||||||
options,
|
options,
|
||||||
optionsToggle,
|
optionsToggle,
|
||||||
validateOn,
|
validateOn,
|
||||||
|
triggerFields,
|
||||||
dependsOn,
|
dependsOn,
|
||||||
endpointParamKey,
|
endpointParamKey,
|
||||||
valueKey,
|
valueKey,
|
||||||
@ -186,6 +187,9 @@
|
|||||||
oninput={() => {
|
oninput={() => {
|
||||||
if (validateOn?.includes('input')) {
|
if (validateOn?.includes('input')) {
|
||||||
formState.validateField(key, formState.form[key], false);
|
formState.validateField(key, formState.form[key], false);
|
||||||
|
for (const related of (triggerFields ?? [])) {
|
||||||
|
formState.validateField(related, formState.form[related], false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onblur={() => {
|
onblur={() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user