Files
cal.diy/packages/features/bookings/Booker/components/hooks/useVerifyEmail.ts
T
313bb89789 refactor: Booker Component (#13176)
* refactor: booker component

* refactor: booker component

* refactor: useBookings, useOverlayCalendar

* fix: imports and types

* fix: don't allow uid update in bookings update api (#13071)

* don't allow uid update in bookings update api

* omit uid from schemaBookingEditBodyParams instead of updating schemaBookingBaseBodyParams

---------

Co-authored-by: Alex van Andel <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>

* New Crowdin translations by Github Action

* fix: use DateRangePicker component in my-account/out-of-office (#13207)

* fix: remove duplicate useBrandColors

* fix: add missing localstorage package

* fix: booking form initial values

* fix: redirect to payment form

* refactor: handle fetching schedule only in Booker

* fixup! refactor: handle fetching schedule only in Booker

* fix: remove empty file

* useBookerLayout.ts useEffect dependencies

isMobile and isEmbed were missing and validateLayout was redundant

* useInitialFormValues useEffect dependencies

* fix: remove unused hook

* refactor: split logic from data fetch overlayCalendar

* fix: small changes

* fix: inifinite loop

* fix: toggle calendar

---------

Co-authored-by: Rajiv Sahal <[email protected]>
Co-authored-by: Riddhesh Mahajan <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Crowdin Bot <[email protected]>
Co-authored-by: Carina Wollendorfer <[email protected]>
Co-authored-by: Lauris Skraucis <[email protected]>
2024-01-22 11:57:00 +02:00

56 lines
1.7 KiB
TypeScript

import { useState } from "react";
import { useBookerStore } from "@calcom/features/bookings/Booker/store";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc";
import { showToast } from "@calcom/ui";
export interface IUseVerifyEmailProps {
email: string;
onVerifyEmail?: () => void;
name?: string | { firstName: string; lastname?: string };
requiresBookerEmailVerification?: boolean;
}
export const useVerifyEmail = ({
email,
name,
requiresBookerEmailVerification,
onVerifyEmail,
}: IUseVerifyEmailProps) => {
const [isEmailVerificationModalVisible, setEmailVerificationModalVisible] = useState(false);
const verifiedEmail = useBookerStore((state) => state.verifiedEmail);
const setVerifiedEmail = useBookerStore((state) => state.setVerifiedEmail);
const { t } = useLocale();
const sendEmailVerificationByCodeMutation = trpc.viewer.auth.sendVerifyEmailCode.useMutation({
onSuccess() {
showToast(t("email_sent"), "success");
},
onError() {
showToast(t("email_not_sent"), "error");
},
});
const handleVerifyEmail = () => {
onVerifyEmail?.();
sendEmailVerificationByCodeMutation.mutate({
email,
username: typeof name === "string" ? name : name?.firstName,
});
setEmailVerificationModalVisible(true);
};
const renderConfirmNotVerifyEmailButtonCond =
!requiresBookerEmailVerification || (email && verifiedEmail && verifiedEmail === email);
return {
handleVerifyEmail,
isEmailVerificationModalVisible,
setEmailVerificationModalVisible,
setVerifiedEmail,
renderConfirmNotVerifyEmailButtonCond: Boolean(renderConfirmNotVerifyEmailButtonCond),
};
};