updated create meeting functionality and store the data in database

This commit is contained in:
Juthatip McDevitt 2024-04-28 13:38:33 -05:00
parent a5f49f643c
commit f3dab8b288
3 changed files with 43 additions and 14 deletions

View file

@ -8,6 +8,11 @@ import Image from 'next/image'
import { Button } from '@/components/ui/button' import { Button } from '@/components/ui/button'
import Link from 'next/link' import Link from 'next/link'
import ThemeOption from '@/app/_utils/ThemeOption' import ThemeOption from '@/app/_utils/ThemeOption'
import { doc, getFirestore, setDoc } from 'firebase/firestore'
import { app } from '@/config/FirebaseConfig'
import { useKindeBrowserClient } from '@kinde-oss/kinde-auth-nextjs'
import { toast } from 'sonner'
import { useRouter } from 'next/navigation'
const MeetingForm = ({setFormEvent}) => { const MeetingForm = ({setFormEvent}) => {
const [themeColor, setThemeColor] = useState(); const [themeColor, setThemeColor] = useState();
@ -18,6 +23,28 @@ const MeetingForm = ({setFormEvent}) => {
const [locationMeeting, setLocationMeeting] = useState(); const [locationMeeting, setLocationMeeting] = useState();
const [urlMeeting, setUrlMeeting] = useState(); const [urlMeeting, setUrlMeeting] = useState();
//initialize the data
const db = getFirestore(app);
const {user} = useKindeBrowserClient();
const router = useRouter();
//create event
const onCreateEvent = async () => {
const id = Date.now().toString();
await setDoc(doc(db, 'MeetingEvent', id), {
id: id,
eventName: eventName,
timeDuration: timeDuration,
locationMeeting: locationMeeting,
urlMeeting: urlMeeting,
themeColor: themeColor,
businessId: doc(db, 'Business', user?.email)
}).then(res => {
toast('New event/meeting is created')
router.replace('/dashboard/meeting')
})
}
useEffect(() => { useEffect(() => {
setFormEvent({ setFormEvent({
eventName: eventName, eventName: eventName,
@ -26,7 +53,7 @@ const MeetingForm = ({setFormEvent}) => {
urlMeeting: urlMeeting, urlMeeting: urlMeeting,
themeColor: themeColor themeColor: themeColor
}) })
}, [eventName, timeDuration, locationMeeting, urlMeeting, themeColor]) }, [eventName, timeDuration, locationMeeting, urlMeeting, themeColor]);
return ( return (
@ -61,8 +88,8 @@ const MeetingForm = ({setFormEvent}) => {
</div> </div>
{locationMeeting && {locationMeeting &&
<div> <div>
<p className='font-semibold'> Add {locationMeeting} url or number <span className='text-red-500'>*</span></p> <p className='font-semibold'> Add {locationMeeting} url or phone number<span className='text-red-500'>*</span></p>
<Input onChange={(ev) => setUrlMeeting(ev.target.value)} placeholder='Add url' className='text-sm'/> <Input onChange={(ev) => setUrlMeeting(ev.target.value)} placeholder='Add url or phone number' className='text-sm'/>
</div> </div>
} }
<p className='font-semibold'>Select Color</p> <p className='font-semibold'>Select Color</p>
@ -72,7 +99,7 @@ const MeetingForm = ({setFormEvent}) => {
))} ))}
</div> </div>
</div> </div>
<Button disabled={(!eventName || !timeDuration || !locationMeeting || !urlMeeting)} className='w-full mt-10'>Create Event</Button> <Button onClick={() => onCreateEvent()} disabled={(!eventName || !timeDuration || !locationMeeting || !urlMeeting)} className='w-full mt-10'>Create Event</Button>
</div> </div>
) )
} }

View file

