From 6ea3b151c37d8fc4809599f0b6accb8adb78a8d9 Mon Sep 17 00:00:00 2001 From: Brian Nelson Date: Mon, 28 Jul 2025 08:10:07 -0400 Subject: [PATCH] creavte venue inside create event --- components/dashboard/DashboardEvents.tsx | 75 +++++++---- components/dialogs/DialogWrapper.tsx | 2 +- components/forms/CreateEventForm.tsx | 153 +++++++++++++++++++++++ components/forms/CreateVenueForm.tsx | 9 +- 4 files changed, 208 insertions(+), 31 deletions(-) create mode 100644 components/forms/CreateEventForm.tsx diff --git a/components/dashboard/DashboardEvents.tsx b/components/dashboard/DashboardEvents.tsx index 3d9aa8c..8c21830 100644 --- a/components/dashboard/DashboardEvents.tsx +++ b/components/dashboard/DashboardEvents.tsx @@ -1,8 +1,11 @@ -import React from 'react' +'use client' +import React, { useState } from 'react' import { Card, CardContent, CardFooter, CardHeader, CardTitle } from '../ui/card' import { Button } from '../ui/button' import Link from 'next/link' import EventInfoQuickView from '../EventInfoQuickView' +import DialogWrapper from '../dialogs/DialogWrapper' +import CreateEventForm from '../forms/CreateEventForm' interface EventsProps { events: { @@ -20,32 +23,50 @@ interface EventsProps { } export default function DashboardEvents({events}: EventsProps) { + const [isDialogOpen, setIsDialogOpen] = useState(false) + return ( - - -
- - Your Events - - -
-
- -
- {events.map((item) => ( - - ))} -
-
- -
- View all -
-
-
+ <> + + +
+ + Your Events + + +
+
+ +
+ {events.map((item) => ( + + ))} +
+
+ +
+ View all +
+
+
+ { + // await refreshEventData(event.id) + setIsDialogOpen(false) + }} + /> + } + /> + ) } diff --git a/components/dialogs/DialogWrapper.tsx b/components/dialogs/DialogWrapper.tsx index afa6db0..f134125 100644 --- a/components/dialogs/DialogWrapper.tsx +++ b/components/dialogs/DialogWrapper.tsx @@ -18,7 +18,7 @@ export default function DialogWrapper({ }) { return ( - e.preventDefault()}> + e.preventDefault()} className="max-h-[90vh] overflow-y-auto w-full max-w-3xl"> {title} {description} diff --git a/components/forms/CreateEventForm.tsx b/components/forms/CreateEventForm.tsx new file mode 100644 index 0000000..defcf67 --- /dev/null +++ b/components/forms/CreateEventForm.tsx @@ -0,0 +1,153 @@ +'use client' + +import React, { useEffect, useState } from 'react' +import { toast } from 'sonner' +import { Label } from '../ui/label' +import { Input } from '../ui/input' +import { Button } from '../ui/button' +import CreateVenueForm from './CreateVenueForm' +import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '../ui/dialog' + +interface CreateEventFormProps { + onSuccess?: () => void +} + +export default function CreateEventForm({ onSuccess }: CreateEventFormProps) { + const [formData, setFormData] = useState({ + name: '', + date: '', + venueId: '' + }) + + const [venues, setVenues] = useState<{ id: string; name: string }[]>([]) + // const [showVenueForm, setShowVenueForm] = useState(false) + const [venueDialogOpen, setVenueDialogOpen] = useState(false) + + useEffect(() => { + async function fetchVenues() { + const res = await fetch('/api/venues/fetch') + const data = await res.json() + setVenues(data) + } + fetchVenues() + }, []) + + function handleChange(e: React.ChangeEvent) { + const { name, value } = e.target + setFormData(prev => ({ ...prev, [name]: value })) + } + + async function handleSubmit(e: React.FormEvent) { + e.preventDefault() + if (!formData.name || !formData.date) { + toast.error('Event Name and Date are required') + return + } + + try { + const res = await fetch('/api/events/create', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + name: formData.name, + date: formData.date, + venueId: formData.venueId || null + }) + }) + + if (!res.ok) throw new Error('Failed to create event') + + toast.success('Event created!') + if (onSuccess) onSuccess() + } catch (err) { + toast.error('Something went wrong') + console.error(err) + } + } + + return ( + <> +
+ + {/* Event Details */} +
+
+ + +
+ +
+ + +
+
+ + {/* Venue Selection */} +
+ + + +
+ + {/* Submit */} + +
+ + e.preventDefault()}> + + Create New Venue + Fill in venue details + + { + // 1. Close the dialog + setVenueDialogOpen(false) + + // 2. Refresh venues list + const res = await fetch('/api/venues/fetch') + const updated = await res.json() + setVenues(updated) + + // 3. Update formData with new venue + setFormData(prev => ({ + ...prev, + venueId: newVenueId || '' + })) + }} + /> + + + + + ) +} diff --git a/components/forms/CreateVenueForm.tsx b/components/forms/CreateVenueForm.tsx index 3402f70..0a218f4 100644 --- a/components/forms/CreateVenueForm.tsx +++ b/components/forms/CreateVenueForm.tsx @@ -7,7 +7,7 @@ import { Label } from '../ui/label' import { toast } from 'sonner' interface CreateVenueFormProps { - onSuccess?: () => void + onSuccess?: (newVenueId?: string) => void } export default function CreateVenueForm({ onSuccess }: CreateVenueFormProps) { @@ -38,7 +38,7 @@ export default function CreateVenueForm({ onSuccess }: CreateVenueFormProps) { } setLoading(true) - try { + try { const res = await fetch('/api/venues/create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -47,6 +47,9 @@ export default function CreateVenueForm({ onSuccess }: CreateVenueFormProps) { if (!res.ok) throw new Error('Failed to create venue') + const data = await res.json() + const newVenueId = data?.id + toast.success('Venue created!') setFormData({ name: '', @@ -59,7 +62,7 @@ export default function CreateVenueForm({ onSuccess }: CreateVenueFormProps) { email: '' }) - if (onSuccess) onSuccess() + if (onSuccess) onSuccess(newVenueId) } catch (err) { console.error(err) toast.error('Something went wrong')