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.
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Calendar } from "lucide-react";
|
import { Calendar } from "lucide-react";
|
||||||
import { useTranslation } from "@/i18n/use-translation";
|
import { useTranslation } from "@/i18n/use-translation";
|
||||||
|
import { translate } from "@/i18n/messages";
|
||||||
import { useAppStore } from "@/store/app-store";
|
import { useAppStore } from "@/store/app-store";
|
||||||
import { useTelegramAuth } from "@/hooks/use-telegram-auth";
|
import { useTelegramAuth } from "@/hooks/use-telegram-auth";
|
||||||
import { fetchDuties, AccessDeniedError } from "@/lib/api";
|
import { fetchDuties, AccessDeniedError } from "@/lib/api";
|
||||||
@@ -66,7 +67,6 @@ export function CurrentDutyView({ onBack, openedFromPin = false }: CurrentDutyVi
|
|||||||
|
|
||||||
const loadTodayDuties = useCallback(
|
const loadTodayDuties = useCallback(
|
||||||
async (signal?: AbortSignal | null) => {
|
async (signal?: AbortSignal | null) => {
|
||||||
setLoading();
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const from = localDateString(today);
|
const from = localDateString(today);
|
||||||
const to = from;
|
const to = from;
|
||||||
@@ -89,13 +89,13 @@ export function CurrentDutyView({ onBack, openedFromPin = false }: CurrentDutyVi
|
|||||||
setDuty(null);
|
setDuty(null);
|
||||||
setRemaining(null);
|
setRemaining(null);
|
||||||
} else {
|
} else {
|
||||||
setError(t("error_generic"));
|
setError(translate(lang, "error_generic"));
|
||||||
setDuty(null);
|
setDuty(null);
|
||||||
setRemaining(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.
|
// 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) {
|
if (isError) {
|
||||||
const handleRetry = () => {
|
const handleRetry = () => {
|
||||||
triggerHapticLight();
|
triggerHapticLight();
|
||||||
|
setLoading();
|
||||||
loadTodayDuties();
|
loadTodayDuties();
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user