refactor(TenderDetails): enhance country flag handling and validation

- Updated the TenderDetails component to validate country codes using a new utility function, isValidAlpha2CountryCode.
- Modified the useGetFlagQuery hook to accept an options parameter for conditional fetching based on the validity of the country code.
- Improved the rendering logic for the country flag to ensure it only displays when valid flag data is available.
This commit is contained in:
AmirReza Jamali
2026-04-13 08:16:21 +03:30
parent 50db71843b
commit 76cb29d31e
3 changed files with 20 additions and 8 deletions
+5 -1
View File
@@ -3,7 +3,10 @@ import { flagsService } from "@/lib/api/services/flags-service";
import { useQuery } from "@tanstack/react-query";
import { useMemo } from "react";
export const useGetFlagQuery = (countryCode: string) => {
export const useGetFlagQuery = (
countryCode: string,
options?: { enabled?: boolean },
) => {
const queryKey = useMemo(
() => [API_ENDPOINTS.FLAGS(countryCode)],
[countryCode],
@@ -12,5 +15,6 @@ export const useGetFlagQuery = (countryCode: string) => {
return useQuery({
queryKey,
queryFn: () => flagsService.getCountryFlag(countryCode),
enabled: options?.enabled ?? true,
});
};