import React, { useState, useEffect } from 'react';
import { Search, ShoppingCart, User, Home, Clock, Star, ChevronDown, ChevronUp, X, Plus, Minus, MapPin, CreditCard, Phone } from 'lucide-react';
// Mock data for restaurants
const restaurantsData = [
{
id: 1,
name: "Habesha Restaurant",
cuisine: "Ethiopian",
rating: 4.8,
deliveryTime: "25-35",
deliveryFee: 30,
minOrder: 100,
image: "https://images.unsplash.com/photo-1567360425618-1594206637d2?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60",
featured: true
},
{
id: 2,
name: "Yod Abyssinia",
cuisine: "Traditional",
rating: 4.6,
deliveryTime: "30-45",
deliveryFee: 25,
minOrder: 150,
image: "https://images.unsplash.com/photo-1544025162-d76694265947?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60"
},
{
id: 3,
name: "Pizza Hut",
cuisine: "Italian",
rating: 4.3,
deliveryTime: "20-30",
deliveryFee: 35,
minOrder: 120,
image: "https://images.unsplash.com/photo-1513104890138-7c749659a591?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60"
},
{
id: 4,
name: "Burger House",
cuisine: "Fast Food",
rating: 4.2,
deliveryTime: "15-25",
deliveryFee: 20,
minOrder: 80,
image: "https://images.unsplash.com/photo-1550547660-d9450f859349?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60"
},
{
id: 5,
name: "Kategna",
cuisine: "Ethiopian",
rating: 4.7,
deliveryTime: "35-50",
deliveryFee: 40,
minOrder: 200,
image: "https://images.unsplash.com/photo-1511910849309-0dffb8785146?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60"
},
{
id: 6,
name: "Kaldi's Coffee",
cuisine: "Cafe",
rating: 4.5,
deliveryTime: "20-30",
deliveryFee: 15,
minOrder: 50,
image: "https://images.unsplash.com/photo-1495474472287-4d71bcdd2085?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60"
}
];
// Mock data for menu items
const menuItemsData = {
1: [
{
id: 101,
name: "Doro Wat",
description: "Spicy chicken stew served with injera",
price: 180,
image: "https://images.unsplash.com/photo-1567360425618-1594206637d2?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60",
category: "Main Dishes",
customizations: [
{
id: 1,
name: "Spice Level",
required: true,
options: [
{ id: 1, name: "Mild", price: 0 },
{ id: 2, name: "Medium", price: 0 },
{ id: 3, name: "Spicy", price: 0 }
]
},
{
id: 2,
name: "Add-ons",
required: false,
options: [
{ id: 4, name: "Extra Injera", price: 20 },
{ id: 5, name: "Ayib (Ethiopian Cheese)", price: 35 }
]
}
]
},
{
id: 102,
name: "Tibs",
description: "Sautéed meat with vegetables and spices",
price: 200,
image: "https://images.unsplash.com/photo-1567360425618-1594206637d2?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60",
category: "Main Dishes",
customizations: [
{
id: 3,
name: "Meat Type",
required: true,
options: [
{ id: 6, name: "Beef", price: 0 },
{ id: 7, name: "Lamb", price: 30 }
]
}
]
},
{
id: 103,
name: "Shiro",
description: "Spiced chickpea stew",
price: 120,
image: "https://images.unsplash.com/photo-1567360425618-1594206637d2?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60",
category: "Vegetarian",
customizations: []
},
{
id: 104,
name: "Kitfo",
description: "Minced raw beef seasoned with spices",
price: 220,
image: "https://images.unsplash.com/photo-1567360425618-1594206637d2?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60",
category: "Main Dishes",
customizations: [
{
id: 4,
name: "Cooking Level",
required: true,
options: [
{ id: 8, name: "Raw (Traditional)", price: 0 },
{ id: 9, name: "Lightly Cooked", price: 0 },
{ id: 10, name: "Well Done", price: 0 }
]
}
]
},
{
id: 105,
name: "Ethiopian Coffee Ceremony",
description: "Traditional coffee service with popcorn",
price: 150,
image: "https://images.unsplash.com/photo-1567360425618-1594206637d2?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60",
category: "Beverages",
customizations: [
{
id: 5,
name: "Size",
required: true,
options: [
{ id: 11, name: "Small (2 people)", price: 0 },
{ id: 12, name: "Medium (4 people)", price: 50 },
{ id: 13, name: "Large (6 people)", price: 100 }
]
}
]
}
]
};
// Mock user data
const userData = {
name: "Abebe Kebede",
email: "abebe@example.com",
phone: "+251912345678",
addresses: [
{
id: 1,
name: "Home",
address: "Bole Road, Addis Ababa",
isDefault: true
},
{
id: 2,
name: "Work",
address: "Meskel Square, Addis Ababa",
isDefault: false
}
]
};
// Main App Component
export default function FoodDeliveryApp() {
const [activeTab, setActiveTab] = useState('home');
const [selectedRestaurant, setSelectedRestaurant] = useState(null);
const [cart, setCart] = useState([]);
const [isAuthenticated, setIsAuthenticated] = useState(false);
const [showLoginModal, setShowLoginModal] = useState(false);
const [showCartModal, setShowCartModal] = useState(false);
const [showItemModal, setShowItemModal] = useState(false);
const [selectedItem, setSelectedItem] = useState(null);
const [selectedCustomizations, setSelectedCustomizations] = useState({});
const [searchQuery, setSearchQuery] = useState('');
const [cuisineFilter, setCuisineFilter] = useState('All');
const [checkoutStep, setCheckoutStep] = useState(0);
const [orderPlaced, setOrderPlaced] = useState(false);
const [orderStatus, setOrderStatus] = useState('');
const [showPaymentModal, setShowPaymentModal] = useState(false);
const [paymentMethod, setPaymentMethod] = useState('telebirr');
// Filter restaurants based on search and cuisine
const filteredRestaurants = restaurantsData.filter(restaurant => {
const matchesSearch = restaurant.name.toLowerCase().includes(searchQuery.toLowerCase());
const matchesCuisine = cuisineFilter === 'All' || restaurant.cuisine === cuisineFilter;
return matchesSearch && matchesCuisine;
});
// Get unique cuisines for filter
const cuisines = ['All', ...new Set(restaurantsData.map(r => r.cuisine))];
// Calculate cart total
const cartTotal = cart.reduce((total, item) => {
let itemTotal = item.price * item.quantity;
// Add customization costs
if (item.selectedOptions) {
Object.values(item.selectedOptions).forEach(option => {
if (option && option.price) {
itemTotal += option.price;
}
});
}
return total + itemTotal;
}, 0);
const deliveryFee = selectedRestaurant ? selectedRestaurant.deliveryFee : 0;
const tax = Math.round(cartTotal * 0.15); // 15% tax
const orderTotal = cartTotal + deliveryFee + tax;
// Handle adding item to cart
const addToCart = () => {
if (!selectedItem) return;
const newItem = {
...selectedItem,
quantity: 1,
selectedOptions: selectedCustomizations
};
setCart([...cart, newItem]);
setShowItemModal(false);
setSelectedCustomizations({});
};
// Handle removing item from cart
const removeFromCart = (index) => {
const newCart = [...cart];
newCart.splice(index, 1);
setCart(newCart);
};
// Handle quantity change
const updateQuantity = (index, delta) => {
const newCart = [...cart];
const newQuantity = newCart[index].quantity + delta;
if (newQuantity > 0) {
newCart[index].quantity = newQuantity;
setCart(newCart);
} else {
removeFromCart(index);
}
};
// Handle customization selection
const handleCustomizationChange = (customizationId, option) => {
setSelectedCustomizations({
...selectedCustomizations,
[customizationId]: option
});
};
// Handle checkout process
const proceedToCheckout = () => {
if (!isAuthenticated) {
setShowLoginModal(true);
return;
}
setShowCartModal(false);
setCheckoutStep(1);
setActiveTab('checkout');
};
// Handle order placement
const placeOrder = () => {
setShowPaymentModal(true);
};
// Handle payment completion
const completePayment = () => {
setShowPaymentModal(false);
setOrderPlaced(true);
setOrderStatus('confirmed');
setCart([]);
// Simulate order status updates
setTimeout(() => setOrderStatus('preparing'), 5000);
setTimeout(() => setOrderStatus('ready'), 10000);
setTimeout(() => setOrderStatus('delivering'), 15000);
setTimeout(() => setOrderStatus('delivered'), 25000);
};
// Handle login
const handleLogin = (e) => {
e.preventDefault();
setIsAuthenticated(true);
setShowLoginModal(false);
};
// Reset to home view
const goToHome = () => {
setActiveTab('home');
setSelectedRestaurant(null);
setCheckoutStep(0);
setOrderPlaced(false);
};
// Open item modal
const openItemModal = (item) => {
setSelectedItem(item);
setSelectedCustomizations({});
setShowItemModal(true);
};
return (
{/* Header */}
{/* Main Content */}
{/* Home Tab - Restaurant Listing */}
{activeTab === 'home' && !selectedRestaurant && (
{/* Cuisine Filters */}
{cuisines.map(cuisine => (
))}
{/* Featured Restaurant */}
{cuisineFilter === 'All' && searchQuery === '' && (
Featured Restaurant
{restaurantsData[0].name}
{restaurantsData[0].rating}
{restaurantsData[0].cuisine}
{restaurantsData[0].deliveryTime} min
)}
{/* Restaurant Grid */}
All Restaurants
{filteredRestaurants.length === 0 ? (
No restaurants found matching your criteria.
) : (
{filteredRestaurants.map(restaurant => (
setSelectedRestaurant(restaurant)}
>
{restaurant.name}
{restaurant.cuisine}
•
{restaurant.rating}
{restaurant.deliveryTime} min
{restaurant.deliveryFee} ETB delivery
))}
)}
)}
{/* Restaurant Detail View */}
{activeTab === 'home' && selectedRestaurant && (
{/* Restaurant Header */}
{selectedRestaurant.name}
{selectedRestaurant.cuisine}
•
{selectedRestaurant.rating}
•
{selectedRestaurant.deliveryTime} min
Minimum order: {selectedRestaurant.minOrder} ETB • Delivery fee: {selectedRestaurant.deliveryFee} ETB
{/* Menu Categories */}
{/* Menu Categories Sidebar */}
Menu Categories
{['Main Dishes', 'Vegetarian', 'Beverages'].map(category => (
-
{category}
))}
{/* Menu Items */}
{['Main Dishes', 'Vegetarian', 'Beverages'].map(category => {
const categoryItems = menuItemsData[selectedRestaurant.id]?.filter(
item => item.category === category
) || [];
if (categoryItems.length === 0) return null;
return (
{category}
{categoryItems.map(item => (
openItemModal(item)}
>
{item.name}
{item.description}
{item.price} ETB
{item.customizations.length > 0 && (
Customizable
)}
))}
);
})}
)}
{/* Checkout Flow */}
{activeTab === 'checkout' && (
{!orderPlaced ? (
Checkout
{/* Checkout Steps */}
{['Delivery Address', 'Payment Method', 'Review Order'].map((step, index) => (
{index < checkoutStep ? '✓' : index + 1}
{step}
))}
{/* Step 1: Delivery Address */}
{checkoutStep === 0 && (
Select Delivery Address
{userData.addresses.map(address => (
))}
)}
{/* Step 2: Payment Method */}
{checkoutStep === 1 && (
Select Payment Method
)}
{/* Step 3: Review Order */}
{checkoutStep === 2 && (
Review Your Order
{/* Delivery Details */}
Delivery Details
{userData.addresses[0].name}
{userData.addresses[0].address}
{/* Payment Method */}
Payment Method
{paymentMethod === 'telebirr' ? (
<>
Telebirr
>
) : paymentMethod === 'mobile-banking' ? (
<>
Mobile Banking
>
) : (
<>
Cash on Delivery
>
)}
{/* Order Items */}
Order Items
{cart.map((item, index) => (
{item.quantity}x
{item.name}
{item.price * item.quantity} ETB
))}
{/* Order Summary */}
Order Summary
Subtotal
{cartTotal} ETB
Delivery Fee
{deliveryFee} ETB
Tax (15%)
{tax} ETB
Total
{orderTotal} ETB
)}
) : (
Order Placed Successfully!
Your order has been confirmed and is being processed.
{/* Order Status */}
Order Confirmed
Your order has been received by the restaurant
Preparing Your Food
The restaurant is preparing your order
Ready for Pickup
Your order is ready and waiting for a driver
On the Way
Your order is on the way to your location
Delivered
Enjoy your meal!
)}
)}
{/* Profile Tab */}
{activeTab === 'profile' && (
My Profile
{userData.name.split(' ').map(n => n[0]).join('')}
{userData.name}
{userData.phone}
{userData.email}
My Addresses
{userData.addresses.map(address => (
{address.name}
{address.isDefault && (
Default
)}
{address.address}
))}
Payment Methods
Telebirr
Connected to {userData.phone}
Order History
Habesha Restaurant
2 items • 400 ETB
Yesterday, 7:30 PM
Delivered
Pizza Hut
3 items • 550 ETB
May 15, 2023, 1:15 PM
Delivered
)}
{/* Bottom Navigation */}
{/* Login Modal */}
{showLoginModal && (
Login or Sign Up
)}
{/* Cart Modal */}
{showCartModal && (
Your Cart
{cart.length === 0 ? (
Your cart is empty
Add items from a restaurant to get started
) : (
<>
{selectedRestaurant?.name || 'Your Items'}
{cart.map((item, index) => (
{item.name}
{item.price * item.quantity} ETB
{/* Item customizations */}
{item.selectedOptions && Object.keys(item.selectedOptions).length > 0 && (
{Object.values(item.selectedOptions).map((option, i) => (
{option.name}
{option.price > 0 && +{option.price} ETB}
))}
)}
{item.quantity}
))}
Subtotal
{cartTotal} ETB
Delivery Fee
{deliveryFee} ETB
Tax (15%)
{tax} ETB
Total
{orderTotal} ETB
>
)}
)}
{/* Item Detail Modal */}
{showItemModal && selectedItem && (
{selectedItem.name}
{selectedItem.description}
{selectedItem.price} ETB
{/* Customizations */}
{selectedItem.customizations.length > 0 && (
{selectedItem.customizations.map(customization => (
{customization.name}
{customization.required && (
*
)}
{customization.options.map(option => (
handleCustomizationChange(customization.id, option)}
>
{}}
className="mr-3"
/>
{option.name}
{option.price > 0 && (
+{option.price} ETB
)}
))}
))}
)}
)}
{/* Telebirr Payment Modal */}
{showPaymentModal && (
Complete Payment
{orderTotal} ETB
Pay using your Telebirr account
To complete your payment, follow these steps:
-
1
Open your Telebirr mobile app
-
2
Select "Pay" and scan the QR code or enter the merchant ID: 123456
-
3
Enter the amount: {orderTotal} ETB
-
4
Confirm the payment with your PIN
)}
);
}