@ -3,7 +3,6 @@ import { PiMapPinLight } from "react-icons/pi";
import { Calendar } from "@/components/ui/calendar" import { Calendar } from "@/components/ui/calendar"
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import Link from "next/link"; import Link from "next/link";
import { Button } from '@/components/ui/button'
const PreviewMeeting = ({formEvent}) => { const PreviewMeeting = ({formEvent}) => {
const [date, setDate] = useState(new Date()); const [date, setDate] = useState(new Date());
@ -30,25 +29,26 @@ const PreviewMeeting = ({formEvent}) => {
return ( return (
<div className='px-5 py-10 shadow-md m-4 border-t-8'> <div className='px-5 py-10 shadow-md m-4 border-t-8' style={{borderTopColor: formEvent?.themeColor}}>
<p className='text-xl uppercase font-semibold tracking-wide'>Schedule.Me</p> <p className='text-xl uppercase font-semibold tracking-wide'>Schedule.Me</p>
<div className='grid grid-cols-1 md:grid-cols-3 mt-5'> <div className='grid grid-cols-1 lg:grid-cols-3 mt-5'>
<div className='border-r'> <div className='border-r'>
<p className='font-semibold'>Event Name: <span className="font-normal">{formEvent?.eventName?formEvent?.eventName:'Meeting/Event Name'}</span></p> <p className='font-semibold'>Event Name:</p>
<p className="font-normal">{formEvent?.eventName?formEvent?.eventName:'Meeting/Event Name'}</p>
<div className='mt-5 flex flex-col gap-2'> <div className='mt-5 flex flex-col gap-2'>
<p className='flex gap-1 items-center'><GoClock/>{formEvent?.timeDuration} minutes</p> <p className='flex gap-1 items-center'><GoClock/>{formEvent?.timeDuration} minutes</p>
<p className='flex gap-1 items-center'><PiMapPinLight/>{formEvent?.locationMeeting}</p> <p className='flex gap-1 items-center'><PiMapPinLight/>{formEvent?.locationMeeting}</p>
<Link href={formEvent?.urlMeeting?formEvent?.urlMeeting:''} className="text-gray-500 underline text-sm">{formEvent?.urlMeeting}</Link> <Link href={formEvent?.urlMeeting?formEvent?.urlMeeting:''} className="text-gray-500 underline text-sm">{formEvent?.urlMeeting}</Link>
</div> </div>
</div> </div>
<div className='flex px-5 md:col-span-2'> <div className='grid px-2 md:px-5 lg:col-span-2 min-[480px]:flex'>
<div className="flex flex-col"> <div className="flex flex-col">
<p className="font-semibold">Select your meeting date & time</p> <p className="font-semibold">Select your meeting date & time</p>
<Calendar mode="single" selected={date} onSelect={setDate} className="rounded-md border mt-5"/> <Calendar disabled={(date) => date < new Date()} mode="single" selected={date} onSelect={setDate} className="rounded-md border mt-5"/>
</div> </div>
<div> <div className="w-full flex flex-col overflow-auto gap-2 p-2 md:p-5" style={{maxHeight: '350px'}}>
{timeSlots?.map((time, index) => ( {timeSlots?.map((time, index) => (
<Button variant="outline">{time}</Button> <button className='text-xs p-2 border rounded-md hover:bg-gray-100'>{time}</button>
))} ))}
</div> </div>
</div> </div>

View file

@ -1,6 +1,7 @@
import React from 'react' import React from 'react'
import SideNav from './_components/sideNav' import SideNav from './_components/sideNav'
import DashboardHeader from './_components/dashboardHeader' import DashboardHeader from './_components/dashboardHeader'
import { Toaster } from 'sonner'
const Layout = ({children}) => { const Layout = ({children}) => {
return ( return (
@ -10,6 +11,7 @@ const Layout = ({children}) => {
</div> </div>
<div className='md:ml-64'> <div className='md:ml-64'>
<DashboardHeader/> <DashboardHeader/>
<Toaster/>
{children} {children}
</div> </div>
</div> </div>