From 6e351a4b208bb1540d5410077ba4d27715beb4a2 Mon Sep 17 00:00:00 2001 From: alannnc Date: Wed, 7 Dec 2022 12:55:47 -0700 Subject: [PATCH] fix/premium-username-flow (#5815) * Removes user plan logic for stripe sub * Update hardcoded price * Removed checkoutSessionId metadata and fix for trpc query * Remove or comment team billing unused code * Add todo note * Fix type checks * Change function that was renamed * Remove duplicated test * remove plan when creating user on test Co-authored-by: Alex van Andel Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Peer Richelsen --- .../steps-views/UserSettings.tsx | 6 +- .../UsernameAvailability/PremiumTextfield.tsx | 40 +-- apps/web/pages/api/teams.ts | 68 ----- apps/web/pages/auth/sso/[provider].tsx | 4 +- apps/web/playwright/change-username.e2e.ts | 72 +----- .../stripepayment/api/paymentCallback.ts | 33 ++- .../stripepayment/api/subscription.ts | 113 ++------- .../app-store/stripepayment/lib/constants.ts | 11 +- .../app-store/stripepayment/lib/downgrade.ts | 13 +- .../lib/getCustomerAndCheckoutSession.ts | 6 +- .../stripepayment/lib/subscriptions.ts | 43 ---- .../stripepayment/lib/team-billing.ts | 234 ------------------ packages/app-store/stripepayment/lib/utils.ts | 48 +--- packages/prisma/zod-utils.ts | 2 - packages/trpc/server/routers/viewer.tsx | 60 +++-- packages/trpc/server/routers/viewer/teams.tsx | 23 +- turbo.json | 10 +- 17 files changed, 142 insertions(+), 644 deletions(-) delete mode 100644 apps/web/pages/api/teams.ts diff --git a/apps/web/components/getting-started/steps-views/UserSettings.tsx b/apps/web/components/getting-started/steps-views/UserSettings.tsx index ed47714ee0..04f0285844 100644 --- a/apps/web/components/getting-started/steps-views/UserSettings.tsx +++ b/apps/web/components/getting-started/steps-views/UserSettings.tsx @@ -42,12 +42,8 @@ const UserSettings = (props: IUserSettingsProps) => { const mutation = trpc.viewer.updateProfile.useMutation({ onSuccess: onSuccess, }); - const { data: stripeCustomer } = trpc.viewer.stripeCustomer.useQuery(); - const paymentRequired = stripeCustomer?.isPremium ? !stripeCustomer?.paidForPremium : false; + const onSubmit = handleSubmit((data) => { - if (paymentRequired) { - return; - } mutation.mutate({ name: data.name, timeZone: selectedTimeZone, diff --git a/apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx b/apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx index 1389d64b02..c1945aec94 100644 --- a/apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx +++ b/apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx @@ -3,7 +3,7 @@ import { debounce, noop } from "lodash"; import { useRouter } from "next/router"; import { RefCallback, useEffect, useMemo, useState } from "react"; -import { getPremiumPlanMode, getPremiumPlanPriceValue } from "@calcom/app-store/stripepayment/lib/utils"; +import { getPremiumPlanPriceValue } from "@calcom/app-store/stripepayment/lib/utils"; import { fetchUsername } from "@calcom/lib/fetchUsername"; import hasKeyInMetadata from "@calcom/lib/hasKeyInMetadata"; import { useLocale } from "@calcom/lib/hooks/useLocale"; @@ -24,9 +24,7 @@ import { } from "@calcom/ui"; export enum UsernameChangeStatusEnum { - NORMAL = "NORMAL", UPGRADE = "UPGRADE", - DOWNGRADE = "DOWNGRADE", } interface ICustomUsernameProps { @@ -60,20 +58,14 @@ interface ICustomUsernameProps { const obtainNewUsernameChangeCondition = ({ userIsPremium, isNewUsernamePremium, - stripeCustomer, }: { userIsPremium: boolean; isNewUsernamePremium: boolean; stripeCustomer: RouterOutputs["viewer"]["stripeCustomer"] | undefined; }) => { - if (!userIsPremium && isNewUsernamePremium && !stripeCustomer?.paidForPremium) { + if (!userIsPremium && isNewUsernamePremium) { return UsernameChangeStatusEnum.UPGRADE; } - - if (userIsPremium && !isNewUsernamePremium && getPremiumPlanMode() === "subscription") { - return UsernameChangeStatusEnum.DOWNGRADE; - } - return UsernameChangeStatusEnum.NORMAL; }; const PremiumTextfield = (props: ICustomUsernameProps) => { @@ -106,7 +98,7 @@ const PremiumTextfield = (props: ICustomUsernameProps) => { setIsInputUsernamePremium(data.premium); setUsernameIsAvailable(data.available); }, 150), - [] + [currentUsername] ); useEffect(() => { @@ -137,7 +129,7 @@ const PremiumTextfield = (props: ICustomUsernameProps) => { }); // when current username isn't set - Go to stripe to check what username he wanted to buy and was it a premium and was it paid for - const paymentRequired = !currentUsername && stripeCustomer?.isPremium && !stripeCustomer?.paidForPremium; + const paymentRequired = !currentUsername && stripeCustomer?.isPremium; const usernameChangeCondition = obtainNewUsernameChangeCondition({ userIsPremium: isCurrentUsernamePremium, @@ -194,7 +186,7 @@ const PremiumTextfield = (props: ICustomUsernameProps) => { }; const saveUsername = () => { - if (usernameChangeCondition === UsernameChangeStatusEnum.NORMAL) { + if (usernameChangeCondition !== UsernameChangeStatusEnum.UPGRADE) { updateUsername.mutate({ username: inputUsernameValue, }); @@ -279,14 +271,6 @@ const PremiumTextfield = (props: ICustomUsernameProps) => { {paymentMsg} {markAsError &&

Username is already taken

} - {usernameIsAvailable && ( -

- {usernameChangeCondition === UsernameChangeStatusEnum.DOWNGRADE && ( - <>{t("premium_to_standard_username_description")} - )} -

- )} -
@@ -295,13 +279,8 @@ const PremiumTextfield = (props: ICustomUsernameProps) => {
- {usernameChangeCondition && usernameChangeCondition !== UsernameChangeStatusEnum.NORMAL && ( -

- {usernameChangeCondition === UsernameChangeStatusEnum.UPGRADE && - t("change_username_standard_to_premium")} - {usernameChangeCondition === UsernameChangeStatusEnum.DOWNGRADE && - t("change_username_premium_to_standard")} -

+ {usernameChangeCondition && usernameChangeCondition === UsernameChangeStatusEnum.UPGRADE && ( +

{t("change_username_standard_to_premium")}

)}
@@ -323,8 +302,7 @@ const PremiumTextfield = (props: ICustomUsernameProps) => {
{/* redirect to checkout */} - {(usernameChangeCondition === UsernameChangeStatusEnum.UPGRADE || - usernameChangeCondition === UsernameChangeStatusEnum.DOWNGRADE) && ( + {usernameChangeCondition === UsernameChangeStatusEnum.UPGRADE && ( )} {/* Normal save */} - {usernameChangeCondition === UsernameChangeStatusEnum.NORMAL && ( + {usernameChangeCondition !== UsernameChangeStatusEnum.UPGRADE && (