|
| 1 | +import { useState } from 'react'; |
| 2 | +import { useSelector } from 'react-redux'; |
| 3 | +import styles from './FaqSection.module.css'; |
| 4 | + |
| 5 | +function FaqSection() { |
| 6 | + const faqs = [ |
| 7 | + { |
| 8 | + id: 1, |
| 9 | + question: 'What is One Community?', |
| 10 | + answer: |
| 11 | + 'One Community is a global nonprofit organization focused on creating sustainable living models and open-source solutions for a better world.', |
| 12 | + category: 'General', |
| 13 | + }, |
| 14 | + { |
| 15 | + id: 2, |
| 16 | + question: 'How can I participate?', |
| 17 | + answer: |
| 18 | + 'You can participate by volunteering, donating, or joining our collaborative projects in various fields like engineering, design, and education.', |
| 19 | + category: 'Participation', |
| 20 | + }, |
| 21 | + { |
| 22 | + id: 3, |
| 23 | + question: 'Is One Community free to join?', |
| 24 | + answer: |
| 25 | + 'Yes, joining One Community is completely free. We welcome anyone interested in sustainability and positive global change.', |
| 26 | + category: 'General', |
| 27 | + }, |
| 28 | + { |
| 29 | + id: 4, |
| 30 | + question: 'How can I contact One Community?', |
| 31 | + answer: |
| 32 | + "You can contact us by clicking on the 'Contact Us' link below. Our team will respond as soon as possible.", |
| 33 | + category: 'Other', |
| 34 | + }, |
| 35 | + { |
| 36 | + id: 5, |
| 37 | + question: 'What kind of events does One Community organize?', |
| 38 | + answer: |
| 39 | + 'We organize workshops, webinars, sustainability summits, and community-building events throughout the year.', |
| 40 | + category: 'Events', |
| 41 | + }, |
| 42 | + { |
| 43 | + id: 6, |
| 44 | + question: 'Where is One Community located?', |
| 45 | + answer: |
| 46 | + 'One Community is a virtual and physical initiative with a developing sustainable village model in the United States.', |
| 47 | + category: 'Other', |
| 48 | + }, |
| 49 | + ]; |
| 50 | + |
| 51 | + const [openIndex, setOpenIndex] = useState(null); |
| 52 | + const [copied, setCopied] = useState(false); |
| 53 | + const [selectedCategory, setSelectedCategory] = useState('All'); |
| 54 | + const [searchTerm, setSearchTerm] = useState(''); |
| 55 | + const darkMode = useSelector(state => state.theme.darkMode); |
| 56 | + |
| 57 | + const toggleFaq = id => { |
| 58 | + setOpenIndex(openIndex === id ? null : id); |
| 59 | + }; |
| 60 | + |
| 61 | + const handleContactClick = () => { |
| 62 | + const email = 'onecommunityglobal@gmail.com'; |
| 63 | + navigator.clipboard |
| 64 | + .writeText(email) |
| 65 | + .then(() => setCopied(true)) |
| 66 | + // eslint-disable-next-line no-console |
| 67 | + .catch(err => console.error('Failed to copy:', err)); |
| 68 | + |
| 69 | + setTimeout(() => setCopied(false), 2000); |
| 70 | + }; |
| 71 | + |
| 72 | + const handleCategoryClick = category => { |
| 73 | + setSelectedCategory(category); |
| 74 | + setOpenIndex(null); |
| 75 | + }; |
| 76 | + |
| 77 | + const handleSearchChange = e => { |
| 78 | + setSearchTerm(e.target.value); |
| 79 | + setOpenIndex(null); |
| 80 | + }; |
| 81 | + |
| 82 | + const filteredFaqs = faqs.filter(faq => { |
| 83 | + const matchesCategory = selectedCategory === 'All' || faq.category === selectedCategory; |
| 84 | + const matchesSearch = |
| 85 | + searchTerm === '' || |
| 86 | + faq.question.toLowerCase().includes(searchTerm.toLowerCase()) || |
| 87 | + faq.answer.toLowerCase().includes(searchTerm.toLowerCase()); |
| 88 | + |
| 89 | + return matchesCategory && matchesSearch; |
| 90 | + }); |
| 91 | + |
| 92 | + return ( |
| 93 | + <div className={styles.faqContainer}> |
| 94 | + <h2 className={styles.faqTitle}>Frequently Asked Questions</h2> |
| 95 | + <p className={styles.faqSubtitle}> |
| 96 | + These are the most frequently asked questions about One Community. |
| 97 | + </p> |
| 98 | + |
| 99 | + <input |
| 100 | + type="text" |
| 101 | + className={`${styles.faqSearch} ${darkMode ? styles.faqSearchDark : ''}`} |
| 102 | + placeholder="Search FAQs..." |
| 103 | + value={searchTerm} |
| 104 | + onChange={handleSearchChange} |
| 105 | + /> |
| 106 | + |
| 107 | + <div className={styles.faqButtons}> |
| 108 | + {['All', 'General', 'Events', 'Participation', 'Other'].map(category => ( |
| 109 | + <button |
| 110 | + key={category} |
| 111 | + type="button" |
| 112 | + className={`${styles.faqCategory} ${ |
| 113 | + selectedCategory === category ? styles.active : '' |
| 114 | + } ${darkMode ? styles.faqCategoryDark : ''}`} |
| 115 | + onClick={() => handleCategoryClick(category)} |
| 116 | + > |
| 117 | + {category} |
| 118 | + </button> |
| 119 | + ))} |
| 120 | + </div> |
| 121 | + |
| 122 | + <div className={styles.faqList}> |
| 123 | + {filteredFaqs.length === 0 ? ( |
| 124 | + <div className={styles.noResults}> |
| 125 | + <p>No FAQs found matching your criteria.</p> |
| 126 | + </div> |
| 127 | + ) : ( |
| 128 | + filteredFaqs.map(faq => ( |
| 129 | + <div key={faq.id} className={styles.faqItem}> |
| 130 | + <button |
| 131 | + type="button" |
| 132 | + className={`${styles.faqQuestion} ${darkMode ? styles.faqQuestionDark : ''}`} |
| 133 | + onClick={() => toggleFaq(faq.id)} |
| 134 | + aria-expanded={openIndex === faq.id} |
| 135 | + > |
| 136 | + {faq.question} |
| 137 | + <span className={`${styles.faqArrow} ${openIndex === faq.id ? styles.open : ''}`}> |
| 138 | + ▾ |
| 139 | + </span> |
| 140 | + </button> |
| 141 | + <div className={`${styles.faqAnswer} ${openIndex === faq.id ? styles.open : ''}`}> |
| 142 | + <div>{faq.answer}</div> |
| 143 | + </div> |
| 144 | + </div> |
| 145 | + )) |
| 146 | + )} |
| 147 | + </div> |
| 148 | + |
| 149 | + <p className={styles.faqContact}> |
| 150 | + Still have questions? Feel free to{' '} |
| 151 | + <button type="button" className={styles.contactLink} onClick={handleContactClick}> |
| 152 | + contact us |
| 153 | + </button> |
| 154 | + .{copied && <span className={styles.copiedMessage}> Copied!</span>} |
| 155 | + </p> |
| 156 | + </div> |
| 157 | + ); |
| 158 | +} |
| 159 | + |
| 160 | +export default FaqSection; |
0 commit comments