From 45c65e302528d237f309df110776012e2aa39298 Mon Sep 17 00:00:00 2001 From: Nikolay Tatarinov Date: Fri, 6 Mar 2026 17:59:32 +0300 Subject: [PATCH] fix: update error handling in CurrentDutyView component - Replaced direct translation function with a new `translate` utility for error messages, improving localization support. - Removed unnecessary loading state call during duty loading to streamline the process. - Updated dependencies in the loadTodayDuties function to enhance clarity and maintainability. --- .../src/components/current-duty/CurrentDutyView.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/webapp-next/src/components/current-duty/CurrentDutyView.tsx b/webapp-next/src/components/current-duty/CurrentDutyView.tsx index 133970b..17a8253 100644 --- a/webapp-next/src/components/current-duty/CurrentDutyView.tsx +++ b/webapp-next/src/components/current-duty/CurrentDutyView.tsx @@ -10,6 +10,7 @@ import { useEffect, useState, useCallback } from "react"; import { Calendar } from "lucide-react"; import { useTranslation } from "@/i18n/use-translation"; +import { translate } from "@/i18n/messages"; import { useAppStore } from "@/store/app-store"; import { useTelegramAuth } from "@/hooks/use-telegram-auth"; import { fetchDuties, AccessDeniedError } from "@/lib/api"; @@ -66,7 +67,6 @@ export function CurrentDutyView({ onBack, openedFromPin = false }: CurrentDutyVi const loadTodayDuties = useCallback( async (signal?: AbortSignal | null) => { - setLoading(); const today = new Date(); const from = localDateString(today); const to = from; @@ -89,13 +89,13 @@ export function CurrentDutyView({ onBack, openedFromPin = false }: CurrentDutyVi setDuty(null); setRemaining(null); } else { - setError(t("error_generic")); + setError(translate(lang, "error_generic")); setDuty(null); setRemaining(null); } } }, - [initDataRaw, lang, t, setLoading, setSuccess, setAccessDenied, setError] + [initDataRaw, lang, setSuccess, setAccessDenied, setError] ); // Fetch today's duties on mount; abort on unmount to avoid setState after unmount. @@ -191,6 +191,7 @@ export function CurrentDutyView({ onBack, openedFromPin = false }: CurrentDutyVi if (isError) { const handleRetry = () => { triggerHapticLight(); + setLoading(); loadTodayDuties(); }; return (