diff --git a/api/visa.ts b/api/visa.ts index 0a6f9e4..357cecd 100644 --- a/api/visa.ts +++ b/api/visa.ts @@ -10,6 +10,7 @@ interface VisaItem { } interface VisaTypeCategory { + title?: string; items: VisaItem[]; } @@ -433,7 +434,7 @@ function getFallbackVisaData(): VisaData { tagline: "35+ years of excellence in UK visa consulting.", visaTypes: [ { - category: "Student & Work", + title: "Student & Work", items: [ { title: "Student Visa", @@ -448,7 +449,7 @@ function getFallbackVisaData(): VisaData { ], }, { - category: "Family & Other", + title: "Family & Other", items: [ { title: "Skilled Worker Visa", @@ -601,7 +602,7 @@ function getFallbackVisaData(): VisaData { tagline: "Your pathway to a better life in Canada starts here.", visaTypes: [ { - category: "Study & Work", + title: "Study & Work", items: [ { title: "Study Permit", @@ -614,7 +615,7 @@ function getFallbackVisaData(): VisaData { ], }, { - category: "Immigration & Family", + title: "Immigration & Family", items: [ { title: "Express Entry", diff --git a/app/visa/[slug]/VisaDetail.tsx b/app/visa/[slug]/VisaDetail.tsx index bd85ea2..fe23f77 100644 --- a/app/visa/[slug]/VisaDetail.tsx +++ b/app/visa/[slug]/VisaDetail.tsx @@ -7,24 +7,33 @@ interface VisaDetailProps { } export default function VisaDetail({ country }: VisaDetailProps) { + // 1. Kiểm tra an toàn (Null Check) + // Vì detailedView có kiểu là 'DetailedView | undefined', ta phải chắc chắn nó tồn tại + if (!country || !country.detailedView) { + return ( +
+

Đang tải dữ liệu...

+
+ ); + } + const { name: rootName, detailedView } = country; + + // 2. Bóc tách dữ liệu sau khi đã kiểm tra detailedView tồn tại const { activeCountry: countryData, relatedCountries, contactInfo, - } = country.detailedView; + } = detailedView; return ( <> - {/* Breadcrumb-Wrapper Section Start */} - {/* Country-details Section Start */}
- {/* Main Content */}
@@ -38,33 +47,19 @@ export default function VisaDetail({ country }: VisaDetailProps) { {/* Visa Types */}
- {/* Render mảng đầu tiên (index 0) */} - {countryData.visaTypes?.[0] && ( -
- {countryData.visaTypes[0].items.map( - (item: any, itemIdx: number) => ( -
-
{item.title}
-

{item.description}

-
- ), - )} + {countryData.visaTypes?.map((type: any, idx: number) => ( +
+ {type.items.map((item: any, itemIdx: number) => ( +
+
{item.title}
+

{item.description}

+
+ ))}
- )} - - {/* Render mảng thứ hai (index 1) */} - {countryData.visaTypes?.[1] && ( -
- {countryData.visaTypes[1].items.map( - (item: any, itemIdx: number) => ( -
-
{item.title}
-

{item.description}

-
- ), - )} -
- )} + ))}
{/* Visa Process */} @@ -102,49 +97,6 @@ export default function VisaDetail({ country }: VisaDetailProps) { )}
)} - - {/* Visa Categories */} - {countryData.visaCategories && ( - <> -

- {countryData.visaCategories.title} -

- - {countryData.visaCategories.steps.map( - (subGroup: string[], groupIdx: number) => ( -
    - {subGroup.map((category: string, idx: number) => ( -
  • - - {category} -
  • - ))} -
- ), - )} - - )} - - {/* Service Options */} - {countryData.visaService && ( - <> -

- {countryData.visaService.title} -

-
    - {countryData.visaService.steps.map( - (process: any, idx: number) => ( -
  • - - {process.number}. {process.title} - - - {process.description} -
  • - ), - )} -
- - )}
@@ -152,7 +104,7 @@ export default function VisaDetail({ country }: VisaDetailProps) { {/* Sidebar */}
- {relatedCountries.map((relCountry: any, idx: number) => ( + {relatedCountries?.map((relCountry: any, idx: number) => (
@@ -178,8 +130,6 @@ export default function VisaDetail({ country }: VisaDetailProps) {

{contactInfo.sectionTitle}

{contactInfo.helpText}

- - {/* Phone */}
@@ -187,13 +137,15 @@ export default function VisaDetail({ country }: VisaDetailProps) {
{contactInfo.phone.label}:
- + {contactInfo.phone.value}
- {/* Email */}