* refactor: move Booker hooks from packages/features to apps/web/modules Migrate the following Booker hooks: - useOverlayCalendar - useSkipConfirmStep - useInitializeWeekStart - useIsQuickAvailabilityCheckFeatureEnabled - useDecoyBooking These hooks are only imported by apps/web files, making them safe to move without creating circular dependencies. Part of the tRPC-driven UI migration from packages/features to apps/web/modules. Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: revert useIsQuickAvailabilityCheckFeatureEnabled move and fix import paths - Reverted useIsQuickAvailabilityCheckFeatureEnabled.ts back to packages/features since it's imported by useSlots.ts in packages/features (would create circular dependency) - Fixed import paths in useOverlayCalendar.ts to use @calcom/features paths - Fixed import paths in useSkipConfirmStep.ts to use @calcom/features paths - Updated Booker.tsx to import useIsQuickAvailabilityCheckFeatureEnabled from original location Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: use @calcom/web alias for hook imports to fix vitest resolution Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * refactor * migrate more hooks * fix * mv types * fix * fix * fix * fix * revert: remove formatting-only changes to make PR easier to review Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix * fix * fix * revert: restore original import ordering in moved hooks Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix imports * fix * fix * wip * wip * wip * wip * wip * wip * fix: add isBrowser guard to useSlotsViewOnSmallScreen hook Address Cubic AI review feedback (confidence 9/10) by adding the isBrowser guard to the useSlotsViewOnSmallScreen hook to follow the file's client-only contract and avoid executing during SSR/prerendering. Co-Authored-By: unknown <> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
78 lines
2.6 KiB
TypeScript
78 lines
2.6 KiB
TypeScript
import { useSession } from "next-auth/react";
|
|
import { useState } from "react";
|
|
|
|
import { useBookerStore } from "@calcom/features/bookings/Booker/store";
|
|
import { useDebounce } from "@calcom/lib/hooks/useDebounce";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { trpc } from "@calcom/trpc/react";
|
|
import { showToast } from "@calcom/ui/components/toast";
|
|
|
|
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 isRescheduling = useBookerStore((state) => Boolean(state.rescheduleUid && state.bookingData));
|
|
const debouncedEmail = useDebounce(email, 600);
|
|
const { data: session } = useSession();
|
|
|
|
const { t, i18n } = useLocale();
|
|
const sendEmailVerificationByCodeMutation = trpc.viewer.auth.sendVerifyEmailCode.useMutation({
|
|
onSuccess: () => {
|
|
setEmailVerificationModalVisible(true);
|
|
showToast(t("email_sent"), "success");
|
|
},
|
|
onError: () => {
|
|
showToast(t("email_not_sent"), "error");
|
|
},
|
|
});
|
|
|
|
const { data: isEmailVerificationRequired } =
|
|
trpc.viewer.public.checkIfUserEmailVerificationRequired.useQuery(
|
|
{
|
|
userSessionEmail: session?.user.email || "",
|
|
email: debouncedEmail,
|
|
},
|
|
{
|
|
enabled: !!debouncedEmail && !isRescheduling,
|
|
}
|
|
);
|
|
|
|
const handleVerifyEmail = () => {
|
|
onVerifyEmail?.();
|
|
|
|
sendEmailVerificationByCodeMutation.mutate({
|
|
email,
|
|
username: typeof name === "string" ? name : name?.firstName,
|
|
language: i18n.language || "en",
|
|
});
|
|
};
|
|
|
|
const isVerificationCodeSending = sendEmailVerificationByCodeMutation.isPending;
|
|
|
|
const renderConfirmNotVerifyEmailButtonCond =
|
|
isRescheduling ||
|
|
(!requiresBookerEmailVerification && !isEmailVerificationRequired) ||
|
|
(email && verifiedEmail && verifiedEmail === email);
|
|
|
|
return {
|
|
handleVerifyEmail,
|
|
isEmailVerificationModalVisible,
|
|
setEmailVerificationModalVisible,
|
|
setVerifiedEmail,
|
|
renderConfirmNotVerifyEmailButtonCond: Boolean(renderConfirmNotVerifyEmailButtonCond),
|
|
isVerificationCodeSending,
|
|
};
|
|
};
|