From 1665daac181d37f2300ffad03174e4d3258fc0f6 Mon Sep 17 00:00:00 2001 From: Joseph Chrzan Date: Wed, 25 Sep 2024 21:20:31 -0400 Subject: [PATCH] sch-1881 (#74) * fix checkout help text * copy adjustments; fix modal sizing * finalize copy; allow current plan to be selected --- .../models/CompanySubscriptionResponseData.ts | 9 ++ .../elements/plan-manager/CheckoutDialog.tsx | 96 +++++++++++++------ components/src/components/ui/modal/Modal.tsx | 4 +- 3 files changed, 79 insertions(+), 30 deletions(-) diff --git a/components/src/api/models/CompanySubscriptionResponseData.ts b/components/src/api/models/CompanySubscriptionResponseData.ts index b52f0edd..a8a36ee8 100644 --- a/components/src/api/models/CompanySubscriptionResponseData.ts +++ b/components/src/api/models/CompanySubscriptionResponseData.ts @@ -74,6 +74,12 @@ export interface CompanySubscriptionResponseData { * @memberof CompanySubscriptionResponseData */ products: Array; + /** + * + * @type {string} + * @memberof CompanySubscriptionResponseData + */ + status: string; /** * * @type {string} @@ -101,6 +107,7 @@ export function instanceOfCompanySubscriptionResponseData( return false; if (!("interval" in value) || value["interval"] === undefined) return false; if (!("products" in value) || value["products"] === undefined) return false; + if (!("status" in value) || value["status"] === undefined) return false; if ( !("subscriptionExternalId" in value) || value["subscriptionExternalId"] === undefined @@ -140,6 +147,7 @@ export function CompanySubscriptionResponseDataFromJSONTyped( products: (json["products"] as Array).map( BillingProductForSubscriptionResponseDataFromJSON, ), + status: json["status"], subscriptionExternalId: json["subscription_external_id"], totalPrice: json["total_price"], }; @@ -163,6 +171,7 @@ export function CompanySubscriptionResponseDataToJSON( products: (value["products"] as Array).map( BillingProductForSubscriptionResponseDataToJSON, ), + status: value["status"], subscription_external_id: value["subscriptionExternalId"], total_price: value["totalPrice"], }; diff --git a/components/src/components/elements/plan-manager/CheckoutDialog.tsx b/components/src/components/elements/plan-manager/CheckoutDialog.tsx index fe46a603..52e0d883 100644 --- a/components/src/components/elements/plan-manager/CheckoutDialog.tsx +++ b/components/src/components/elements/plan-manager/CheckoutDialog.tsx @@ -1,4 +1,4 @@ -import { useCallback, useMemo, useState } from "react"; +import { useCallback, useLayoutEffect, useMemo, useState } from "react"; import { useTheme } from "styled-components"; import pluralize from "pluralize"; import type { @@ -100,6 +100,7 @@ export const CheckoutDialog = () => { dueNow: number; newCharges: number; proration: number; + periodStart: Date; }>(); const [paymentMethodId, setPaymentMethodId] = useState(); const [isLoading, setIsLoading] = useState(false); @@ -206,10 +207,16 @@ export const CheckoutDialog = () => { [selectedPlan, selectPlan], ); + useLayoutEffect(() => { + document.body.style.overflow = "hidden"; + return () => { + document.body.style.overflow = ""; + }; + }, []); + const allowCheckout = api && selectedPlan && - selectedPlan?.id !== currentPlan?.id && ((paymentMethod && !showPaymentForm) || paymentMethodId) && !isLoading; @@ -517,20 +524,19 @@ export const CheckoutDialog = () => { )} - {!(plan.current || plan.id === currentPlan?.id) && - plan.id !== selectedPlan?.id && ( - selectPlan(plan), - })} - $size="sm" - $color="primary" - $variant="outline" - > - Select - - )} + {plan.id !== selectedPlan?.id && ( + selectPlan(plan), + })} + $size="sm" + $color="primary" + $variant="outline" + > + Select + + )} ); @@ -592,14 +598,15 @@ export const CheckoutDialog = () => { { {currentPlan && ( - + { /> - + { )} + { $padding="1.5rem" > {selectedPlan && subscriptionPrice && ( - + { )} {charges && ( - + { $weight={theme.typography.text.fontWeight} $color={theme.typography.text.color} > - {formatCurrency(charges.dueNow)} + {formatCurrency(Math.max(0, charges.dueNow))} + + + + )} + + {charges?.dueNow && charges.dueNow < 0 && ( + + + + Credits to be applied to future invoices: + + + + + + {formatCurrency(Math.abs(charges.dueNow))} @@ -998,11 +1040,9 @@ export const CheckoutDialog = () => { $weight={theme.typography.text.fontWeight} $color={theme.typography.text.color} > - {checkoutStage === "plan" - ? "Discounts & credits applied at checkout" - : subscriptionPrice && - `You will be billed ${subscriptionPrice} for this subscription - every ${planPeriod} on the ${data.subscription?.latestInvoice?.dueDate && formatOrdinal(new Date(data.subscription.latestInvoice.dueDate).getDate())} ${planPeriod === "year" && data.subscription?.latestInvoice?.dueDate ? `of ${getMonthName(data.subscription.latestInvoice.dueDate)}` : ""} unless you unsubscribe.`} + {subscriptionPrice && + `You will be billed ${subscriptionPrice} for this subscription + every ${planPeriod} ${charges?.periodStart ? `on the ${formatOrdinal(charges.periodStart.getDate())}` : ""} ${planPeriod === "year" && charges?.periodStart ? `of ${getMonthName(charges.periodStart)}` : ""} unless you unsubscribe.`} diff --git a/components/src/components/ui/modal/Modal.tsx b/components/src/components/ui/modal/Modal.tsx index 82fd1384..a5f882c8 100644 --- a/components/src/components/ui/modal/Modal.tsx +++ b/components/src/components/ui/modal/Modal.tsx @@ -67,8 +67,8 @@ export const Modal = ({ children, size = "auto", onClose }: ModalProps) => { : { $width: "100%", $height: "100%", - $maxWidth: "1366px", - $maxHeight: "768px", + $maxWidth: "1356px", + $maxHeight: "860px", })} $backgroundColor={theme.card.background} $borderRadius="0.5rem"