fix after meeting 10/04/2026

1.fix datetime patient
2.fix duplicate email client validation
3.fix email2 duplicate
This commit is contained in:
faiztyanirh 2026-04-11 10:58:45 +07:00
parent 80d59f3120
commit 0c65d607d2
4 changed files with 33 additions and 10 deletions

View File

@ -25,7 +25,25 @@ export function usePatientForm(formState, patientSchema) {
return status === "success" && data === false ? false : true;
},
{ message: "Patient ID already used" }
)
),
EmailAddress1: patientSchema.shape.EmailAddress1.refine(
async (value) => {
if (!value) return false;
const res = await fetch(`${API.BASE_URL}${API.CHECK}?EmailAddress1=${value}`);
const { status, data } = await res.json();
return status === "success" && data === false ? false : true;
},
{ message: "Email address already used" }
),
EmailAddress2: patientSchema.shape.EmailAddress2.refine(
async (value) => {
if (!value) return false;
const res = await fetch(`${API.BASE_URL}${API.CHECK}?EmailAddress1=${value}`);
const { status, data } = await res.json();
return status === "success" && data === false ? false : true;
},
{ message: "Email address already used" }
),
});
const partial = asyncSchema.pick({ [field]: true });

View File

@ -114,10 +114,10 @@
tempMap,
});
console.log(payload)
// const result = await formState.save(masterDetail.mode, payload);
const result = await formState.save(masterDetail.mode, payload);
// toast('Test Map Created!');
// masterDetail?.exitForm(true);
toast('Test Map Created!');
masterDetail?.exitForm(true);
}
const primaryAction = $derived({

View File

@ -14,7 +14,10 @@ export const patientSchema = z.object({
EmailAddress2: 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"),
MobilePhone: z.string().max(14, "Max 14 chars").regex(/^$|^[0-9]+$/, "Can only contain numbers"),
TimeOfDeath: z.string().optional(),
TimeOfDeath: z.string().optional().refine(
(date) => new Date(date) <= new Date(),
"Cannot exceed today's date"
),
});
export const patientInitialForm = {
@ -69,6 +72,7 @@ export const patientDefaultErrors = {
PatIdt_Identifier: null,
Phone: null,
MobilePhone: null,
TimeOfDeath: null,
};
export const patientFormFields = [
@ -259,7 +263,7 @@ export const patientFormFields = [
{
type: "row",
columns: [
{ key: "EmailAddress2", label: "Email Address 2", required: false, type: "email", validateOn: ["input"] },
{ key: "EmailAddress2", label: "Email Address 2", required: false, type: "email", validateOn: ["input", "blur"] },
{ key: "MobilePhone", label: "Mobile Phone", required: false, type: "text", validateOn: ["input"] },
]
},
@ -277,7 +281,7 @@ export const patientFormFields = [
optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/death_indicator`,
defaultValue: 'N'
},
{ key: "TimeOfDeath", label: "Time of Death", required: false, type: "datetime" }
{ key: "TimeOfDeath", label: "Time of Death", required: false, type: "datetime", validateOn: ["input"] }
]
},
{ key: "LinkTo", label: "Link To", required: false, type: "linkto" }

View File

@ -114,7 +114,7 @@
}}
onblur={() => {
if (validateOn?.includes("blur")) {
formState.validateField(key, formState.form[key], false);
validateFieldAsync(key, mode, originalData?.[key]);
}
}}
/>
@ -147,12 +147,13 @@
<ReusableCalendarTimepicker
bind:value={formState.form[key]}
disabled={key === "TimeOfDeath" && isDeathDateDisabled}
onValueChange={(val) => {
parentFunction={(val) => {
formState.form[key] = val;
if (validateOn?.includes("input")) {
formState.validateField(key, formState.form[key], false);
formState.validateField(key, val, false);
}
}}
/>
{:else if type === "textarea"}
<textarea