How to get an awaited validation schema before passing to an action ? #111
-
First of all thanks for this great library! I am using translated error messages in my zod Schema. To make my schema shareable between client and server I pass the translation function to a getValidationSchema function. To get my translations on the server side I first have to await my getTranslations function. I tried making a wrapper to do this, but got stuck and I am confused how to use the action after I got my shema in my async function If someone know how I could do this please let me know. This is how my server action looks like type EmailFormData = {
newEmail: string
confirmEmail: string
}
export type FormState = ZodIssue[] | EmailFormData
export const onSubmitEmailAction = async (prevData: FormState, actionData: EmailFormData) => {
const { t } = await getTranslations('nl', 'myProfile')
const schema = getValidationSchema(t)
// how to use the action from the safe-action library here ?
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
I am facing the same issue. We use the same approach to translate zod validation errors rather than Edit: export const signIn = guestActionClient.
schema(
async () => {
const t= await getTranslations('validation')
return signInSchema(t)
})
.action(
...
) |
Beta Was this translation helpful? Give feedback.
-
Implemented this feature in v7.0.0-next.51, and added a i18n recipe on the website too, to explain how this works in detail. |
Beta Was this translation helpful? Give feedback.
Implemented this feature in v7.0.0-next.51, and added a i18n recipe on the website too, to explain how this works in detail.
This will hopefully solve this issue and enable support for i18n solutions, but if you still experience problems feel free to leave a comment down here and I'll reopen this discussion, thanks!