From 59d8e51abda6148a664d0014d46ae55a457dc7c2 Mon Sep 17 00:00:00 2001 From: emjshrx Date: Fri, 24 Nov 2023 13:43:58 +0530 Subject: [PATCH 1/3] refac: change faq to a generic component --- src/components/CollapseList.tsx | 58 ++++++++++++++++++++++++ src/components/Faq.tsx | 78 --------------------------------- src/pages/cohort.astro | 35 ++++++++++++++- 3 files changed, 91 insertions(+), 80 deletions(-) create mode 100644 src/components/CollapseList.tsx delete mode 100644 src/components/Faq.tsx diff --git a/src/components/CollapseList.tsx b/src/components/CollapseList.tsx new file mode 100644 index 0000000..28c85f9 --- /dev/null +++ b/src/components/CollapseList.tsx @@ -0,0 +1,58 @@ +import Collapse from "@mui/material/Collapse"; +import { useState } from "react"; + +export const CollapseList = ({ + header, + listConfig, +}: { + header: string; + listConfig: { q: any; a: any }[]; +}) => { + const [activeIndex, setActiveIndex] = useState(-1); + const handleElementClick = (index: number) => { + if (activeIndex == index) { + setActiveIndex(-1); + } else { + setActiveIndex(index); + } + }; + return ( + <> +
+ {header} +
+
+ + + ); +}; diff --git a/src/components/Faq.tsx b/src/components/Faq.tsx deleted file mode 100644 index 4e98d5d..0000000 --- a/src/components/Faq.tsx +++ /dev/null @@ -1,78 +0,0 @@ -import Collapse from "@mui/material/Collapse"; -import { useState } from "react"; -const defaultConfig = [ - { - q: "How does the Bitcoin Study Cohort work?", - a: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ", - }, - { - q: "Who can join the Bitcoin Study Cohort?", - a: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ", - }, - { - q: "Is there a fee to join the cohort?", - a: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ", - }, - { - q: "What resources are provided to participants?", - a: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ", - }, - { - q: "Is there a fee to join the cohort?", - a: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ", - }, - { - q: "What resources are provided to participants?", - a: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ", - }, -]; - -export const Faq = () => { - const [activeIndex, setActiveIndex] = useState(-1); - const handleQuestionClick = (index: number) => { - if (activeIndex == index) { - setActiveIndex(-1); - } else { - setActiveIndex(index); - } - }; - return ( - <> -
- Checkout some of the FAQs -
-
- - - ); -}; diff --git a/src/pages/cohort.astro b/src/pages/cohort.astro index 96f583a..e9f56c1 100644 --- a/src/pages/cohort.astro +++ b/src/pages/cohort.astro @@ -5,7 +5,34 @@ import CohortCard from "../components/CohortCard.astro"; import Footer from "../components/Footer.astro"; import Carousel from "../components/Carousel"; import Header from "../components/Header.astro"; -import { Faq } from "../components/Faq"; +import { CollapseList } from "../components/CollapseList"; + +const faqConfig = [ + { + q: "How does the Bitcoin Study Cohort work?", + a: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ", + }, + { + q: "Who can join the Bitcoin Study Cohort?", + a: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ", + }, + { + q: "Is there a fee to join the cohort?", + a: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ", + }, + { + q: "What resources are provided to participants?", + a: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ", + }, + { + q: "Is there a fee to join the cohort?", + a: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ", + }, + { + q: "What resources are provided to participants?", + a: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ", + }, +]; --- @@ -18,7 +45,11 @@ import { Faq } from "../components/Faq"; /> - +