feat(whole project): huge changes, huge updates

This commit is contained in:
sankalp committed 2025-04-24 20:17:52 +05:45
1 parent 666b5bb827
commit 2bd8bb2dfc
196 files changed
+9146 -4316

No files matched your search

+127 -61
View File
@@ -1,68 +1,134 @@
import { View, Text, ScrollView } from 'react-native'
import React, { useState } from 'react'
import { View, Text, ScrollView, ActivityIndicator, Animated } from 'react-native'
import React, { useState, useEffect, useRef } from 'react'
import { TouchableOpacity } from 'react-native';
import { ChevronDownIcon, ChevronUpIcon } from 'react-native-heroicons/outline';
import { getFAQs, getFAQCategories } from '../api';
export default function FaqCenter() {
const faq = ["All", "Services", "General", "Account"]
const [faqActive, setfaqActive] = useState(0);
return (
<View className={`mx-4 mt-5 `} >
<ScrollView horizontal showsHorizontalScrollIndicator={false}>
{
faq.map((item, index) => {
let isActive = index == faqActive;
return (
<TouchableOpacity
key={index}
onPress={() => setfaqActive(index)}
className={`
border border-gray-200 bg-gray-200 px-5 mr-4 mb-4 rounded-full py-3
${isActive ? "bg-primary" : ""}
`}>
<Text className={`${isActive ? "text-white " : ""} capitalize font-bold`}>
{item}
</Text>
</TouchableOpacity>
)
})
}
</ScrollView>
<View className={`border border-gray-300 rounded-2xl mb-5`}>
<View className={`flex-row justify-between items-center p-3 border-b border-b-gray-300 `}>
<Text className={`font-semibold text-lg`}>Can i track my order's delevery status ?</Text>
<ChevronUpIcon color={"#704f38"} />
</View>
<Text className={`p-3`}>Lorem ipsum dolor sit amet consectetur adipisicing elit. Ab distinctio nihil assumenda nostrum laboriosam quo,
officia eligendi obcaecati accusamus aliquam debitis, voluptatibus excepturi consequatur expedita eius quisquam velit. Rerum, officia?</Text>
</View>
<View className={`mb-`}>
<View className={`flex-row justify-between items-center p-3 border rounded-2xl border-gray-300 mb-2 `}>
<Text className={`font-semibold text-lg`}>Is there a return policy ?</Text>
<ChevronDownIcon color={"#704f38"} />
</View>
<View className={`flex-row justify-between items-center p-3 border rounded-2xl border-gray-300 mb-2 `}>
<Text className={`font-semibold text-lg`}>Can i save my favorite item for later ?</Text>
<ChevronDownIcon color={"#704f38"} />
</View>
<View className={`flex-row justify-between items-center p-3 border rounded-2xl border-gray-300 mb-2`}>
<Text className={`font-semibold text-lg`}>Can i share products with my friends ?</Text>
<ChevronDownIcon color={"#704f38"} />
</View>
<View className={`flex-row justify-between items-center p-3 border rounded-2xl border-gray-300 mb-2`}>
<Text className={`font-semibold text-lg`}>How do i contact customer support ?</Text>
<ChevronDownIcon color={"#704f38"} />
</View>
<View className={`flex-row justify-between items-center p-3 border rounded-2xl border-gray-300 mb-2`}>
<Text className={`font-semibold text-lg`}>What payment methods are accepted ?</Text>
<ChevronDownIcon color={"#704f38"} />
</View>
<View className={`flex-row justify-between items-center p-3 border rounded-2xl border-gray-300 mb-2`}>
<Text className={`font-semibold text-lg`}>How to add review ?</Text>
<ChevronDownIcon color={"#704f38"} />
</View>
</View>
const [categories, setCategories] = useState(['All', 'Services', 'General', 'Account']);
const [activeCategory, setActiveCategory] = useState('All');
const [faqs, setFaqs] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const [expandedFaqs, setExpandedFaqs] = useState({});
const animations = useRef({});
useEffect(() => {
fetchCategories();
}, []);
useEffect(() => {
fetchFAQs();
}, [activeCategory]);
const fetchCategories = async () => {
try {
const data = await getFAQCategories();
setCategories(data);
} catch (err) {
console.error('Error fetching categories:', err);
}
};
const fetchFAQs = async () => {
try {
setLoading(true);
const data = await getFAQs(activeCategory);
setFaqs(data);
const initialExpandedState = {};
data.forEach(faq => {
initialExpandedState[faq.id] = false;
animations.current[faq.id] = new Animated.Value(0);
});
setExpandedFaqs(initialExpandedState);
} catch (err) {
setError('Failed to load FAQs');
console.error('Error fetching FAQs:', err);
} finally {
setLoading(false);
}
};
const toggleFaq = (faqId) => {
const isExpanded = !expandedFaqs[faqId];
setExpandedFaqs(prev => ({
...prev,
[faqId]: isExpanded
}));
Animated.timing(animations.current[faqId], {
toValue: isExpanded ? 1 : 0,
duration: 300,
useNativeDriver: false,
}).start();
};
return (
<View className="mx-4 mt-5">
<ScrollView horizontal showsHorizontalScrollIndicator={false} className="mb-4">
{categories.map((category, index) => {
const isActive = category === activeCategory;
return (
<TouchableOpacity
key={index}
onPress={() => setActiveCategory(category)}
className={`
border border-gray-200 bg-gray-200 px-5 mr-4 rounded-full py-3
${isActive ? "bg-primary" : ""}
`}>
<Text className={`${isActive ? "text-white" : ""} capitalize font-bold`}>
{category}
</Text>
</TouchableOpacity>
);
})}
</ScrollView>
{loading ? (
<ActivityIndicator size="large" color="#704f38" />
) : error ? (
<Text className="text-red-500 text-center">{error}</Text>
) : faqs.length > 0 ? (
faqs.map((faq) => (
<View key={faq.id} className="mb-4">
<View className="border rounded-2xl border-gray-300 bg-white overflow-hidden">
<TouchableOpacity
onPress={() => toggleFaq(faq.id)}
className="flex-row justify-between items-center p-4">
<Text className="font-semibold text-lg flex-1 mr-2">{faq.question}</Text>
{expandedFaqs[faq.id] ? (
<ChevronUpIcon color="#704f38" size={24} />
) : (
<ChevronDownIcon color="#704f38" size={24} />
)}
</TouchableOpacity>
<Animated.View
style={{
maxHeight: animations.current[faq.id].interpolate({
inputRange: [0, 1],
outputRange: [0, 1000],
}),
opacity: animations.current[faq.id],
overflow: 'hidden',
}}
>
<View className="px-4 pb-4">
<View className="h-px bg-gray-200 mb-4" />
<Text className="text-gray-700 leading-6 text-base">
{faq.answer}
</Text>
</View>
</Animated.View>
</View>
</View>
))
) : (
<View className="items-center justify-center py-8">
<Text className="text-gray-500 text-center text-lg">
No FAQs available for this category
</Text>
</View>
)}
</View>
)
);
}