Add footer API integration

This commit is contained in:
2026-02-05 15:13:51 +07:00
parent 857d250435
commit a85182ff20
8 changed files with 225 additions and 118 deletions

62
api/footerApi.ts Normal file
View File

@@ -0,0 +1,62 @@
/**
* Footer API Functions
* Fetch footer data from external API
*/
const getApiUrl = (): string => {
return process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001";
};
export interface FooterData {
top: {
bgImage: string;
phone: {
display: string;
href: string;
};
address: string;
logo: {
src: string;
alt: string;
href: string;
};
menuLinks: Array<{
label: string;
href: string;
}>;
socialLinks: Array<{
icon: string;
href: string;
}>;
};
bottom: {
copyright: {
text: string;
brand: string;
rights: string;
};
menuLinks: Array<{
label: string;
href: string;
}>;
};
}
export const footerApi = {
// Get footer data
getFooter: async (): Promise<FooterData> => {
try {
const apiUrl = getApiUrl();
const response = await fetch(`${apiUrl}/api/footer`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error("Error fetching footer data:", error);
// Fallback to static data if API fails
const fallbackData = await import("../app/components/layout/Footer/footer.json");
return fallbackData.default as FooterData;
}
},
};