From 9456ffbb48f48f32751f876a880047897789e49e Mon Sep 17 00:00:00 2001 From: Leo Giovanetti Date: Mon, 10 Jul 2023 11:10:30 -0300 Subject: [PATCH] chore: Credits with commit hash (#9999) --- apps/web/components/PageWrapper.tsx | 8 ++----- apps/web/pages/404.tsx | 7 +++--- packages/lib/constants.ts | 6 ++++++ packages/lib/isCalcom.ts | 2 -- packages/ui/components/credits/Credits.tsx | 24 +++++++++++++++++---- packages/ui/components/head-seo/HeadSeo.tsx | 11 ++-------- 6 files changed, 33 insertions(+), 25 deletions(-) delete mode 100644 packages/lib/isCalcom.ts diff --git a/apps/web/components/PageWrapper.tsx b/apps/web/components/PageWrapper.tsx index ecf7667081..c076ebd2da 100644 --- a/apps/web/components/PageWrapper.tsx +++ b/apps/web/components/PageWrapper.tsx @@ -6,7 +6,7 @@ import Script from "next/script"; import "@calcom/embed-core/src/embed-iframe"; import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired"; -import { WEBAPP_URL } from "@calcom/lib/constants"; +import { WEBAPP_URL, IS_CALCOM } from "@calcom/lib/constants"; import { buildCanonical } from "@calcom/lib/next-seo.config"; import type { AppProps } from "@lib/app-providers"; @@ -53,10 +53,6 @@ function PageWrapper(props: AppProps) { // Use the layout defined at the page level, if available const getLayout = Component.getLayout ?? ((page) => page); - // Canonical: Check if the URL is from cal.com so that we set the canonical conditionally - const isCalcom = - WEBAPP_URL && - (new URL(WEBAPP_URL).hostname.endsWith("cal.com") || new URL(WEBAPP_URL).hostname.endsWith("cal.dev")); const path = router.asPath; return ( @@ -70,7 +66,7 @@ function PageWrapper(props: AppProps) { {t("check_spelling_mistakes_or_go_back")} - ) : isCalcom ? ( + ) : IS_CALCOM ? ( {t(`404_the_${currentPageType.toLowerCase()}`)}{" "} @@ -267,7 +266,7 @@ export default function Custom404() { )}
- {((!isSubpage && isCalcom) || + {((!isSubpage && IS_CALCOM) || currentPageType === pageType.ORG || currentPageType === pageType.TEAM) && (
    diff --git a/packages/lib/constants.ts b/packages/lib/constants.ts index c90674f2a7..ea73c0b90c 100644 --- a/packages/lib/constants.ts +++ b/packages/lib/constants.ts @@ -23,6 +23,12 @@ export const SENDER_NAME = process.env.NEXT_PUBLIC_SENDGRID_SENDER_NAME || "Cal. // As website isn't setup for preview environments, use the webapp url instead export const CAL_URL = new URL(WEBAPP_URL).hostname.endsWith(".vercel.app") ? WEBAPP_URL : WEBSITE_URL; +export const IS_CALCOM = + WEBAPP_URL && + (new URL(WEBAPP_URL).hostname.endsWith("cal.com") || + new URL(WEBAPP_URL).hostname.endsWith("cal.dev") || + new URL(WEBAPP_URL).hostname.endsWith("cal-staging.com")); + export const CONSOLE_URL = new URL(WEBAPP_URL).hostname.endsWith(".cal.dev") || process.env.NODE_ENV !== "production" ? `https://console.cal.dev` diff --git a/packages/lib/isCalcom.ts b/packages/lib/isCalcom.ts deleted file mode 100644 index 1a5a79aa00..0000000000 --- a/packages/lib/isCalcom.ts +++ /dev/null @@ -1,2 +0,0 @@ -const isCalcom = process.env.NEXT_PUBLIC_WEBSITE_URL === "https://cal.com"; -export default isCalcom; diff --git a/packages/ui/components/credits/Credits.tsx b/packages/ui/components/credits/Credits.tsx index 74536fa782..0791ed09ed 100644 --- a/packages/ui/components/credits/Credits.tsx +++ b/packages/ui/components/credits/Credits.tsx @@ -1,11 +1,15 @@ import Link from "next/link"; import { useEffect, useState } from "react"; -import { COMPANY_NAME, IS_SELF_HOSTED } from "@calcom/lib/constants"; +import { COMPANY_NAME, IS_SELF_HOSTED, IS_CALCOM } from "@calcom/lib/constants"; // Relative to prevent triggering a recompile import pkg from "../../../../apps/web/package.json"; +// eslint-disable-next-line turbo/no-undeclared-env-vars +const vercelCommitHash = process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA; +const commitHash = vercelCommitHash ? `-${vercelCommitHash.slice(0, 7)}` : ""; + export const CalComVersion = `v.${pkg.version}-${!IS_SELF_HOSTED ? "h" : "sh"}`; export default function Credits() { @@ -22,9 +26,21 @@ export default function Credits() { {COMPANY_NAME} {" "} {hasMounted && ( - - {CalComVersion} - + <> + + {CalComVersion} + + {vercelCommitHash && IS_CALCOM ? ( + + {commitHash} + + ) : ( + commitHash + )} + )} ); diff --git a/packages/ui/components/head-seo/HeadSeo.tsx b/packages/ui/components/head-seo/HeadSeo.tsx index 3415b1107c..3891960d5c 100644 --- a/packages/ui/components/head-seo/HeadSeo.tsx +++ b/packages/ui/components/head-seo/HeadSeo.tsx @@ -5,8 +5,7 @@ import { useRouter } from "next/router"; import type { AppImageProps, MeetingImageProps } from "@calcom/lib/OgImages"; import { constructAppImage, constructGenericImage, constructMeetingImage } from "@calcom/lib/OgImages"; -import { getBrowserInfo } from "@calcom/lib/browser/browser.utils"; -import { APP_NAME, WEBSITE_URL } from "@calcom/lib/constants"; +import { APP_NAME, WEBSITE_URL, IS_CALCOM } from "@calcom/lib/constants"; import { seoConfig, getSeoImage, buildCanonical } from "@calcom/lib/next-seo.config"; import { truncateOnWord } from "@calcom/lib/text"; @@ -71,17 +70,11 @@ const buildSeoMeta = (pageProps: { export const HeadSeo = (props: HeadSeoProps): JSX.Element => { // The below code sets the defaultUrl for our canonical tags - - // Get the current URL from the window object - const { url } = getBrowserInfo(); - // Check if the URL is from cal.com - const isCalcom = - url && (new URL(url).hostname.endsWith("cal.com") || new URL(url).hostname.endsWith("cal.dev")); // Get the router's path const path = useRouter().asPath; const selfHostedOrigin = WEBSITE_URL || "https://cal.com"; // Set the default URL to either the current URL (if self-hosted) or https://cal.com canonical URL - const defaultUrl = isCalcom + const defaultUrl = IS_CALCOM ? buildCanonical({ path, origin: "https://cal.com" }) : buildCanonical({ path, origin: selfHostedOrigin });