diff --git a/src/components/FeedbackSection.tsx b/src/components/FeedbackSection.tsx new file mode 100644 index 0000000..cfc3227 --- /dev/null +++ b/src/components/FeedbackSection.tsx @@ -0,0 +1,104 @@ +import { Box, Typography, Button } from '@mui/material'; +import React, { useState } from 'react'; + +import { FeedbackItem } from '@utils/types'; + +import { ColoredBox } from './ColoredBox'; +import { FeedbackCard } from './FeedbackCard'; + +interface FeedbackSectionProps { + title: string; + feedbacks: FeedbackItem[]; +} + +export const FeedbackSection: React.FC = ({ + title, + feedbacks, +}) => { + const initialDisplay = 3; + const [feedbacksDisplayed, setFeedbacksDisplayed] = + useState(initialDisplay); + const showMoreFeedbacks = () => { + setFeedbacksDisplayed((prevCount) => + Math.min(prevCount + 3, feedbacks.length), + ); + }; + const showLessFeedbacks = () => { + setFeedbacksDisplayed(3); + }; + + return ( + + + + {title} + + initialDisplay ? '1fr 1fr' : '', + md: '', + }, + }} + > + {feedbacks && feedbacks.length > 0 ? ( + feedbacks + .slice(0, feedbacksDisplayed) + .map((feedback: FeedbackItem) => ( + + )) + ) : ( +

There‵s no feedback yet!

+ )} +
+ + {feedbacks.length > initialDisplay && ( + + )} +
+
+ ); +}; diff --git a/src/components/index.tsx b/src/components/index.tsx index 8e3aa1d..eef2c1c 100644 --- a/src/components/index.tsx +++ b/src/components/index.tsx @@ -35,3 +35,4 @@ export { ResourcesCard } from './ResourcesCard'; export { HeroWithImage } from './HeroWithImage'; export { InfoWithContact } from './InfoWithContact'; export { BreadCrumbsDynamic } from './BreadCrumbsDynamic'; +export { FeedbackSection } from './FeedbackSection'; diff --git a/src/lib/api.ts b/src/lib/api.ts index 50317f8..e45c3b1 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -2,6 +2,8 @@ import axios, { AxiosRequestConfig } from 'axios'; import { logger } from 'bs-logger'; import { NextApiResponse } from 'next'; +import { MentorshipProgrammeData } from '@utils/types'; + import aboutUsPage from './responses/aboutUs.json'; import aboutUsTeam from './responses/aboutUsTeam.json'; import footerData from './responses/footer.json'; @@ -85,6 +87,7 @@ export const fetchData = async (path: string) => { } }; +// Refactor this using fetchFromPath() export const handleApiError = (error: unknown, res: NextApiResponse) => { const err = error as { response?: { status: number; data: unknown }; @@ -106,3 +109,19 @@ export const fetchFooter = async () => { return footerData; } }; +export const fetchMentorship: () => Promise = + async () => fetchFromPath('/mentorship/overview', mentorShipPage); + +const fetchFromPath = async (path: string, backupData: any) => { + try { + logger.debug(`Attempting to fetch from ${path}`); + const response = await client.get(`${apiBaseUrl}${path}`, { + headers: { 'X-API-KEY': API_KEY }, + }); + + return response.data; + } catch (error) { + logger.error(`Failed to fetch from ${path}. Error: ${error}`); + return backupData; + } +}; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 2cdb4a2..19b20dc 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -9,22 +9,23 @@ import { VolunteerSection, Footer, EventContainer, + FeedbackSection, } from '@components'; -import { FooterResponse, LandingPageResponse } from '@utils/types'; -import { fetchData } from 'lib/api'; - -type CombinedResponse = { - data: LandingPageResponse; - footer: FooterResponse; -}; +import { + FooterResponse, + LandingPageResponse, + MentorshipProgrammeData, +} from '@utils/types'; +import { fetchData, fetchMentorship } from 'lib/api'; interface HomePageProps { data: LandingPageResponse; footer: FooterResponse; + mentorship: MentorshipProgrammeData; error: string | null; } -const HomePage = ({ data, footer, error }: HomePageProps) => { +const HomePage = ({ data, footer, mentorship, error }: HomePageProps) => { const router = useRouter(); useEffect(() => { @@ -46,6 +47,10 @@ const HomePage = ({ data, footer, error }: HomePageProps) => { +