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

@@ -50,12 +93,26 @@ const MeetingEventSelection = ({meetingEventInfo, businessInfo}) => {

{meetingEventInfo?.eventName?meetingEventInfo?.eventName:'Meeting/Event Name'}

{format(date, 'PPP')}

-

{meetingEventInfo?.timeDuration} minutes {selectedTime && ({selectedTime})}

+

{meetingEventInfo?.timeDuration} minutes + {selectedTime && ({selectedTime})} +

{meetingEventInfo?.locationMeeting}

- {meetingEventInfo?.urlMeeting} + {meetingEventInfo?.urlMeeting}
- + {nextStep == 1 ? + + : + + } +
+
+ {nextStep == 2 && } + {nextStep ==1 ? + + : + + }
) diff --git a/scheduler_app/app/(routes)/[business]/_components/TimeDateSelection.js b/scheduler_app/app/(routes)/[business]/_components/TimeDateSelection.js index e097a6f..78e5cc5 100644 --- a/scheduler_app/app/(routes)/[business]/_components/TimeDateSelection.js +++ b/scheduler_app/app/(routes)/[business]/_components/TimeDateSelection.js @@ -1,16 +1,16 @@ import { Calendar } from "@/components/ui/calendar" import React from 'react' -const TimeDateSelection = ({date, handleDatechange, timeSlots, setSelectedTime, unavialableTime}) => { +const TimeDateSelection = ({date, handleDatechange, timeSlots, setSelectedTime, unavialableTime, selectedTime}) => { return (

Select your meeting date & time

- date < new Date()} mode="single" selected={date} onSelect={(d) => handleDatechange(d)} className="rounded-md border mt-5"/> + date <= new Date()} mode="single" selected={date} onSelect={(d) => handleDatechange(d)} className="rounded-md border mt-5"/>
{timeSlots?.map((time, index) => ( - + ))}
diff --git a/scheduler_app/app/(routes)/[business]/_components/UserFormInfo.js b/scheduler_app/app/(routes)/[business]/_components/UserFormInfo.js new file mode 100644 index 0000000..9c8506a --- /dev/null +++ b/scheduler_app/app/(routes)/[business]/_components/UserFormInfo.js @@ -0,0 +1,25 @@ +import { Input } from '@/components/ui/input' +import React from 'react' + +const UserFormInfo = ({setUserName, setUserEmail, setUserMessage}) => { + + return ( +
+

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'/> +
+
+ ) +} + +export default UserFormInfo \ No newline at end of file