Skip to content

Commit

Permalink
feat: retrieve headquarter and full category on footer
Browse files Browse the repository at this point in the history
  • Loading branch information
lcaohoanq committed Dec 11, 2024
1 parent 0306399 commit 511f28f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
11 changes: 3 additions & 8 deletions client/src/components/Footer/CategoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type CategoryResponse = {
updated_at: string
}

type ApiResponse<T> = {
export type ApiResponse<T> = {
message: string
data: T
status_code: number
Expand Down Expand Up @@ -70,13 +70,8 @@ function CategoryList() {
>
{category.name}
</Typography>
<ul className='list-disc list-inside text-gray-600'>
{category.subcategories.map((subcategory) => (
<li key={subcategory.id} className='mb-1'>
{subcategory.name}
</li>
))}
</ul>

<p className='text-gray-700'>{category.subcategories.map((subcategory) => subcategory.name).join(' | ')}</p>
</div>
))}
</div>
Expand Down
36 changes: 33 additions & 3 deletions client/src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
import CategoryList from './CategoryList'
import { useEffect, useState } from 'react'
import CategoryList, { ApiResponse } from './CategoryList'
import axios from 'axios'
import { Link } from '@mui/material'

type HeadQuarter = {
id: number
region: string
domain_url: string
created_at: string
updated_at: string
}

export default function Footer() {
const [headQuarters, setHeadQuarters] = useState<HeadQuarter[]>([])

useEffect(() => {
const fetchHeadQuarters = async () => {
try {
const response = await axios.get<ApiResponse<HeadQuarter[]>>('http://localhost:8080/api/v1/headquarters')
setHeadQuarters(response.data.data)
} catch (error) {
console.error('Failed to fetch head quarters', error)
}
}

fetchHeadQuarters()
}, [])

return (
<footer className='bg-neutral-100 py-16'>
<div className='container'>
Expand All @@ -11,8 +37,12 @@ export default function Footer() {
</div>
<div className='lg:col-span-2'>
<div>
Quốc gia & Khu vực: Singapore Indonesia Thái Lan Malaysia Việt Nam Philippines Brazil México Colombia
Chile Đài Loan
Quốc gia & Khu vực:{' '}
{headQuarters.map((headQuarter) => (
<Link key={headQuarter.id} href={headQuarter.domain_url} target='_blank' rel='noreferrer'>
{headQuarter.region} |{' '}
</Link>
))}
</div>
</div>
</div>
Expand Down

0 comments on commit 511f28f

Please sign in to comment.