From 31d73143ff140fde68a7552c656cac9e431fd5bc Mon Sep 17 00:00:00 2001 From: iamtrazy Date: Wed, 4 Dec 2024 01:27:26 +0530 Subject: [PATCH] fix: UI enhancements --- src/components/User/Discount/index.tsx | 124 ++++++++++++------------ src/components/User/FoodCombo/index.tsx | 27 +++++- 2 files changed, 85 insertions(+), 66 deletions(-) diff --git a/src/components/User/Discount/index.tsx b/src/components/User/Discount/index.tsx index 16967a1..ab2e33a 100644 --- a/src/components/User/Discount/index.tsx +++ b/src/components/User/Discount/index.tsx @@ -1,25 +1,38 @@ -import { useEffect, useState } from 'react'; -import { Link } from 'react-router-dom'; -import TextButton from './TextButton'; -import { useDiscount } from '@/api/useDiscount'; -import { Discount } from '@/types/discount'; +import { useQuery } from '@tanstack/react-query'; +import { useFoods } from '@/api/useFoodItem'; +import { useCombos } from '@/api/useFoodCombo'; +import { Food } from '@/types/food'; +import { FoodCombo } from '@/types/combo'; +import Item from '../AllMenuItems/ItemList'; function index() { - const { getAllDiscounts } = useDiscount(); - const [discount, setDiscount] = useState([]); + const { getAllFoods } = useFoods(); + const { getAllCombos } = useCombos(); - const fetchDiscount = async () => { - try { - const data = await getAllDiscounts(); - setDiscount(data); - } catch (error: any) { - console.error(error); - } - }; + const foodQuery = useQuery({ + queryKey: ['foods'], + queryFn: getAllFoods, + }); - useEffect(() => { - fetchDiscount(); - }, []); + const comboQuery = useQuery({ + queryKey: ['combos'], + queryFn: getAllCombos, + }); + + if (foodQuery.isLoading || comboQuery.isLoading) { + return
Loading...
; + } + + if (foodQuery.isError || comboQuery.isError) { + return
Error loading items
; + } + + const foods: Food[] = foodQuery.data.filter( + (food: Food) => food.discountStatus, + ); + const combos: FoodCombo[] = comboQuery.data.filter( + (combo: FoodCombo) => combo.discountStatus, + ); return (
@@ -27,53 +40,38 @@ function index() { Promotions
- Enjoy great savings with exclusive deals and offers available on your favorite items. + Enjoy great savings with exclusive deals and offers available on your + favorite items.
-
- {discount.map((item: any) => { - return ( - -
- {item[0].limited === 1 && ( -
-

- LIMITED TIME -

-
- )} - -
- -
- -
-
-

- - {item[0].name} - -

-

{item[0].branch}

-
- -
- -
-
-
- - ); - })} +
+ {foods.map((food: Food) => ( + + ))} + {combos.map((combo: FoodCombo) => ( + + ))}
); diff --git a/src/components/User/FoodCombo/index.tsx b/src/components/User/FoodCombo/index.tsx index 54318d5..ed12d98 100644 --- a/src/components/User/FoodCombo/index.tsx +++ b/src/components/User/FoodCombo/index.tsx @@ -36,6 +36,7 @@ function FoodComboForm({ id }: Props) { const [combo, setFoodCombo] = useState(); const [price, setPrice] = useState(1); const [additionalPrices, setAdditionalPrices] = useState(0); + const [currentRating, setCurrentRating] = useState(4); const { handleSubmit, @@ -115,6 +116,11 @@ function FoodComboForm({ id }: Props) { setAdditionalPrices((prev) => prev + priceDelta); }; + const handleStarClick = (starIndex: number) => { + setCurrentRating(starIndex + 1); + showSwal(); + }; + if (!combo) { return
Loading...
; } @@ -123,8 +129,17 @@ function FoodComboForm({ id }: Props) { return (
+ +
{combo.name}
{combo.description}
-
+
{Array.from({ length: 5 }).map((_, i) => ( - +
handleStarClick(i)} + > + +
))}