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:
@@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user