-
Notifications
You must be signed in to change notification settings - Fork 12k
feat: Add email input dialog to /booking/uid page #22542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5566e77
9d50856
5425092
922c4c4
f5d2a4f
80b8840
9a7c5fb
300467a
27eda6c
121e1c7
f551126
8e541ac
02a90b9
1bc263c
abfe1ca
93e3b72
c3a435a
5d4589c
b98e770
e03902b
ced377d
d67ae00
ab65181
eb98e9e
90ccd6c
a6c06e1
d177570
54dbe9f
da1c051
290ad23
672504e
7636778
293d7dd
b7c17ca
fc002a1
2ce0960
fb0ac70
a92bb7a
8dc4cf2
3edb21b
0be3e55
c8176f5
11785f2
84b351d
b31cfd4
832b6dc
74772c4
7d153b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ import classNames from "classnames"; | |
| import { useSession } from "next-auth/react"; | ||
| import Link from "next/link"; | ||
| import { usePathname, useRouter } from "next/navigation"; | ||
| import { Fragment, useEffect, useState } from "react"; | ||
| import { Fragment, useCallback, useEffect, useMemo, useState } from "react"; | ||
| import { Toaster } from "sonner"; | ||
| import { z } from "zod"; | ||
|
|
||
|
|
@@ -49,8 +49,10 @@ import { Alert } from "@calcom/ui/components/alert"; | |
| import { Avatar } from "@calcom/ui/components/avatar"; | ||
| import { Badge } from "@calcom/ui/components/badge"; | ||
| import { Button } from "@calcom/ui/components/button"; | ||
| import { Dialog, DialogContent, DialogHeader } from "@calcom/ui/components/dialog"; | ||
| import { EmptyScreen } from "@calcom/ui/components/empty-screen"; | ||
| import { EmailInput, TextArea } from "@calcom/ui/components/form"; | ||
| import { Input } from "@calcom/ui/components/form"; | ||
| import { Icon } from "@calcom/ui/components/icon"; | ||
| import { showToast } from "@calcom/ui/components/toast"; | ||
| import { useCalcomTheme } from "@calcom/ui/styles"; | ||
|
|
@@ -82,6 +84,10 @@ const querySchema = z.object({ | |
| redirect_status: z.string().optional(), | ||
| }); | ||
|
|
||
| const verificationSchema = z.object({ | ||
| email: z.string().min(1, "Email is required").email("Enter a valid email address"), | ||
| }); | ||
|
|
||
| const useBrandColors = ({ | ||
| brandColor, | ||
| darkBrandColor, | ||
|
|
@@ -162,7 +168,7 @@ export default function Success(props: PageProps) { | |
| const [is24h, setIs24h] = useState( | ||
| props?.userTimeFormat ? props.userTimeFormat === 24 : isBrowserLocale24h() | ||
| ); | ||
| const { data: session } = useSession(); | ||
| const { data: session, status: sessionStatus } = useSession(); | ||
| const isHost = props.isLoggedInUserHost; | ||
|
|
||
| const [showUtmParams, setShowUtmParams] = useState(false); | ||
|
|
@@ -195,12 +201,17 @@ export default function Success(props: PageProps) { | |
| const currentUserEmail = | ||
| searchParams?.get("rescheduledBy") ?? | ||
| searchParams?.get("cancelledBy") ?? | ||
| searchParams?.get("email") ?? | ||
| session?.user?.email ?? | ||
| undefined; | ||
|
|
||
| const defaultRating = validateRating(rating); | ||
| const [rateValue, setRateValue] = useState<number>(defaultRating); | ||
| const [isFeedbackSubmitted, setIsFeedbackSubmitted] = useState(false); | ||
| const [showVerificationDialog, setShowVerificationDialog] = useState<boolean>(false); | ||
| const [verificationEmail, setVerificationEmail] = useState<string>(""); | ||
| const [verificationError, setVerificationError] = useState<string>(""); | ||
| const [isVerifying, setIsVerifying] = useState<boolean>(false); | ||
|
|
||
| const mutation = trpc.viewer.public.submitRating.useMutation({ | ||
| onSuccess: async () => { | ||
|
|
@@ -450,6 +461,87 @@ export default function Success(props: PageProps) { | |
| return isRecurringBooking ? t("meeting_is_scheduled_recurring") : t("meeting_is_scheduled"); | ||
| })(); | ||
|
|
||
| const emailParam = useMemo(() => { | ||
| return searchParams.get("email"); | ||
| }, [searchParams]); | ||
|
|
||
| const [isEmailVerified, setIsEmailVerified] = useState<boolean>(false); | ||
| const [lastVerifiedEmail, setLastVerifiedEmail] = useState<string | null>(null); | ||
|
|
||
| const { data: emailVerificationResult, isLoading: isVerifyingEmailParam } = | ||
| trpc.viewer.public.verifyBookingEmail.useQuery( | ||
| { bookingUid: bookingInfo.uid, email: emailParam ?? "" }, | ||
| { enabled: !!emailParam && !session } | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| if (emailVerificationResult?.isValid && emailParam) { | ||
| setIsEmailVerified(true); | ||
| setLastVerifiedEmail(emailParam); | ||
| } | ||
| }, [emailVerificationResult, emailParam]); | ||
|
|
||
| useEffect(() => { | ||
| if (emailParam !== lastVerifiedEmail) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Manual email verification is immediately cleared by the new Prompt for AI agents |
||
| setIsEmailVerified(false); | ||
| } | ||
| }, [emailParam, lastVerifiedEmail]); | ||
|
|
||
| useEffect(() => { | ||
| if (sessionStatus === "loading" || isVerifyingEmailParam) return; | ||
|
|
||
| const needsVerification = !session && (!emailParam || !emailVerificationResult?.isValid); | ||
|
|
||
| setShowVerificationDialog((prev) => { | ||
| if (prev === needsVerification) return prev; | ||
| return needsVerification; | ||
| }); | ||
| }, [session, sessionStatus, emailParam, emailVerificationResult, isVerifyingEmailParam]); | ||
|
|
||
| const updateSearchParams = useCallback( | ||
| (email: string) => { | ||
| const params = new URLSearchParams(searchParams.toString()); | ||
| params.set("email", email); | ||
| router.replace(`?${params.toString()}`, { scroll: false }); | ||
| }, | ||
| [router, searchParams] | ||
| ); | ||
|
|
||
| const verifyEmailMutation = trpc.viewer.public.verifyBookingEmail.useQuery( | ||
| { bookingUid: bookingInfo.uid, email: verificationEmail }, | ||
| { enabled: false } | ||
| ); | ||
|
|
||
| const handleVerification = async () => { | ||
| setVerificationError(""); | ||
|
|
||
| const parsed = verificationSchema.safeParse({ email: verificationEmail }); | ||
| if (!parsed.success) { | ||
| setVerificationError(parsed.error.errors[0].message); | ||
| return; | ||
| } | ||
|
|
||
| setIsVerifying(true); | ||
| try { | ||
| const result = await verifyEmailMutation.refetch(); | ||
| if (result.data?.isValid) { | ||
| setIsEmailVerified(true); | ||
| updateSearchParams(verificationEmail); | ||
| setShowVerificationDialog(false); | ||
| } else { | ||
| setVerificationError(t("verification_email_error")); | ||
| } | ||
| } finally { | ||
| setIsVerifying(false); | ||
| } | ||
| }; | ||
|
|
||
| const showBookingInfo = useMemo(() => { | ||
cubic-dev-ai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (session) return true; | ||
| if (!emailParam) return false; | ||
| return isEmailVerified || emailVerificationResult?.isValid; | ||
| }, [session, emailParam, isEmailVerified, emailVerificationResult]); | ||
|
|
||
| return ( | ||
| <div className={isEmbed ? "" : "h-screen"} data-testid="success-page"> | ||
| {!isEmbed && !isFeedbackMode && ( | ||
|
|
@@ -478,7 +570,8 @@ export default function Success(props: PageProps) { | |
| <BookingPageTagManager | ||
| eventType={{ ...eventType, metadata: eventTypeMetaDataSchemaWithTypedApps.parse(eventType.metadata) }} | ||
| /> | ||
| <main className={classNames(shouldAlignCentrally ? "mx-auto" : "", isEmbed ? "" : "max-w-3xl")}> | ||
| {showBookingInfo ? ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Email-gated booking details are only hidden in the UI; SSR still delivers full booking data to unauthenticated users Prompt for AI agents |
||
| <main className={classNames(shouldAlignCentrally ? "mx-auto" : "", isEmbed ? "" : "max-w-3xl")}> | ||
| <div className={classNames("overflow-y-auto", isEmbed ? "" : "z-50 ")}> | ||
| <div | ||
| className={classNames( | ||
|
|
@@ -1112,6 +1205,45 @@ export default function Success(props: PageProps) { | |
| </div> | ||
| </div> | ||
| </main> | ||
| ) : ( | ||
| <Dialog | ||
| open={showVerificationDialog} | ||
| onOpenChange={() => { | ||
| setShowVerificationDialog; | ||
| }} | ||
| data-testid="verify-email-dialog"> | ||
| <DialogContent | ||
| onPointerDownOutside={(e) => e.preventDefault()} | ||
| onEscapeKeyDown={(e) => e.preventDefault()}> | ||
| <DialogHeader title={t("verify_email")} /> | ||
| <div className="space-y-4 py-4"> | ||
| <p className="text-default text-sm">{t("verification_email_dialog_description")}</p> | ||
| <Input | ||
| data-testid="verify-email-input" | ||
| type="email" | ||
| placeholder={t("verification_email_input_placeholder")} | ||
| value={verificationEmail} | ||
| onChange={(e) => setVerificationEmail(e.target.value)} | ||
| className="mb-2" | ||
| /> | ||
| {verificationError && ( | ||
| <p data-testid="verify-email-error" className="text-error text-sm"> | ||
| {verificationError} | ||
| </p> | ||
| )} | ||
| <div className="flex justify-end space-x-2"> | ||
| <Button | ||
| onClick={handleVerification} | ||
| disabled={isVerifying} | ||
| loading={isVerifying} | ||
| data-testid="verify-email-trigger"> | ||
| {t("verify")} | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </DialogContent> | ||
| </Dialog> | ||
| )} | ||
| <Toaster position="bottom-right" /> | ||
| </div> | ||
| ); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.