-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(refactor) Refactor conditions form validation logic #1881
(refactor) Refactor conditions form validation logic #1881
Conversation
Size Change: -77 B (0%) Total Size: 11.1 MB ℹ️ View Unchanged
|
35611f6
to
5effb23
Compare
5effb23
to
8beaa11
Compare
8beaa11
to
cc527f7
Compare
const createSchema = (formContext: 'creating' | 'editing', t: TFunction) => { | ||
const isCreating = formContext === 'creating'; | ||
|
||
export type ConditionSchema = z.infer<typeof schema>; | ||
const clinicalStatusValidation = z.string().refine((clinicalStatus) => !isCreating || !!clinicalStatus, { | ||
message: t('clinicalStatusRequired', 'A clinical status is required'), | ||
}); | ||
|
||
const conditionNameValidation = z.string().refine((conditionName) => !isCreating || !!conditionName, { | ||
message: t('conditionRequired', 'A condition is required'), | ||
}); | ||
|
||
return z.object({ | ||
abatementDateTime: z.date().optional().nullable(), | ||
clinicalStatus: clinicalStatusValidation, | ||
conditionName: conditionNameValidation, | ||
onsetDateTime: z.date().nullable(), | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the key change. I've moved the validation logic into the Zod schema declaration. Previously, error handling was handled manually using the setError
function. Following this change, errors are handled automatically based on the rules described in the schema.
@ibacher looks good? |
Thanks! |
Requirements
Summary
This PR refactors the conditions form's validation logic to use the zod schema as the source of truth instead of manual validation logic in the
onSubmit
handler.Screenshots
Related Issue
Other