feat: Duration select dropdown multiple durations email embed (#17432)

Co-authored-by: Anik Dhabal Babu <[email protected]>
This commit is contained in:
Amit SharmaandAnik Dhabal Babu authored and GitHub committed 2025-02-19 12:29:52 +00:00
1 parent e87168322c
commit 984ccf7c80
1 file changed
+47 -12
+47 -12
View File
@@ -2,7 +2,7 @@ import { Collapsible, CollapsibleContent } from "@radix-ui/react-collapsible";
import classNames from "classnames"; import classNames from "classnames";
import { useSession } from "next-auth/react"; import { useSession } from "next-auth/react";
import { usePathname, useRouter } from "next/navigation"; import { usePathname, useRouter } from "next/navigation";
import type { RefObject } from "react"; import type { RefObject, Dispatch, SetStateAction } from "react";
import { createRef, useRef, useState } from "react"; import { createRef, useRef, useState } from "react";
import type { ControlProps } from "react-select"; import type { ControlProps } from "react-select";
import { components } from "react-select"; import { components } from "react-select";
@@ -233,12 +233,16 @@ const EmailEmbed = ({
username, username,
orgSlug, orgSlug,
isTeamEvent, isTeamEvent,
selectedDuration,
setSelectedDuration,
userSettingsTimezone, userSettingsTimezone,
}: { }: {
eventType?: EventType; eventType?: EventType;
username: string; username: string;
orgSlug?: string; orgSlug?: string;
isTeamEvent: boolean; isTeamEvent: boolean;
selectedDuration: number | undefined;
setSelectedDuration: Dispatch<SetStateAction<number | undefined>>;
userSettingsTimezone?: string; userSettingsTimezone?: string;
}) => { }) => {
const { t, i18n } = useLocale(); const { t, i18n } = useLocale();
@@ -274,7 +278,12 @@ const EmailEmbed = ({
shallow shallow
); );
const event = useEvent(); const event = useEvent();
const schedule = useScheduleForEvent({ orgSlug, eventId: eventType?.id, isTeamEvent }); const schedule = useScheduleForEvent({
orgSlug,
eventId: eventType?.id,
isTeamEvent,
duration: selectedDuration,
});
const nonEmptyScheduleDays = useNonEmptyScheduleDays(schedule?.data?.slots); const nonEmptyScheduleDays = useNonEmptyScheduleDays(schedule?.data?.slots);
const onTimeSelect = (time: string) => { const onTimeSelect = (time: string) => {
@@ -334,6 +343,15 @@ const EmailEmbed = ({
if (!eventType) { if (!eventType) {
return null; return null;
} }
if (!selectedDuration) {
setSelectedDuration(eventType.length);
}
const multipleDurations = eventType?.metadata?.multipleDuration ?? [];
const durationsOptions = multipleDurations.map((duration) => ({
label: `${duration} ${t("minutes")}`,
value: duration,
}));
return ( return (
<div className="flex flex-col"> <div className="flex flex-col">
@@ -388,12 +406,23 @@ const EmailEmbed = ({
<Collapsible open> <Collapsible open>
<CollapsibleContent> <CollapsibleContent>
<div className="text-default mb-[9px] text-sm">{t("duration")}</div> <div className="text-default mb-[9px] text-sm">{t("duration")}</div>
<TextField {durationsOptions.length > 0 ? (
disabled <Select<{ label: string; value: number }>
label={t("duration")} value={durationsOptions.find((option) => option.value === selectedDuration)}
defaultValue={eventType?.length ?? 15} options={durationsOptions}
addOnSuffix={<>{t("minutes")}</>} onChange={(option) => {
/> setSelectedDuration(option?.value);
setSelectedDatesAndTimes({});
}}
/>
) : (
<TextField
disabled
label={t("duration")}
defaultValue={eventType?.length ?? 15}
addOnSuffix={<>{t("minutes")}</>}
/>
)}
</CollapsibleContent> </CollapsibleContent>
</Collapsible> </Collapsible>
</div> </div>
@@ -416,6 +445,7 @@ const EmailEmbedPreview = ({
month, month,
selectedDateAndTime, selectedDateAndTime,
calLink, calLink,
selectedDuration,
userSettingsTimezone, userSettingsTimezone,
}: { }: {
eventType: EventType; eventType: EventType;
@@ -425,6 +455,7 @@ const EmailEmbedPreview = ({
month?: string; month?: string;
selectedDateAndTime: { [key: string]: string[] }; selectedDateAndTime: { [key: string]: string[] };
calLink: string; calLink: string;
selectedDuration: number | undefined;
userSettingsTimezone?: string; userSettingsTimezone?: string;
}) => { }) => {
const { t } = useLocale(); const { t } = useLocale();
@@ -472,7 +503,7 @@ const EmailEmbedPreview = ({
lineHeight: "17px", lineHeight: "17px",
color: "#333333", color: "#333333",
}}> }}>
{t("duration")}: <b style={{ color: "black" }}>{eventType.length} mins</b> {t("duration")}: <b style={{ color: "black" }}>{selectedDuration} mins</b>
</div> </div>
<div> <div>
<b style={{ color: "black" }}> <b style={{ color: "black" }}>
@@ -534,9 +565,9 @@ const EmailEmbedPreview = ({
// So we add 'team/' to the url. // So we add 'team/' to the url.
const bookingURL = `${eventType.bookerUrl}/${ const bookingURL = `${eventType.bookerUrl}/${
eventType.teamId !== null ? "team/" : "" eventType.teamId !== null ? "team/" : ""
}${username}/${eventType.slug}?duration=${ }${username}/${
eventType.length eventType.slug
}&date=${key}&month=${month}&slot=${time}&cal.tz=${timezone}`; }?duration=${selectedDuration}&date=${key}&month=${month}&slot=${time}&cal.tz=${timezone}`;
return ( return (
<td <td
key={time} key={time}
@@ -705,6 +736,7 @@ const EmbedTypeCodeAndPreviewDialogContent = ({
const refOfEmbedCodesRefs = useRef(embedCodeRefs); const refOfEmbedCodesRefs = useRef(embedCodeRefs);
const embed = types.find((embed) => embed.type === embedType); const embed = types.find((embed) => embed.type === embedType);
const [selectedDuration, setSelectedDuration] = useState(eventTypeData?.eventType.length);
const [isEmbedCustomizationOpen, setIsEmbedCustomizationOpen] = useState(true); const [isEmbedCustomizationOpen, setIsEmbedCustomizationOpen] = useState(true);
const [isBookingCustomizationOpen, setIsBookingCustomizationOpen] = useState(true); const [isBookingCustomizationOpen, setIsBookingCustomizationOpen] = useState(true);
@@ -895,6 +927,8 @@ const EmbedTypeCodeAndPreviewDialogContent = ({
userSettingsTimezone={userSettings?.timeZone} userSettingsTimezone={userSettings?.timeZone}
orgSlug={data?.user?.org?.slug} orgSlug={data?.user?.org?.slug}
isTeamEvent={!!teamSlug} isTeamEvent={!!teamSlug}
selectedDuration={selectedDuration}
setSelectedDuration={setSelectedDuration}
/> />
) : ( ) : (
<div className="flex flex-col"> <div className="flex flex-col">
@@ -1238,6 +1272,7 @@ const EmbedTypeCodeAndPreviewDialogContent = ({
<div key={tab.href} className={classNames("flex flex-grow flex-col")}> <div key={tab.href} className={classNames("flex flex-grow flex-col")}>
<div className="flex h-[55vh] flex-grow flex-col"> <div className="flex h-[55vh] flex-grow flex-col">
<EmailEmbedPreview <EmailEmbedPreview
selectedDuration={selectedDuration}
calLink={calLink} calLink={calLink}
eventType={eventTypeData?.eventType} eventType={eventTypeData?.eventType}
emailContentRef={emailContentRef} emailContentRef={emailContentRef}