From bc6af6ea3d691f08f994dc79464575882ce41a9e Mon Sep 17 00:00:00 2001 From: Sean Brydon Date: Fri, 15 Sep 2023 14:15:21 +0100 Subject: [PATCH] Add premium username tag --- apps/web/pages/signup.tsx | 49 +++++++++++++------ apps/web/public/static/locales/en/common.json | 1 + 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/apps/web/pages/signup.tsx b/apps/web/pages/signup.tsx index e3dba8d4cf..03f85611f5 100644 --- a/apps/web/pages/signup.tsx +++ b/apps/web/pages/signup.tsx @@ -1,5 +1,5 @@ import { zodResolver } from "@hookform/resolvers/zod"; -import { ShieldCheckIcon } from "lucide-react"; +import { Info, Loader2, ShieldCheckIcon, StarIcon } from "lucide-react"; import type { GetServerSidePropsContext } from "next"; import { signIn } from "next-auth/react"; import Link from "next/link"; @@ -12,6 +12,7 @@ import { Trans } from "react-i18next"; import { z } from "zod"; import getStripe from "@calcom/app-store/stripepayment/lib/client"; +import { getPremiumPlanPriceValue } from "@calcom/app-store/stripepayment/lib/utils"; import { getOrgFullDomain } from "@calcom/ee/organizations/lib/orgDomains"; import { checkPremiumUsername } from "@calcom/features/ee/common/lib/checkPremiumUsername"; import { isSAMLLoginEnabled } from "@calcom/features/ee/sso/lib/saml"; @@ -42,12 +43,15 @@ type FormValues = z.infer; type SignupProps = inferSSRProps; -function UsernameField({ ...props }: React.ComponentProps) { +function UsernameField({ + ...props +}: React.ComponentProps & { setPremiumExternal?: () => void }) { const { t } = useLocale(); const { formState, watch, setError, register } = useFormContext(); const { errors } = formState; const [loading, setLoading] = useState(false); const [premium, setPremium] = useState(false); + const [taken, setTaken] = useState(false); const watchedUsername = watch("username"); const debouncedUsername = useDebounce(watchedUsername, 500); @@ -55,23 +59,20 @@ function UsernameField({ ...props }: React.ComponentProps) { async function checkUsername() { if (!debouncedUsername) { setLoading(false); + setPremium(false); + setTaken(false); return; } setLoading(true); fetchUsername(debouncedUsername) .then(({ data }) => { if (data.premium) { - // setError("username", { - // type: "manual", - // message: t("premium_username_error"), - // }); setPremium(true); + } else { + setPremium(false); } if (!data.available) { - setError("username", { - type: "manual", - message: t("already_in_use_error"), - }); + setTaken(true); } }) .finally(() => { @@ -82,13 +83,31 @@ function UsernameField({ ...props }: React.ComponentProps) { }, [debouncedUsername, t, setError]); return ( - <> - +
+
- {loading && } - {errors.username?.message} +

+ {loading ? ( + <> + + {t("loading")} + + ) : taken ? ( +

+ + {t("already_taken")} +
+ ) : premium ? ( + <> + + {t("premium_username", { + price: getPremiumPlanPriceValue(), + })} + + ) : null} +

- +
); } diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 2b05fbc2e8..6f4f385024 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -1138,6 +1138,7 @@ "active_on": "Active on", "workflow_updated_successfully": "{{workflowName}} workflow updated successfully", "premium_to_standard_username_description": "This is a standard username and updating will take you to billing to downgrade.", + "premium_username": "This is a premium username, get yours for {{price}}", "current": "Current", "premium": "premium", "standard": "standard",