i18n: fixing form validaton messages
This commit is contained in:
@@ -26,7 +26,7 @@ export type State = {
|
|||||||
*/
|
*/
|
||||||
const FormSchema = (t:IntlTemplateFn) => z.object({
|
const FormSchema = (t:IntlTemplateFn) => z.object({
|
||||||
_id: z.string(),
|
_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(),
|
billNotes: z.string(),
|
||||||
payedAmount: z.string().nullable().transform((val, ctx) => {
|
payedAmount: z.string().nullable().transform((val, ctx) => {
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
|
|||||||
if (isNaN(parsed)) {
|
if (isNaN(parsed)) {
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: t("validation.not-a-number"),
|
message: t("not-a-number"),
|
||||||
});
|
});
|
||||||
|
|
||||||
// This is a special symbol you can use to
|
// This is a special symbol you can use to
|
||||||
@@ -52,7 +52,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
|
|||||||
if (parsed < 0) {
|
if (parsed < 0) {
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: t("validation.negative-number")
|
message: t("negative-number")
|
||||||
});
|
});
|
||||||
|
|
||||||
// This is a special symbol you can use to
|
// 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 { id: userId } = user;
|
||||||
|
|
||||||
const t = await getTranslations("bill-edit-form");
|
const t = await getTranslations("bill-edit-form.validation");
|
||||||
|
|
||||||
// FormSchema
|
// FormSchema
|
||||||
const validatedFields = FormSchema(t)
|
const validatedFields = FormSchema(t)
|
||||||
@@ -131,7 +131,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
|
|||||||
console.log("updateBill.validation-error");
|
console.log("updateBill.validation-error");
|
||||||
return({
|
return({
|
||||||
errors: validatedFields.error.flatten().fieldErrors,
|
errors: validatedFields.error.flatten().fieldErrors,
|
||||||
message: t("validation.form-error-message"),
|
message: t("form-error-message"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export type State = {
|
|||||||
*/
|
*/
|
||||||
const FormSchema = (t:IntlTemplateFn) => z.object({
|
const FormSchema = (t:IntlTemplateFn) => z.object({
|
||||||
_id: z.string(),
|
_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(),
|
locationNotes: z.string(),
|
||||||
})
|
})
|
||||||
// dont include the _id field in the response
|
// dont include the _id field in the response
|
||||||
@@ -42,7 +42,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
|
|||||||
|
|
||||||
noStore();
|
noStore();
|
||||||
|
|
||||||
const t = await getTranslations("location-edit-form");
|
const t = await getTranslations("location-edit-form.validation");
|
||||||
|
|
||||||
const validatedFields = FormSchema(t).safeParse({
|
const validatedFields = FormSchema(t).safeParse({
|
||||||
locationName: formData.get('locationName'),
|
locationName: formData.get('locationName'),
|
||||||
|
|||||||
Reference in New Issue
Block a user