chore: init
This commit is contained in:
199 files changed
+27919
No files matched your search
@@ -0,0 +1,81 @@
|
||||
import { View, Text, Image, TouchableOpacity, StyleSheet } from 'react-native'
|
||||
import React from 'react'
|
||||
import { useNavigation } from '@react-navigation/native'
|
||||
|
||||
export default function ActiveOrder({ orders = [], navigation: propNavigation }) {
|
||||
// Use provided navigation prop if available, otherwise get from hook
|
||||
const navigation = propNavigation || useNavigation();
|
||||
|
||||
// Safe number formatting helper
|
||||
const formatCurrency = (value) => {
|
||||
if (value === undefined || value === null) return '0.00';
|
||||
if (typeof value === 'number') return value.toFixed(2);
|
||||
if (typeof value === 'string') {
|
||||
const num = parseFloat(value);
|
||||
return isNaN(num) ? '0.00' : num.toFixed(2);
|
||||
}
|
||||
return '0.00';
|
||||
};
|
||||
|
||||
if (!orders || orders.length === 0) {
|
||||
return (
|
||||
<View className="flex-1 justify-center items-center py-10">
|
||||
<Text className="text-gray-500">No active orders found</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<View className={`mx-4`}>
|
||||
{orders.map((order, index) => {
|
||||
// Each order can have multiple items
|
||||
return (
|
||||
<View key={index} className="mb-6 border rounded-lg border-gray-200 overflow-hidden">
|
||||
<View className="bg-gray-100 p-3 border-b border-gray-200">
|
||||
<Text className="font-bold">Order #{order.id}</Text>
|
||||
<Text className="text-gray-500">
|
||||
{new Date(order.created_at || order.date).toLocaleDateString()} |
|
||||
Status: <Text className="text-primary font-medium capitalize">{order.status}</Text>
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
{order.items && order.items.map((item, itemIndex) => (
|
||||
<View key={itemIndex} className={`flex-row items-center gap-6 py-3 px-3 ${itemIndex < order.items.length - 1 ? 'border-b border-gray-200' : ''}`}>
|
||||
<Image
|
||||
source={{ uri: item.product_image || item.product?.image || 'https://via.placeholder.com/100' }}
|
||||
className="size-[90px] rounded-lg"
|
||||
defaultSource={require('../../assets/images/favicon.png')}
|
||||
/>
|
||||
<View className={`flex-1 flex-col gap-2`}>
|
||||
<Text className={`font-medium text-lg`}>{item.product_name || item.product?.title || 'Product'}</Text>
|
||||
<Text className={`text-sm`}>Qty: {item.quantity}</Text>
|
||||
<View className={`flex-row justify-between items-start`}>
|
||||
<Text className={`text-lg font-bold`}>${formatCurrency(item.price || item.subtotal)}</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
|
||||
<View className="bg-gray-50 p-3 border-t border-gray-200 flex-row justify-between items-center">
|
||||
<Text className="font-bold">Total: ${formatCurrency(order.total_price || order.total_amount)}</Text>
|
||||
<TouchableOpacity
|
||||
onPress={() => navigation.navigate('Track Order', { orderId: order.id })}
|
||||
className={`bg-primary rounded-full px-4 py-2`}
|
||||
>
|
||||
<Text className={`text-white font-medium`}>Track Order</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = {
|
||||
itemImage: {
|
||||
width: 90,
|
||||
height: 90,
|
||||
borderRadius: 10,
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { View, Text, Image, TouchableOpacity } from 'react-native'
|
||||
import React from 'react'
|
||||
import { useNavigation } from '@react-navigation/native'
|
||||
|
||||
export default function CancelledOrder({ orders = [], navigation: propNavigation }) {
|
||||
// Use provided navigation prop if available, otherwise get from hook
|
||||
const navigation = propNavigation || useNavigation();
|
||||
|
||||
// Safe number formatting helper
|
||||
const formatCurrency = (value) => {
|
||||
if (value === undefined || value === null) return '0.00';
|
||||
if (typeof value === 'number') return value.toFixed(2);
|
||||
if (typeof value === 'string') {
|
||||
const num = parseFloat(value);
|
||||
return isNaN(num) ? '0.00' : num.toFixed(2);
|
||||
}
|
||||
return '0.00';
|
||||
};
|
||||
|
||||
if (!orders || orders.length === 0) {
|
||||
return (
|
||||
<View className="flex-1 justify-center items-center py-10">
|
||||
<Text className="text-gray-500">No cancelled orders found</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<View className={`mx-4`}>
|
||||
{orders.map((order, index) => {
|
||||
// Each order can have multiple items
|
||||
return (
|
||||
<View key={index} className="mb-6 border rounded-lg border-gray-200 overflow-hidden">
|
||||
<View className="bg-gray-100 p-3 border-b border-gray-200">
|
||||
<Text className="font-bold">Order #{order.id}</Text>
|
||||
<Text className="text-gray-500">
|
||||
{new Date(order.created_at || order.date).toLocaleDateString()} |
|
||||
Status: <Text className="text-red-500 font-medium capitalize">{order.status}</Text>
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
{order.items && order.items.map((item, itemIndex) => (
|
||||
<View key={itemIndex} className={`flex-row items-center gap-6 py-3 px-3 ${itemIndex < order.items.length - 1 ? 'border-b border-gray-200' : ''}`}>
|
||||
<Image
|
||||
source={{ uri: item.product_image || item.product?.image || 'https://via.placeholder.com/100' }}
|
||||
className="size-[90px] rounded-lg"
|
||||
defaultSource={require('../../assets/images/favicon.png')}
|
||||
/>
|
||||
<View className={`flex-1 flex-col gap-2`}>
|
||||
<Text className={`font-medium text-lg`}>{item.product_name || item.product?.title || 'Product'}</Text>
|
||||
<Text className={`text-sm`}>Qty: {item.quantity}</Text>
|
||||
<View className={`flex-row justify-between items-start`}>
|
||||
<Text className={`text-lg font-bold`}>${formatCurrency(item.price || item.subtotal)}</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
|
||||
<View className="bg-gray-50 p-3 border-t border-gray-200 flex-row justify-between items-center">
|
||||
<Text className="font-bold">Total: ${formatCurrency(order.total_price || order.total_amount)}</Text>
|
||||
<TouchableOpacity
|
||||
onPress={() => navigation.navigate('Home')}
|
||||
className={`bg-primary rounded-full px-4 py-2`}
|
||||
>
|
||||
<Text className={`text-white font-medium`}>Re-Order</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { View, Text, ScrollView, Image, TouchableOpacity } from 'react-native'
|
||||
import React from 'react'
|
||||
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
|
||||
export default function Category({ categories = [] }) {
|
||||
const navigation = useNavigation()
|
||||
|
||||
// Use fallback demo data if no categories are provided
|
||||
const displayCategories = categories.length > 0 ? categories : [
|
||||
{
|
||||
id: 1,
|
||||
name: "T-shirt",
|
||||
image: "https://www.iconarchive.com/download/i97169/iconsmind/outline/T-Shirt.ico"
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "Pant",
|
||||
image: "https://static.vecteezy.com/system/resources/previews/010/347/283/non_2x/pants-boy-garment-line-icon-illustration-vector.jpg"
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: "Dress",
|
||||
image: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRQdRkx2psjWSnEJnmPy1-8c40UVYLtDtTINA&s"
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: "Jacket",
|
||||
image: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTskcACyLVW4kXqpz2KGOAPyoQ7LKURrafxLw&s"
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
name: "Kids",
|
||||
image: "https://cdn-icons-png.flaticon.com/512/2934/2934315.png"
|
||||
}
|
||||
]
|
||||
|
||||
return (
|
||||
<View className=" flex-col gap-4 mb-6">
|
||||
<View className="flex-row justify-between items-center px-1 mx-4" >
|
||||
<Text className="text-xl font-semibold">Category</Text>
|
||||
<Text className="text-secondary font-medium">See All</Text>
|
||||
</View>
|
||||
<ScrollView
|
||||
horizontal
|
||||
showsHorizontalScrollIndicator={false}
|
||||
className="ml-4"
|
||||
>
|
||||
{
|
||||
displayCategories.map((item, index) => {
|
||||
return (
|
||||
<TouchableOpacity
|
||||
key={item.id}
|
||||
onPress={() => {
|
||||
navigation.navigate('Category', {
|
||||
categoryId: item.id,
|
||||
title: item.name
|
||||
})
|
||||
}}
|
||||
className={`${index + 1 == displayCategories.length ? "mr-4" : " mr-4"} flex-col items-center gap-2`}
|
||||
>
|
||||
<View className="bg-secondary flex justify-center items-center rounded-full" style={{ height: hp('8%'), width: hp('8%') }}>
|
||||
<Image
|
||||
source={{ uri: item.image }}
|
||||
className="size-10"
|
||||
style={{ width: hp('6%'), height: hp('6%'), borderRadius: 30 }}
|
||||
/>
|
||||
</View>
|
||||
<Text className="text-center">{item.name}</Text>
|
||||
</TouchableOpacity>
|
||||
)
|
||||
})
|
||||
}
|
||||
</ScrollView>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { View, Text, Image, TouchableOpacity } from 'react-native'
|
||||
import React from 'react'
|
||||
import { useNavigation } from '@react-navigation/native'
|
||||
|
||||
export default function CompletedOrder({ orders = [], navigation: propNavigation }) {
|
||||
// Use provided navigation prop if available, otherwise get from hook
|
||||
const navigation = propNavigation || useNavigation();
|
||||
|
||||
// Safe number formatting helper
|
||||
const formatCurrency = (value) => {
|
||||
if (value === undefined || value === null) return '0.00';
|
||||
if (typeof value === 'number') return value.toFixed(2);
|
||||
if (typeof value === 'string') {
|
||||
const num = parseFloat(value);
|
||||
return isNaN(num) ? '0.00' : num.toFixed(2);
|
||||
}
|
||||
return '0.00';
|
||||
};
|
||||
|
||||
if (!orders || orders.length === 0) {
|
||||
return (
|
||||
<View className="flex-1 justify-center items-center py-10">
|
||||
<Text className="text-gray-500">No completed orders found</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<View className={`mx-4`}>
|
||||
{orders.map((order, index) => {
|
||||
// Each order can have multiple items
|
||||
return (
|
||||
<View key={index} className="mb-6 border rounded-lg border-gray-200 overflow-hidden">
|
||||
<View className="bg-gray-100 p-3 border-b border-gray-200">
|
||||
<Text className="font-bold">Order #{order.id}</Text>
|
||||
<Text className="text-gray-500">
|
||||
{new Date(order.created_at || order.date).toLocaleDateString()} |
|
||||
Status: <Text className="text-green-600 font-medium capitalize">{order.status}</Text>
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
{order.items && order.items.map((item, itemIndex) => (
|
||||
<View key={itemIndex} className={`flex-row items-center gap-6 py-3 px-3 ${itemIndex < order.items.length - 1 ? 'border-b border-gray-200' : ''}`}>
|
||||
<Image
|
||||
source={{ uri: item.product_image || item.product?.image || 'https://via.placeholder.com/100' }}
|
||||
className="size-[90px] rounded-lg"
|
||||
defaultSource={require('../../assets/images/favicon.png')}
|
||||
/>
|
||||
<View className={`flex-1 flex-col gap-2`}>
|
||||
<Text className={`font-medium text-lg`}>{item.product_name || item.product?.title || 'Product'}</Text>
|
||||
<Text className={`text-sm`}>Qty: {item.quantity}</Text>
|
||||
<View className={`flex-row justify-between items-start`}>
|
||||
<Text className={`text-lg font-bold`}>${formatCurrency(item.price || item.subtotal)}</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
|
||||
<View className="bg-gray-50 p-3 border-t border-gray-200 flex-row justify-between items-center">
|
||||
<Text className="font-bold">Total: ${formatCurrency(order.total_price || order.total_amount)}</Text>
|
||||
<TouchableOpacity
|
||||
onPress={() => navigation.navigate('Leave Review')}
|
||||
className={`bg-primary rounded-full px-4 py-2`}
|
||||
>
|
||||
<Text className={`text-white font-medium`}>Leave Review</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { View, Text } from 'react-native'
|
||||
import React from 'react'
|
||||
import { ChevronDownIcon, ChevronUpIcon, GlobeAltIcon } from 'react-native-heroicons/outline'
|
||||
import Icon from 'react-native-vector-icons/FontAwesome6';
|
||||
|
||||
export default function ContactUsCenter() {
|
||||
return (
|
||||
<View className={` mt-4 mx-4 `}>
|
||||
<View className={` flex-row items-center justify-between p-4 border rounded-xl border-gray-300 mb-3`}>
|
||||
<View className={`flex-row items-center gap-4 `}>
|
||||
<Icon name='headset' color={"#704f38"} size={25} />
|
||||
<Text className={`text-lg font-semibold`}>Customer Service</Text>
|
||||
</View>
|
||||
<View className={`justify-center items-center`}>
|
||||
<ChevronDownIcon color={"#704f38"} size={24} />
|
||||
</View>
|
||||
</View>
|
||||
<View className={`border mb-3 rounded-xl border-gray-300`}>
|
||||
<View className={` flex-row items-center justify-between p-4 border-b border-b-gray-300 mb-3`}>
|
||||
<View className={`flex-row items-center gap-4 `}>
|
||||
<Icon name='whatsapp' color={"#704f38"} size={25} />
|
||||
<Text className={`text-lg font-semibold`}>WhatsApp</Text>
|
||||
</View>
|
||||
<View className={`justify-center items-center`}>
|
||||
<ChevronUpIcon color={"#704f38"} size={24} />
|
||||
</View>
|
||||
</View>
|
||||
<Text className={`p-4 text-left mx-9 text-gray-500`}>(480)555-0103</Text>
|
||||
</View>
|
||||
<View className={` flex-row items-center justify-between p-4 border rounded-xl border-gray-300 mb-3`}>
|
||||
<View className={`flex-row items-center gap-4 `}>
|
||||
<GlobeAltIcon color={"#704f38"} size={26} />
|
||||
<Text className={`text-lg font-semibold`}>Website</Text>
|
||||
</View>
|
||||
<View className={`justify-center items-center`}>
|
||||
<ChevronDownIcon color={"#704f38"} size={24} />
|
||||
</View>
|
||||
</View>
|
||||
<View className={` flex-row items-center justify-between p-4 border rounded-xl border-gray-300 mb-3`}>
|
||||
<View className={`flex-row items-center gap-4 `}>
|
||||
<Icon name='facebook' color={"#704f38"} size={26} />
|
||||
<Text className={`text-lg font-semibold`}>Facebook</Text>
|
||||
</View>
|
||||
<View className={`justify-center items-center`}>
|
||||
<ChevronDownIcon color={"#704f38"} size={24} />
|
||||
</View>
|
||||
</View>
|
||||
<View className={` flex-row items-center justify-between p-4 border rounded-xl border-gray-300 mb-3`}>
|
||||
<View className={`flex-row items-center gap-4 `}>
|
||||
<Icon name='instagram' color={"#704f38"} size={26} />
|
||||
<Text className={`text-lg font-semibold`}>Instagram</Text>
|
||||
</View>
|
||||
<View className={`justify-center items-center`}>
|
||||
<ChevronDownIcon color={"#704f38"} size={24} />
|
||||
</View>
|
||||
</View>
|
||||
<View className={` flex-row items-center justify-between p-4 border rounded-xl border-gray-300 mb-3`}>
|
||||
<View className={`flex-row items-center gap-4 `}>
|
||||
<Icon name='twitter' color={"#704f38"} size={26} />
|
||||
<Text className={`text-lg font-semibold`}>Twitter</Text>
|
||||
</View>
|
||||
<View className={`justify-center items-center`}>
|
||||
<ChevronDownIcon color={"#704f38"} size={24} />
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { View, Text, ScrollView } from 'react-native'
|
||||
import React, { useState } from 'react'
|
||||
import { TouchableOpacity } from 'react-native';
|
||||
import { ChevronDownIcon, ChevronUpIcon } from 'react-native-heroicons/outline';
|
||||
|
||||
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>
|
||||
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import { TouchableOpacity, ActivityIndicator } from 'react-native'
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import { HeartIcon } from 'react-native-heroicons/outline'
|
||||
import { HeartIcon as HeartSolid } from 'react-native-heroicons/solid'
|
||||
import { getFavorites } from '../api'
|
||||
|
||||
/**
|
||||
* A reusable favorite/wishlist button component
|
||||
*
|
||||
* @param {Object} props Component props
|
||||
* @param {boolean} props.isFavorite Whether the item is in favorites
|
||||
* @param {Function} props.onToggleFavorite Function to call when toggling favorite state
|
||||
* @param {number} props.size Icon size
|
||||
* @param {string} props.activeColor Color when active
|
||||
* @param {string} props.inactiveColor Color when inactive
|
||||
* @param {Object} props.style Additional styles for the container
|
||||
* @param {number} props.productId The ID of the product
|
||||
* @returns {React.Component} Favorite button component
|
||||
*/
|
||||
export default function FavoriteButton({
|
||||
isFavorite = false,
|
||||
onToggleFavorite,
|
||||
size = 24,
|
||||
activeColor = '#ff3b30',
|
||||
inactiveColor = '#000000',
|
||||
style = {},
|
||||
productId
|
||||
}) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [favoriteState, setFavoriteState] = useState(isFavorite);
|
||||
|
||||
// Update favorite state when isFavorite prop changes
|
||||
useEffect(() => {
|
||||
setFavoriteState(isFavorite);
|
||||
}, [isFavorite]);
|
||||
|
||||
// Check favorite status when component mounts
|
||||
useEffect(() => {
|
||||
const checkFavoriteStatus = async () => {
|
||||
if (productId) {
|
||||
try {
|
||||
const favorites = await getFavorites();
|
||||
const isFavorited = favorites.some(fav => fav.id === productId);
|
||||
setFavoriteState(isFavorited);
|
||||
} catch (error) {
|
||||
console.error('Error checking favorite status:', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
checkFavoriteStatus();
|
||||
}, [productId]);
|
||||
|
||||
const handlePress = async () => {
|
||||
if (!onToggleFavorite) return;
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
await onToggleFavorite();
|
||||
// Update local state after successful toggle
|
||||
setFavoriteState(!favoriteState);
|
||||
} catch (error) {
|
||||
console.error('Error toggling favorite:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<TouchableOpacity
|
||||
onPress={handlePress}
|
||||
disabled={loading}
|
||||
style={style}
|
||||
className="justify-center items-center"
|
||||
>
|
||||
{loading ? (
|
||||
<ActivityIndicator size="small" color={activeColor} />
|
||||
) : favoriteState ? (
|
||||
<HeartSolid size={size} color={activeColor} />
|
||||
) : (
|
||||
<HeartIcon size={size} color={inactiveColor} />
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
// demodata //normal case
|
||||
// demoData //camel case ex:iAmAGoodBBoy
|
||||
// demo_data // snake case ex:i_am_a_good_boy
|
||||
|
||||
import { View, Text, ScrollView, TouchableOpacity, Image } from 'react-native'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import MasonryList from '@react-native-seoul/masonry-list';
|
||||
import flashSalesData from '../constants/flashSalesData';
|
||||
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen';
|
||||
import { StarIcon } from 'react-native-heroicons/solid';
|
||||
import { HeartIcon } from 'react-native-heroicons/outline';
|
||||
import Icon from "react-native-vector-icons/FontAwesome"
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import { getFavorites, toggleFavorite } from '../api';
|
||||
|
||||
const FlashSales = ({data}) => {
|
||||
const navigation = useNavigation()
|
||||
const saleEnd = "2024-12-20T23:45:30";
|
||||
const [endDate, setEndDate] = useState(calenderLastDate(saleEnd))
|
||||
const [favorites, setFavorites] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => {
|
||||
const remainigTime = calenderLastDate(saleEnd)
|
||||
if (remainigTime.total <= 0) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
setEndDate(remainigTime)
|
||||
}, 1000)
|
||||
return () => clearInterval(timer)
|
||||
}, [saleEnd])
|
||||
|
||||
// Load favorites when component mounts
|
||||
useEffect(() => {
|
||||
const loadFavorites = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const favoriteProducts = await getFavorites();
|
||||
setFavorites(favoriteProducts || []);
|
||||
} catch (error) {
|
||||
console.error('Error loading favorites:', error);
|
||||
setFavorites([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
loadFavorites();
|
||||
}, []);
|
||||
|
||||
//Category toggle
|
||||
const subCategory = ["All", "Newest", "Popular", "Mens", "Kids", "Womens"]
|
||||
const [activeSet, setActiveSet] = useState("All")
|
||||
|
||||
const handleSubCategory = (item) => {
|
||||
setActiveSet(item)
|
||||
}
|
||||
|
||||
const handleFavouriteToggle = async (product) => {
|
||||
try {
|
||||
const updatedFavorites = await toggleFavorite(product);
|
||||
setFavorites(updatedFavorites || []);
|
||||
} catch (error) {
|
||||
console.error('Error toggling favorite:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const isProductFavorited = (productId) => {
|
||||
if (!Array.isArray(favorites)) return false;
|
||||
return favorites.some(fav => fav.id === productId);
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<View className="flex-1 justify-center items-center">
|
||||
<Text>Loading...</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<View>
|
||||
<View className="flex-row justify-between items-center px-1 mx-4 mb-4">
|
||||
<Text className="text-xl font-semibold">FlashSales</Text>
|
||||
{
|
||||
endDate.total >= 0 ? <View className="flex-row items-center gap-2">
|
||||
<Text className="font-medium text-gray-500">Closing in :</Text>
|
||||
<View className="bg-btnPrimary h-8 w-8 flex justify-center items-center rounded-lg">
|
||||
<Text className="text-primary">{endDate.hours}</Text>
|
||||
</View>
|
||||
<Text>:</Text>
|
||||
<View className="bg-btnPrimary h-8 w-8 flex justify-center items-center rounded-lg">
|
||||
<Text className="text-primary">{endDate.minutes}</Text>
|
||||
</View>
|
||||
<Text>:</Text>
|
||||
<View className="bg-btnPrimary h-8 w-8 flex justify-center items-center rounded-lg">
|
||||
<Text className="text-primary">{endDate.seconds}</Text>
|
||||
</View>
|
||||
</View> : <></>
|
||||
}
|
||||
</View>
|
||||
<ScrollView
|
||||
horizontal
|
||||
showsHorizontalScrollIndicator={false}
|
||||
>
|
||||
{
|
||||
subCategory.map((item, index) => {
|
||||
let isActive = item == activeSet;
|
||||
return (
|
||||
<TouchableOpacity
|
||||
onPress={() => handleSubCategory(item)}
|
||||
key={index}
|
||||
className={`
|
||||
border border-gray-500 px-4 ml-4 mb-4 rounded-full py-2
|
||||
${isActive ? "bg-primary" : ""}
|
||||
`}>
|
||||
<Text className={`font-bold ${isActive ? "text-white" : ""}`}>
|
||||
{item}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
)
|
||||
})
|
||||
}
|
||||
</ScrollView>
|
||||
<MasonryList
|
||||
data={data}
|
||||
keyExtractor={(item) => item.id}
|
||||
numColumns={2}
|
||||
showsVerticalScrollIndicator={false}
|
||||
renderItem={({ item, index }) => (
|
||||
<CardItem
|
||||
item={item}
|
||||
index={index}
|
||||
handleFavouriteToggle={() => handleFavouriteToggle(item)}
|
||||
isFavourite={isProductFavorited(item.id)}
|
||||
navigation={navigation}
|
||||
/>
|
||||
)}
|
||||
className="mx-4"
|
||||
/>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
const calenderLastDate = (saleEnd) => {
|
||||
const nowDate = new Date();
|
||||
const saleEndDate = new Date(saleEnd)
|
||||
const total = Math.floor(saleEndDate - nowDate)
|
||||
|
||||
const days = Math.floor(total / (1000 * 60 * 60 * 24))
|
||||
const hours = Math.floor(total / (1000 * 60 * 60) % 24)
|
||||
const minutes = Math.floor(total / (1000 * 60) % 60)
|
||||
const seconds = Math.floor(total / (1000) % 60)
|
||||
|
||||
return {
|
||||
total: total,
|
||||
days: Math.max(0, days),
|
||||
hours: Math.max(0, hours),
|
||||
minutes: Math.max(0, minutes),
|
||||
seconds: Math.max(0, seconds),
|
||||
}
|
||||
}
|
||||
|
||||
const CardItem = ({ item, index, handleFavouriteToggle, isFavourite, navigation }) => {
|
||||
let isEven = item.id % 2 == 0
|
||||
|
||||
const getRating = () => {
|
||||
if (item.rating) {
|
||||
if (typeof item.rating === 'object' && item.rating.rate !== undefined) {
|
||||
return item.rating.rate;
|
||||
}
|
||||
if (typeof item.rating === 'number') {
|
||||
return item.rating;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.average_rating !== undefined) {
|
||||
return item.average_rating;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (
|
||||
<View className={`${isEven ? "pl-4" : " pr-4"} flex-col gap-3 mb-4`}>
|
||||
<TouchableOpacity onPress={() => { navigation.navigate('ProductDetails',{id:item.id,}) }} className="relative">
|
||||
<Image source={{ uri: item.image }} height={hp(20)} className=" object-cover rounded-3xl" />
|
||||
<TouchableOpacity
|
||||
onPress={(e) => {
|
||||
e.stopPropagation();
|
||||
handleFavouriteToggle();
|
||||
}}
|
||||
className="absolute right-4 top-4 bg-white/50 p-2 rounded-full"
|
||||
>
|
||||
{
|
||||
isFavourite ?
|
||||
<Icon name='heart' size={16} color={"red"} />
|
||||
:
|
||||
<HeartIcon size={20} color={"white"} />
|
||||
}
|
||||
</TouchableOpacity>
|
||||
</TouchableOpacity>
|
||||
<View className="flex-row justify-between px-1">
|
||||
<Text className={`flex-1`}>{item.name || item.title}</Text>
|
||||
<View className="flex-row gap-1 ">
|
||||
<StarIcon size={20} color={"orange"} />
|
||||
<Text>{getRating()}</Text>
|
||||
</View>
|
||||
</View>
|
||||
<View className="px-1 ">
|
||||
<Text className="font-medium">Rs {item.price}</Text>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
export default FlashSales
|
||||
@@ -0,0 +1,48 @@
|
||||
import { View, Text, Image } from 'react-native'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import PagerView from 'react-native-pager-view';
|
||||
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen';
|
||||
|
||||
const HomeCarousel = ({ setPage, slider }) => {
|
||||
return (
|
||||
<PagerView
|
||||
style={{ flex: 1 }}
|
||||
initialPage={0}
|
||||
scrollEnabled={true}
|
||||
|
||||
// overdrag={true}
|
||||
// overScrollMode={'always'}
|
||||
onPageSelected={(e) => setPage(e.nativeEvent.position)}
|
||||
>
|
||||
{
|
||||
slider.map((item, index) => {
|
||||
return (
|
||||
<View key={index} className={`justify-center items-center bg-[#ece4da] mx-4 mb-3 rounded-xl flex-1`} >
|
||||
<View className={`flex-row justify-between flex-1 p-4`}>
|
||||
<View className={`justify-center gap-3 items- w-1/2`}>
|
||||
<Text className={`capitalize font-semibold text-xl`}>{item.title}</Text>
|
||||
<Text className={`capitalize text-[#797979]`}>{item.description}</Text>
|
||||
<View className={`justify-center items-start`}>
|
||||
<View className={`px-3 py-2 bg-primary w-fit rounded-lg`}>
|
||||
<Text className={`text-white font-bold`}>Shop Now</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
<Image
|
||||
source={{ uri: "https://cdn.clo3d.com/resource/images/artwork/landing/watermark_landing_sustainably_renewal_1920.png" }}
|
||||
className={`w-1/2 h-full`}
|
||||
style={{}}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
</PagerView>
|
||||
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
export default HomeCarousel
|
||||
@@ -0,0 +1,73 @@
|
||||
import React from 'react';
|
||||
import { View, Text, Image, StyleSheet, TouchableOpacity } from 'react-native';
|
||||
import Icon from 'react-native-vector-icons/FontAwesome';
|
||||
|
||||
const ItemCard = ({ item, onPress, onFavoritePress, isFavourite }) => (
|
||||
<View style={styles.card}>
|
||||
<TouchableOpacity onPress={onPress}>
|
||||
<Image source={{ uri: item.image }} style={styles.image} />
|
||||
<TouchableOpacity
|
||||
style={styles.heartButton}
|
||||
onPress={onFavoritePress}
|
||||
>
|
||||
<Icon
|
||||
name={isFavourite ? "heart" : "heart-o"}
|
||||
size={20}
|
||||
color={isFavourite ? "#ff0000" : "#333"}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
</TouchableOpacity>
|
||||
<Text style={styles.title}>{item.title}</Text>
|
||||
<Text style={styles.price}>${item.price}</Text>
|
||||
<View style={styles.ratingContainer}>
|
||||
<Text style={styles.rating}>{item.rating}</Text>
|
||||
<Icon name="star" size={16} color="#f5a623" />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
card: {
|
||||
backgroundColor: '#fff',
|
||||
margin: 10,
|
||||
borderRadius: 10,
|
||||
elevation: 2,
|
||||
flex: 1,
|
||||
alignItems: 'center',
|
||||
padding: 10,
|
||||
},
|
||||
image: {
|
||||
width: '100%',
|
||||
height: 150,
|
||||
borderRadius: 8,
|
||||
},
|
||||
heartButton: {
|
||||
position: 'absolute',
|
||||
top: 10,
|
||||
right: 10,
|
||||
padding: 5,
|
||||
},
|
||||
title: {
|
||||
fontSize: 16,
|
||||
fontWeight: 'bold',
|
||||
marginTop: 8,
|
||||
},
|
||||
price: {
|
||||
fontWeight: 'bold',
|
||||
fontSize: 16,
|
||||
color: '#555',
|
||||
marginTop: 4,
|
||||
},
|
||||
ratingContainer: {
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
marginTop: 4,
|
||||
},
|
||||
rating: {
|
||||
fontSize: 14,
|
||||
marginRight: 4,
|
||||
color: '#f5a623',
|
||||
},
|
||||
});
|
||||
|
||||
export default ItemCard;
|
||||
@@ -0,0 +1,46 @@
|
||||
import { View, Text, TouchableOpacity } from 'react-native'
|
||||
import React from 'react'
|
||||
import { MinusIcon, PlusIcon } from 'react-native-heroicons/outline'
|
||||
|
||||
/**
|
||||
* A reusable component for quantity selection with plus and minus buttons
|
||||
*
|
||||
* @param {Object} props Component props
|
||||
* @param {number} props.quantity Current quantity value
|
||||
* @param {Function} props.onIncrease Function to call when increasing quantity
|
||||
* @param {Function} props.onDecrease Function to call when decreasing quantity
|
||||
* @param {string} props.label Label text to display (optional)
|
||||
* @param {Object} props.containerStyle Additional styles for the container
|
||||
* @returns {React.Component} Quantity selector component
|
||||
*/
|
||||
export default function ProductQuantityInput({
|
||||
quantity = 1,
|
||||
onIncrease,
|
||||
onDecrease,
|
||||
label = "Quantity",
|
||||
containerStyle = {}
|
||||
}) {
|
||||
return (
|
||||
<View style={containerStyle}>
|
||||
{label && <Text className="text-[17px] font-medium mb-2">{label}</Text>}
|
||||
<View className="flex-row items-center">
|
||||
<TouchableOpacity
|
||||
onPress={onDecrease}
|
||||
className={`bg-primary/40 rounded-lg p-1 ${quantity <= 1 ? 'opacity-50' : ''}`}
|
||||
disabled={quantity <= 1}
|
||||
>
|
||||
<MinusIcon color={quantity <= 1 ? "gray" : "black"} size={25} />
|
||||
</TouchableOpacity>
|
||||
|
||||
<Text className="mx-4 text-xl">{quantity}</Text>
|
||||
|
||||
<TouchableOpacity
|
||||
onPress={onIncrease}
|
||||
className="bg-primary rounded-lg p-1"
|
||||
>
|
||||
<PlusIcon color="white" size={25} />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user