-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor shell to individual files (#16893)
* banners * useAuthHooks * fixes to redirect and banner * extract useIntercom to custom hook * use app theme * extract user-dropdown to new component * Navigation Item * navigation and profile dropdown * Fix import * navigation and sidebar * fix type errors * fix banners being an async call * fix types * fix banner prop type * fix mobile nav item import * fix banner types * (revert) layout banner render method to fix type error --------- Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
- Loading branch information
1 parent
b4f1b5a
commit 4553455
Showing
16 changed files
with
1,353 additions
and
1,152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/features/auth/lib/hooks/useRedirectToLoginIfUnauthenticated.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/features/auth/lib/hooks/useRedirectToOnboardingIfNeeded.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.