Skip to content

Commit

Permalink
fix: cart Api
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtrazy committed Jul 26, 2024
1 parent 3ecd874 commit e5ce4fd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 42 deletions.
Empty file added src/api/useCart.tsx
Empty file.
88 changes: 49 additions & 39 deletions src/components/User/FoodItem/TextButtonGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,59 @@
import { useState } from "react";
import { Button, ButtonGroup } from "@nextui-org/react";
import { useState } from 'react';
import { Button, ButtonGroup } from '@nextui-org/react';

interface Props {
name: string;
levels: string[];
defaultPrice: number;
prices: number[];
setPrice: (newPrice: number) => void;
name: string;
levels: string[];
defaultPrice: number;
prices: number[];
setPrice: (newPrice: number) => void;
}

export default function TextButtonGroup({ name, levels, defaultPrice, prices, setPrice }: Props) {
const [selectedIndex, setSelectedIndex] = useState<number | null>(null);
export default function TextButtonGroup({
name,
levels,
defaultPrice,
prices,
setPrice,
}: Props) {
const [selectedIndex, setSelectedIndex] = useState<number | null>(null);

const handleIncrement = (index: number) => {
setPrice(defaultPrice + prices[index]);
setSelectedIndex(index);
console.log(defaultPrice);
};
const handleIncrement = (index: number) => {
setPrice(defaultPrice + prices[index]);
setSelectedIndex(index);
console.log(defaultPrice);
};

return (
<div className='flex mt-8'>
<div className='text-white mt-2'>
<b>{name}:</b>
</div>
<ButtonGroup className='ml-5'>
{levels.map((level, index) => {
let buttonClass = 'border duration-300 hover:bg-foodbg';
return (
<div className="flex mt-8">
<div className="text-white mt-2">
<b>{name}:</b>
</div>
<ButtonGroup className="ml-5">
{levels.map((level, index) => {
let buttonClass = 'border duration-300 hover:bg-foodbg';

if (index === 0) {
buttonClass += ' rounded-l-lg';
} else if (index === levels.length - 1) {
buttonClass += ' rounded-r-lg';
}
if (index === 0) {
buttonClass += ' rounded-l-lg';
} else if (index === levels.length - 1) {
buttonClass += ' rounded-r-lg';
}

if (selectedIndex === index) {
buttonClass += ' bg-foodbg text-white';
}
if (selectedIndex === index) {
buttonClass += ' bg-foodbg text-white';
}

return (
<Button key={index} className={buttonClass} onClick={() => handleIncrement(index)}>
{level}
</Button>
);
})}
</ButtonGroup>
</div>
);
return (
<Button
key={index}
className={buttonClass}
onClick={() => handleIncrement(index)}
>
{level}({prices[index]})
</Button>
);
})}
</ButtonGroup>
</div>
);
}
7 changes: 4 additions & 3 deletions src/components/User/FoodItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ function index({ id }: Props) {
try {
const food = await getFoodById(id?.toString() || '');
setFood(food);
console.log(food);
console.log(food.price);
setPrice(food.price);
} catch (error) {
console.error('Error fetching item:', error);
Expand Down Expand Up @@ -62,12 +64,11 @@ function index({ id }: Props) {

<div className="font-bold text-white pt-5 text-2xl">
<span className="pr-2 text-orange-500">Rs.</span>
{price*count}
{price * count}
</div>

<div>
<QtySelector count={count} setCount={setCount} />

<QtySelector count={count} setCount={setCount} />

<div className="mt-8">
{food.features.map((feature: any, index: number) => (
Expand Down

0 comments on commit e5ce4fd

Please sign in to comment.