fix(i18n): localize API error messages by code (no more raw English)
Error toasts surfaced the raw English backend message. Added an errors namespace (fa/ar/en) keyed by error code + a useApiError() resolver that maps ApiClientError.code to the localized message (fallback to a localized generic). Wired into menu, tables, demo banner, and subscription checkout; hardened getErrorMessage so it never returns the raw backend message. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
import { useState } from "react";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { Sparkles, Loader2 } from "lucide-react";
|
||||
import { ApiClientError, apiPost } from "@/lib/api/client";
|
||||
import { apiPost } from "@/lib/api/client";
|
||||
import { notify } from "@/lib/notify";
|
||||
import { useApiError } from "@/lib/use-api-error";
|
||||
import { useAuthStore } from "@/lib/stores/auth.store";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -27,6 +28,7 @@ export function DemoDataBanner({ invalidateKeys, className }: Props) {
|
||||
const cafeId = useAuthStore((s) => s.user?.cafeId);
|
||||
const role = useAuthStore((s) => s.user?.role);
|
||||
const qc = useQueryClient();
|
||||
const apiError = useApiError();
|
||||
const [done, setDone] = useState(false);
|
||||
const [summary, setSummary] = useState<DemoSeedResult | null>(null);
|
||||
|
||||
@@ -41,11 +43,7 @@ export function DemoDataBanner({ invalidateKeys, className }: Props) {
|
||||
}
|
||||
},
|
||||
onError: (err) => {
|
||||
notify.error(
|
||||
err instanceof ApiClientError
|
||||
? err.message
|
||||
: "افزودن دادههای نمونه ناموفق بود. دوباره تلاش کنید."
|
||||
);
|
||||
notify.error(apiError(err));
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user