From 1ef0f830d3fe3ccd44896a5265bdb61fdc750fcd Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Fri, 18 Aug 2023 14:15:58 -0400 Subject: [PATCH] fix: Username suffix on production [CAL-2262] (#10825) --- .../ui/UsernameAvailability/index.tsx | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/apps/web/components/ui/UsernameAvailability/index.tsx b/apps/web/components/ui/UsernameAvailability/index.tsx index 4a66c40db4..b96ab4a464 100644 --- a/apps/web/components/ui/UsernameAvailability/index.tsx +++ b/apps/web/components/ui/UsernameAvailability/index.tsx @@ -2,10 +2,10 @@ import { useSearchParams } from "next/navigation"; import { useState } from "react"; import { Controller, useForm } from "react-hook-form"; -import { getOrgFullDomain } from "@calcom/features/ee/organizations/lib/orgDomains"; +import { useOrgBranding } from "@calcom/features/ee/organizations/context/provider"; import { IS_SELF_HOSTED } from "@calcom/lib/constants"; +import { CAL_URL } from "@calcom/lib/constants"; import type { TRPCClientErrorLike } from "@calcom/trpc/client"; -import type { RouterOutputs } from "@calcom/trpc/react"; import { trpc } from "@calcom/trpc/react"; import type { AppRouter } from "@calcom/trpc/server/routers/_app"; @@ -21,16 +21,6 @@ interface UsernameAvailabilityFieldProps { onErrorMutation?: (error: TRPCClientErrorLike) => void; } -function useUserNamePrefix(organization: RouterOutputs["viewer"]["me"]["organization"]): string { - return organization - ? organization.slug - ? getOrgFullDomain(organization.slug, { protocol: false }) - : organization.metadata && organization.metadata.requestedSlug - ? getOrgFullDomain(organization.metadata.requestedSlug, { protocol: false }) - : process.env.NEXT_PUBLIC_WEBSITE_URL.replace("https://", "").replace("http://", "") - : process.env.NEXT_PUBLIC_WEBSITE_URL.replace("https://", "").replace("http://", ""); -} - export const UsernameAvailabilityField = ({ onSuccessMutation, onErrorMutation, @@ -49,7 +39,11 @@ export const UsernameAvailabilityField = ({ }, }); - const usernamePrefix = useUserNamePrefix(user.organization); + const orgBranding = useOrgBranding(); + + const usernamePrefix = orgBranding + ? orgBranding?.fullDomain.replace(/^(https?:|)\/\//, "") + : `${CAL_URL?.replace(/^(https?:|)\/\//, "")}`; return (