forked from UKSOURCE/hailearning.edu.vn
feat: add country API integration and image fallback component
This commit is contained in:
@@ -100,6 +100,20 @@ export interface ServicePageData {
|
||||
reviews: ReviewSection;
|
||||
}
|
||||
|
||||
export interface Country {
|
||||
id: number;
|
||||
name: string;
|
||||
slug: string;
|
||||
mainImage: string;
|
||||
icon: string;
|
||||
services: string[];
|
||||
}
|
||||
|
||||
export interface CountryApiResponse {
|
||||
success: boolean;
|
||||
data: Country[];
|
||||
}
|
||||
|
||||
/* =======================
|
||||
Utils
|
||||
======================= */
|
||||
@@ -230,6 +244,43 @@ export const fetchServiceBySlug = async (slug: string): Promise<any> => {
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchCountries = async (): Promise<Country[]> => {
|
||||
try {
|
||||
const apiUrl = getApiUrl();
|
||||
const endpoint = `${apiUrl}/api/visa/country`;
|
||||
|
||||
console.log("Fetching countries from endpoint:", endpoint);
|
||||
|
||||
const response = await fetch(endpoint, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
console.log("Countries API response status:", response.status);
|
||||
|
||||
if (!response.ok) {
|
||||
console.error("Countries API failed, using fallback data");
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const result = (await response.json()) as CountryApiResponse;
|
||||
|
||||
if (!result.success) {
|
||||
throw new Error("Countries API returned success=false");
|
||||
}
|
||||
|
||||
console.log("Countries data received successfully");
|
||||
return result.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching countries:", error);
|
||||
console.log("Using fallback countries data");
|
||||
return getFallbackCountries();
|
||||
}
|
||||
};
|
||||
|
||||
/* =======================
|
||||
Fallback Data
|
||||
======================= */
|
||||
@@ -560,3 +611,70 @@ export const getFallbackServicePageData = (): ServicePageData => ({
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
export const getFallbackCountries = (): Country[] => [
|
||||
{
|
||||
id: 1,
|
||||
name: "Canada",
|
||||
slug: "canada",
|
||||
mainImage: "_images/default.jpg",
|
||||
icon: "img/home-3/choose-us/icon-1.png",
|
||||
services: ["Immigration Appeal", "Permanent Residency", "Study Visa"],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "Australia",
|
||||
slug: "australia",
|
||||
mainImage: "_images/default.jpg",
|
||||
icon: "img/home-3/choose-us/icon-2.png",
|
||||
services: ["Work Visa", "Permanent Residency", "Student Visa"],
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: "United Kingdom",
|
||||
slug: "united-kingdom",
|
||||
mainImage: "_images/default.jpg",
|
||||
icon: "img/home-3/choose-us/icon-3.png",
|
||||
services: ["Study Visa", "Work Visa", "Family Visa"],
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: "United States",
|
||||
slug: "united-states",
|
||||
mainImage: "_images/default.jpg",
|
||||
icon: "img/home-3/choose-us/icon-1.png",
|
||||
services: ["Immigration Appeal", "Work Visa", "Student Visa"],
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
name: "Germany",
|
||||
slug: "germany",
|
||||
mainImage: "_images/default.jpg",
|
||||
icon: "img/home-3/choose-us/icon-2.png",
|
||||
services: ["Study Visa", "Work Visa", "Permanent Residency"],
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
name: "France",
|
||||
slug: "france",
|
||||
mainImage: "_images/default.jpg",
|
||||
icon: "img/home-3/choose-us/icon-3.png",
|
||||
services: ["Student Visa", "Work Visa", "Family Visa"],
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
name: "New Zealand",
|
||||
slug: "new-zealand",
|
||||
mainImage: "_images/default.jpg",
|
||||
icon: "img/home-3/choose-us/icon-1.png",
|
||||
services: ["Work Visa", "Permanent Residency", "Study Visa"],
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
name: "Japan",
|
||||
slug: "japan",
|
||||
mainImage: "_images/default.jpg",
|
||||
icon: "img/home-3/choose-us/icon-2.png",
|
||||
services: ["Work Visa", "Student Visa", "Business Visa"],
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user