Skip to content

Commit

Permalink
sch-1881 (#74)
Browse files Browse the repository at this point in the history
* fix checkout help text

* copy adjustments; fix modal sizing

* finalize copy; allow current plan to be selected
  • Loading branch information
tenub authored Sep 26, 2024
1 parent d2090ac commit 1665daa
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 30 deletions.
9 changes: 9 additions & 0 deletions components/src/api/models/CompanySubscriptionResponseData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export interface CompanySubscriptionResponseData {
* @memberof CompanySubscriptionResponseData
*/
products: Array<BillingProductForSubscriptionResponseData>;
/**
*
* @type {string}
* @memberof CompanySubscriptionResponseData
*/
status: string;
/**
*
* @type {string}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -140,6 +147,7 @@ export function CompanySubscriptionResponseDataFromJSONTyped(
products: (json["products"] as Array<any>).map(
BillingProductForSubscriptionResponseDataFromJSON,
),
status: json["status"],
subscriptionExternalId: json["subscription_external_id"],
totalPrice: json["total_price"],
};
Expand All @@ -163,6 +171,7 @@ export function CompanySubscriptionResponseDataToJSON(
products: (value["products"] as Array<any>).map(
BillingProductForSubscriptionResponseDataToJSON,
),
status: value["status"],
subscription_external_id: value["subscriptionExternalId"],
total_price: value["totalPrice"],
};
Expand Down
96 changes: 68 additions & 28 deletions components/src/components/elements/plan-manager/CheckoutDialog.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -100,6 +100,7 @@ export const CheckoutDialog = () => {
dueNow: number;
newCharges: number;
proration: number;
periodStart: Date;
}>();
const [paymentMethodId, setPaymentMethodId] = useState<string | undefined>();
const [isLoading, setIsLoading] = useState(false);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -517,20 +524,19 @@ export const CheckoutDialog = () => {
</Flex>
)}

{!(plan.current || plan.id === currentPlan?.id) &&
plan.id !== selectedPlan?.id && (
<StyledButton
disabled={plan.valid === false}
{...(plan.valid === true && {
onClick: () => selectPlan(plan),
})}
$size="sm"
$color="primary"
$variant="outline"
>
Select
</StyledButton>
)}
{plan.id !== selectedPlan?.id && (
<StyledButton
disabled={plan.valid === false}
{...(plan.valid === true && {
onClick: () => selectPlan(plan),
})}
$size="sm"
$color="primary"
$variant="outline"
>
Select
</StyledButton>
)}
</Flex>
</Flex>
);
Expand Down Expand Up @@ -592,14 +598,15 @@ export const CheckoutDialog = () => {

<Flex
$flexDirection="column"
$width="21.5rem"
$overflow="auto"
$backgroundColor={theme.card.background}
$borderRadius="0 0 0.5rem"
$width="21.5rem"
$boxShadow="0px 1px 20px 0px #1018280F, 0px 1px 3px 0px #1018281A;"
>
<Flex
$flexDirection="column"
$position="relative"
$flexDirection="column"
$gap="1rem"
$width="100%"
$height="auto"
Expand Down Expand Up @@ -727,7 +734,11 @@ export const CheckoutDialog = () => {

<Flex $flexDirection="column" $gap="0.5rem">
{currentPlan && (
<Flex $justifyContent="space-between" $alignItems="center">
<Flex
$justifyContent="space-between"
$alignItems="center"
$gap="1rem"
>
<Flex
{...(selectedPlan && {
$opacity: "0.625",
Expand Down Expand Up @@ -778,7 +789,11 @@ export const CheckoutDialog = () => {
/>
</Box>

<Flex $justifyContent="space-between" $alignItems="center">
<Flex
$justifyContent="space-between"
$alignItems="center"
$gap="1rem"
>
<Flex>
<Text
$font={theme.typography.heading4.fontFamily}
Expand Down Expand Up @@ -860,6 +875,7 @@ export const CheckoutDialog = () => {
</>
)}
</Flex>

<Flex
$flexDirection="column"
$position="relative"
Expand All @@ -869,7 +885,7 @@ export const CheckoutDialog = () => {
$padding="1.5rem"
>
{selectedPlan && subscriptionPrice && (
<Flex $justifyContent="space-between">
<Flex $justifyContent="space-between" $gap="1rem">
<Box $opacity="0.625">
<Text
$font={theme.typography.text.fontFamily}
Expand All @@ -895,7 +911,7 @@ export const CheckoutDialog = () => {
)}

{charges && (
<Flex $justifyContent="space-between">
<Flex $justifyContent="space-between" $gap="1rem">
<Box $opacity="0.625">
<Text
$font={theme.typography.text.fontFamily}
Expand All @@ -914,7 +930,33 @@ export const CheckoutDialog = () => {
$weight={theme.typography.text.fontWeight}
$color={theme.typography.text.color}
>
{formatCurrency(charges.dueNow)}
{formatCurrency(Math.max(0, charges.dueNow))}
</Text>
</Box>
</Flex>
)}

{charges?.dueNow && charges.dueNow < 0 && (
<Flex $justifyContent="space-between" $gap="1rem">
<Box $opacity="0.625">
<Text
$font={theme.typography.text.fontFamily}
$size={theme.typography.text.fontSize}
$weight={theme.typography.text.fontWeight}
$color={theme.typography.text.color}
>
Credits to be applied to future invoices:
</Text>
</Box>

<Box>
<Text
$font={theme.typography.text.fontFamily}
$size={theme.typography.text.fontSize}
$weight={theme.typography.text.fontWeight}
$color={theme.typography.text.color}
>
{formatCurrency(Math.abs(charges.dueNow))}
</Text>
</Box>
</Flex>
Expand Down Expand Up @@ -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.`}
</Text>
</Box>
</Flex>
Expand Down
4 changes: 2 additions & 2 deletions components/src/components/ui/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 1665daa

Please sign in to comment.