i18n: fixing form validaton messages

This commit is contained in:
2024-02-17 10:17:17 +01:00
parent fc6243f9b8
commit f7b92931a9
2 changed files with 7 additions and 7 deletions

View File

@@ -26,7 +26,7 @@ export type State = {
*/
const FormSchema = (t:IntlTemplateFn) => z.object({
_id: z.string(),
billName: z.coerce.string().min(1, t("validation.bill-name-required")),
billName: z.coerce.string().min(1, t("bill-name-required")),
billNotes: z.string(),
payedAmount: z.string().nullable().transform((val, ctx) => {
@@ -39,7 +39,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
if (isNaN(parsed)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: t("validation.not-a-number"),
message: t("not-a-number"),
});
// This is a special symbol you can use to
@@ -52,7 +52,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
if (parsed < 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: t("validation.negative-number")
message: t("negative-number")
});
// This is a special symbol you can use to
@@ -115,7 +115,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
const { id: userId } = user;
const t = await getTranslations("bill-edit-form");
const t = await getTranslations("bill-edit-form.validation");
// FormSchema
const validatedFields = FormSchema(t)
@@ -131,7 +131,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
console.log("updateBill.validation-error");
return({
errors: validatedFields.error.flatten().fieldErrors,
message: t("validation.form-error-message"),
message: t("form-error-message"),
});
}

View File

@@ -25,7 +25,7 @@ export type State = {
*/
const FormSchema = (t:IntlTemplateFn) => z.object({
_id: z.string(),
locationName: z.coerce.string().min(1, t("validation.location-name-required")),
locationName: z.coerce.string().min(1, t("location-name-required")),
locationNotes: z.string(),
})
// dont include the _id field in the response
@@ -42,7 +42,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
noStore();
const t = await getTranslations("location-edit-form");
const t = await getTranslations("location-edit-form.validation");
const validatedFields = FormSchema(t).safeParse({
locationName: formData.get('locationName'),