Skip to content
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

chore: refactor shell to individual files #16893

Merged
merged 21 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/web/modules/more/more-page-view.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import Shell, { MobileNavigationMoreItems } from "@calcom/features/shell/Shell";
import Shell from "@calcom/features/shell/Shell";
import { MobileNavigationMoreItems } from "@calcom/features/shell/navigation/Navigation";
import { useLocale } from "@calcom/lib/hooks/useLocale";

export default function MorePage() {
Expand Down
3 changes: 2 additions & 1 deletion apps/web/playwright/signup.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, Page } from "@playwright/test";
import type { Page } from "@playwright/test";
import { expect } from "@playwright/test";
import { randomBytes } from "crypto";

import { APP_NAME, IS_PREMIUM_USERNAME_ENABLED, IS_MAILHOG_ENABLED } from "@calcom/lib/constants";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useSession } from "next-auth/react";
import { useRouter } from "next/navigation";
import { useEffect } from "react";

import { WEBAPP_URL } from "@calcom/lib/constants";

export function useRedirectToLoginIfUnauthenticated(isPublic = false) {
const { data: session, status } = useSession();
const loading = status === "loading";
const router = useRouter();
useEffect(() => {
if (isPublic) {
return;
}

if (!loading && !session) {
const urlSearchParams = new URLSearchParams();
urlSearchParams.set("callbackUrl", `${WEBAPP_URL}${location.pathname}${location.search}`);
router.replace(`/auth/login?${urlSearchParams.toString()}`);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [loading, session, isPublic]);

return {
loading: loading && !session,
session,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { User } from "@prisma/client";
import { useRouter } from "next/navigation";
import { useEffect } from "react";

import dayjs from "@calcom/dayjs";
import { useFlagMap } from "@calcom/features/flags/context/provider";
import { useEmailVerifyCheck } from "@calcom/trpc/react/hooks/useEmailVerifyCheck";
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";

const shouldShowOnboarding = (
user: Pick<User, "createdDate" | "completedOnboarding"> & {
organizationId: number | null;
}
) => {
return (
!user.completedOnboarding &&
!user.organizationId &&
dayjs(user.createdDate).isAfter(ONBOARDING_INTRODUCED_AT)
);
};

export const ONBOARDING_INTRODUCED_AT = dayjs("September 1 2021").toISOString();

export const ONBOARDING_NEXT_REDIRECT = {
redirect: {
permanent: false,
destination: "/getting-started",
},
} as const;

export function useRedirectToOnboardingIfNeeded() {
const router = useRouter();
const query = useMeQuery();
const user = query.data;
const flags = useFlagMap();

const { data: email } = useEmailVerifyCheck();

const needsEmailVerification = !email?.isVerified && flags["email-verification"];

const isRedirectingToOnboarding = user && shouldShowOnboarding(user);

useEffect(() => {
if (isRedirectingToOnboarding && !needsEmailVerification) {
router.replace("/getting-started");
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isRedirectingToOnboarding, needsEmailVerification]);

return {
isRedirectingToOnboarding,
};
}
14 changes: 14 additions & 0 deletions packages/features/ee/support/lib/intercom/useIntercom.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// eslint-disable-next-line no-restricted-imports
import { noop } from "lodash";
import { useEffect } from "react";
import { useIntercom as useIntercomLib } from "react-use-intercom";
import { z } from "zod";

import dayjs from "@calcom/dayjs";
import { WEBAPP_URL, WEBSITE_URL } from "@calcom/lib/constants";
import { useHasTeamPlan, useHasPaidPlan } from "@calcom/lib/hooks/useHasPaidPlan";
import { localStorage } from "@calcom/lib/webstorage";
import { trpc } from "@calcom/trpc/react";

// eslint-disable-next-line turbo/no-undeclared-env-vars
Expand Down Expand Up @@ -117,4 +119,16 @@ export const useIntercom = () => {
return { ...hookData, open, boot };
};

export const useBootIntercom = () => {
const { boot } = useIntercom();
const { data: user } = trpc.viewer.me.useQuery();
useEffect(() => {
// not using useMediaQuery as it toggles between true and false
const showIntercom = localStorage.getItem("showIntercom");
if (!isInterComEnabled || showIntercom === "false" || window.innerWidth <= 768 || !user) return;
boot();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [user]);
};

export default useIntercom;
Loading
Loading