diff --git a/scheduler_app/app/(routes)/[business]/_components/MeetingEventSelection.js b/scheduler_app/app/(routes)/[business]/_components/MeetingEventSelection.js index 5369938..6b3fb9c 100644 --- a/scheduler_app/app/(routes)/[business]/_components/MeetingEventSelection.js +++ b/scheduler_app/app/(routes)/[business]/_components/MeetingEventSelection.js @@ -1,19 +1,32 @@ +"use client" import { GoClock } from "react-icons/go"; import { PiMapPinLight, PiInfo, PiCalendarCheck } from "react-icons/pi"; import React, { useEffect, useState } from 'react' import Link from "next/link"; import { format } from "date-fns"; import TimeDateSelection from "./TimeDateSelection"; +import { Button } from "@/components/ui/button"; +import UserFormInfo from "./UserFormInfo"; +import { doc, getFirestore, setDoc } from "firebase/firestore"; +import { app } from "@/config/FirebaseConfig"; +import { toast } from "sonner"; const MeetingEventSelection = ({meetingEventInfo, businessInfo}) => { const [date, setDate] = useState(new Date()); const [timeSlots, setTimeSlots] = useState(); - const [unavialableTime, setUnavialableTime] = useState(false) + const [unavialableTime, setUnavialableTime] = useState(false); const [selectedTime, setSelectedTime] = useState(); - useEffect(() => { - meetingEventInfo?.timeDuration && createTimeSlot(meetingEventInfo?.timeDuration) - }, [meetingEventInfo]) + //set user schedule data + const [userName, setUserName] = useState(); + const [userEmail, setUserEmail] = useState(); + const [userMessage, setUserMessage] = useState(''); + + //setup the next step + const [nextStep, setNextStep] = useState(1); + + const db = getFirestore(app); + //create time slot const createTimeSlot = (interval) => { const startTime = 8 * 60; @@ -39,10 +52,40 @@ const MeetingEventSelection = ({meetingEventInfo, businessInfo}) => { setUnavialableTime(false) } } - + + //store user scheduale data + const handleSchedule = async () => { + const regex = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; + if(regex.test(userEmail) == false){ + toast('Please enter your valid email!') + return ; + } + + const docId = Date.now().toString(); + await setDoc(doc(db, 'ScheduleMeeting', docId), { + businessName: businessInfo.businessName, + businessEmail: businessInfo.email, + selectedTime: selectedTime, + selectedDate: date, + duration: meetingEventInfo.timeDuration, + urlMeeting: meetingEventInfo.urlMeeting, + eventId: meetingEventInfo.id, + id: docId, + userName: userName, + userEmail: userEmail, + userMessage: userMessage + }).then(res => { + toast('Your schedule is created successfully'); + }) + } + + useEffect(() => { + meetingEventInfo?.timeDuration && createTimeSlot(meetingEventInfo?.timeDuration) + }, [meetingEventInfo]) + return ( -
Schedule.Me
Select your meeting date & time
-Schedule Form
+Name*
+ setUserName(e.target.value)} placeholder='Enter your name' className='text-xs'/> +Email*
+ setUserEmail(e.target.value)} placeholder='Enter your email' className='text-xs'/> +Message
+ setUserMessage(e.target.value)} placeholder='Enter your brief message' className='text-xs'/> +