import React, {useState, useEffect} from "react"; import Layout from "../Partials/Layout"; import usersService from "../../services/UsersService"; import LoadingSpinner from "../Spinners/LoadingSpinner"; import TabButton from "../customTabs/TabButton"; export default function LearnMore() { const apiCall = new usersService() const [selectedTab, setSelectedTab] = useState("topic 1"); const [tabs, setTabs] = useState( [ //STATE FOR SWITCHING BETWEEN TABS { id: 1, title: "topic 1", iconName: "history", }, { id: 2, title: "topic 2", iconName: "history", }, { id: 3, title: "topic 3", iconName: "history", }, { id: 4, title: "topic 4", iconName: "history", }, ] ) // const tabs = [ //STATE FOR SWITCHING BETWEEN TABS // { // id: 1, // title: "topic 1", // iconName: "history", // }, // { // id: 2, // title: "topic 2", // iconName: "history", // }, // { // id: 3, // title: "topic 3", // iconName: "history", // }, // { // id: 4, // title: "topic 4", // iconName: "history", // }, // ] let [topics, setTopics] = useState({ // FOR PAYMENT HISTORY loading: true, data: [], }) //FUNCTION TO GET LEARN MORE TOPIC useEffect(()=>{ apiCall.getLearnmoreTopics().then((res)=>{ if(res.data.internal_return < 0){ // success but no data setTopics(prev => ({...prev, loading: false})) return } const resData = res?.data?.result_list setTopics(prev => ({...prev, loading: false, data: resData})) setTabs(prev => { return prev.map((item, index) => ({...item, title:resData[index].topic})) }) setSelectedTab(resData[0].topic) // console.log('RES', resData) }).catch((error)=>{ setTopics(prev => ({...prev, loading: false})) }) }, []) return ( <>

Learn More

{(!topics.loading && topics?.data?.length > 0) && tabs.map((item) => (
))}
<> {/* TOPICS SECTION */}
{topics.loading ? : <> {(topics?.data && topics?.data?.length > 0) ?
item.topic == selectedTab)[0]?.contents, }} className='prose dark:text-white dark:bg-dark-white' > {/* {topics?.data?.filter(item => item.topic == selectedTab)[0]?.contents} */}
:

No Topics found

} }
{/* END OF TOPICS SECTION */}
); }