* chore: booker web wrapper * fixup! chore: booker web wrapper * fixup! fixup! chore: booker web wrapper * fixup! fixup! fixup! chore: booker web wrapper * fixup! fixup! fixup! fixup! chore: booker web wrapper * fix: CreateANewOrganizationForm verify dialog * fix: EventBooker not rerendering when it should * fix: init booker store properly * fixup! fix: init booker store properly * fix: useMemo EventBooker * fix: remove unnecessary file
56 lines
1.7 KiB
TypeScript
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 type UseVerifyEmailReturnType = ReturnType<typeof useVerifyEmail>;
|
|
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),
|
|
};
|
|
};
|