mirror of
https://github.com/0xShay/ticketchain.git
synced 2026-01-11 13:13:25 +00:00
add num tickets
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Card,
|
||||
CardHeader,
|
||||
@@ -32,8 +32,10 @@ const EventDescription: React.FC<EventDescriptionProps> = ({
|
||||
eventDetails,
|
||||
}) => {
|
||||
const { toast } = useToast();
|
||||
const [numTickets, setNumTickets] = useState(1);
|
||||
|
||||
const handleBuyNow = () => {
|
||||
buyHandler(eventDetails.EventID, toast);
|
||||
buyHandler(eventDetails.EventID, numTickets, toast);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -79,7 +81,10 @@ const EventDescription: React.FC<EventDescriptionProps> = ({
|
||||
</Button>
|
||||
<div className="relative md:left-5">
|
||||
<NumberPicker
|
||||
initialCount={numTickets}
|
||||
min={1}
|
||||
max={eventDetails.capacity - eventDetails.ticketsSold}
|
||||
onChange={setNumTickets}
|
||||
/>
|
||||
</div>
|
||||
</CardFooter>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
'use client';
|
||||
import React, { useState } from 'react';
|
||||
import { Button } from '../ui/button'; // Adjust import path to where your shadcn Button component is located
|
||||
import React from 'react';
|
||||
import { Button } from '../ui/button';
|
||||
|
||||
interface NumberPickerProps {
|
||||
initialCount?: number;
|
||||
@@ -15,25 +14,23 @@ const NumberPicker: React.FC<NumberPickerProps> = ({
|
||||
max = 10,
|
||||
onChange,
|
||||
}) => {
|
||||
const [count, setCount] = useState<number>(initialCount);
|
||||
const [count, setCount] = React.useState(initialCount);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (onChange) {
|
||||
onChange(count);
|
||||
}
|
||||
}, [count, onChange]);
|
||||
|
||||
const increment = () => {
|
||||
if (count < max) {
|
||||
const newCount = count + 1;
|
||||
setCount(newCount);
|
||||
if (onChange) {
|
||||
onChange(newCount);
|
||||
}
|
||||
setCount(count + 1);
|
||||
}
|
||||
};
|
||||
|
||||
const decrement = () => {
|
||||
if (count > min) {
|
||||
const newCount = count - 1;
|
||||
setCount(newCount);
|
||||
if (onChange) {
|
||||
onChange(newCount);
|
||||
}
|
||||
setCount(count - 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user