Skip to content

Commit 74edbc0

Browse files
authored
[SCH-3924] Trial checkout bug (#492)
1 parent 4502790 commit 74edbc0

File tree

16 files changed

+94
-44
lines changed

16 files changed

+94
-44
lines changed

components/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@schematichq/schematic-components",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"main": "dist/schematic-components.cjs.js",
55
"module": "dist/schematic-components.esm.js",
66
"types": "dist/schematic-components.d.ts",
@@ -46,14 +46,14 @@
4646
"@eslint/json": "^0.13.0",
4747
"@eslint/markdown": "^7.0.0",
4848
"@microsoft/api-extractor": "^7.52.8",
49-
"@openapitools/openapi-generator-cli": "^2.21.2",
49+
"@openapitools/openapi-generator-cli": "^2.21.3",
5050
"@stripe/react-stripe-js": "^3.7.0",
5151
"@types/jest": "^30.0.0",
5252
"@types/lodash": "^4.17.20",
5353
"@types/pako": "^2.0.3",
5454
"@types/react": "^19.1.8",
5555
"@types/react-dom": "^19.1.6",
56-
"esbuild": "^0.25.6",
56+
"esbuild": "^0.25.8",
5757
"eslint": "^9.31.0",
5858
"eslint-import-resolver-typescript": "^4.4.4",
5959
"eslint-plugin-import": "^2.32.0",

components/src/components/elements/metered-features/PriceDetails.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ export const PriceDetails = ({
5151
: currentTier?.perUnitPrice,
5252
};
5353

54-
if (
55-
typeof feature === "undefined" ||
56-
typeof currentTierPerUnitPrice !== "number"
57-
) {
54+
if (!feature || typeof currentTierPerUnitPrice !== "number") {
5855
return null;
5956
}
6057

components/src/components/elements/payment-method/PaymentMethodDetails.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,7 @@ export const PaymentMethodDetails = ({
326326
))}
327327
</Flex>
328328

329-
{(!setupIntent ||
330-
!currentPaymentMethod ||
331-
showDifferentPaymentMethods) && (
329+
{(!setupIntent || !currentPaymentMethod) && (
332330
<Button
333331
type="button"
334332
onClick={initializePaymentMethod}

components/src/components/elements/plan-manager/AddOn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const AddOn = ({ addOn, currency, layout }: AddOnProps) => {
2525
>
2626
<Text display={layout.addOns.fontStyle}>{addOn.name}</Text>
2727

28-
{addOn.planPrice && addOn.planPeriod && (
28+
{typeof addOn.planPrice === "number" && addOn.planPeriod && (
2929
<Text>
3030
{formatCurrency(addOn.planPrice, currency)}
3131
<sub>

components/src/components/elements/plan-manager/PlanManager.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const PlanManager = forwardRef<
9292

9393
const isLightBackground = useIsLightBackground();
9494

95-
const trialEndDays = useTrialEnd();
95+
const trialEnd = useTrialEnd();
9696

9797
/**
9898
* Can change plan if there is:
@@ -171,9 +171,9 @@ export const PlanManager = forwardRef<
171171
: lighten(settings.theme.card.background, 0.04)
172172
}
173173
>
174-
{trialEndDays && (
174+
{typeof trialEnd.formatted !== "undefined" && (
175175
<Text as="h3" display="heading3">
176-
{t("Trial ends in", { days: trialEndDays })}
176+
{trialEnd.formatted}
177177
</Text>
178178
)}
179179

@@ -207,7 +207,7 @@ export const PlanManager = forwardRef<
207207
{t("Subscription canceled")}
208208
</Text>
209209

210-
{billingSubscription?.cancelAt && (
210+
{typeof billingSubscription?.cancelAt === "number" && (
211211
<Text
212212
as="p"
213213
$size={0.8125 * settings.theme.typography.text.fontSize}

components/src/components/elements/pricing-table/Plan.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const Plan = ({
6060

6161
const isLightBackground = useIsLightBackground();
6262

63-
const trialEndDays = useTrialEnd();
63+
const trialEnd = useTrialEnd();
6464

6565
const {
6666
currentPeriod,
@@ -73,7 +73,8 @@ export const Plan = ({
7373
if (isCheckoutData(data)) {
7474
const billingSubscription = data.company?.billingSubscription;
7575
const isTrialSubscription = billingSubscription?.status === "trialing";
76-
const willSubscriptionCancel = billingSubscription?.cancelAt;
76+
const willSubscriptionCancel =
77+
typeof billingSubscription?.cancelAt === "number";
7778

7879
return {
7980
currentPeriod: data.company?.plan?.planPeriod || "month",
@@ -192,8 +193,10 @@ export const Plan = ({
192193
hexToHSL(settings.theme.primary).l > 50 ? "#000000" : "#FFFFFF"
193194
}
194195
>
195-
{isTrialSubscription && !willSubscriptionCancel && trialEndDays
196-
? t("Trial ends in", { days: trialEndDays })
196+
{isTrialSubscription &&
197+
!willSubscriptionCancel &&
198+
typeof trialEnd !== "undefined"
199+
? trialEnd.formatted
197200
: t("Active")}
198201
</Text>
199202
</Flex>

components/src/components/elements/upcoming-bill/UpcomingBill.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export const UpcomingBill = forwardRef<
237237
})
238238
: t("Amount off", {
239239
amount: formatCurrency(
240-
discount.amountOff as number,
240+
discount.amountOff as number, // we already checked for `number` type
241241
discount?.currency,
242242
),
243243
})}

components/src/components/layout/viewport/Viewport.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ export const Viewport = forwardRef<HTMLDivElement | null, ViewportProps>(
6262
{canCheckout &&
6363
layout === "checkout" &&
6464
createPortal(<CheckoutDialog top={top} />, portal || document.body)}
65+
6566
{layout === "unsubscribe" &&
6667
createPortal(
6768
<UnsubscribeDialog top={top} />,
6869
portal || document.body,
6970
)}
71+
7072
{layout === "payment" &&
7173
createPortal(<PaymentDialog top={top} />, portal || document.body)}
7274
</>

components/src/components/shared/pricing-tiers-tooltip/PricingTiersTooltip.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useMemo } from "react";
22
import { useTranslation } from "react-i18next";
33

44
import { type BillingProductPriceTierResponseData } from "../../../api/checkoutexternal";
5+
import { TiersMode } from "../../../const";
56
import { useEmbed, useIsLightBackground } from "../../../hooks";
67
import type { Feature } from "../../../types";
78
import { Box, Flex, Icon, Text, Tooltip } from "../../ui";
@@ -103,7 +104,9 @@ export const PricingTiersTooltip = ({
103104
);
104105
})}
105106
</dl>
106-
{tiersMode && (
107+
108+
{(tiersMode === TiersMode.Volume ||
109+
tiersMode === TiersMode.Graduated) && (
107110
<>
108111
<hr
109112
style={{
@@ -115,7 +118,7 @@ export const PricingTiersTooltip = ({
115118
<Box>
116119
<Text>
117120
ℹ️{" "}
118-
{tiersMode === "volume"
121+
{tiersMode === TiersMode.Volume
119122
? t("Price by unit based on final tier reached.")
120123
: t("Tiers apply progressively as quantity increases.")}
121124
</Text>

components/src/components/shared/unsubscribe-dialog/UnsubscribeDialog.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@ export const UnsubscribeDialog = ({ top = 0 }: UnsubscribeDialogProps) => {
100100
{t(
101101
"You will retain access to your plan until the end of the billing period, on",
102102
)}{" "}
103-
{cancelDate
104-
? toPrettyDate(cancelDate, {
105-
month: "numeric",
106-
})
107-
: ""}
103+
{toPrettyDate(cancelDate, {
104+
month: "numeric",
105+
})}
108106
</Text>
109107
</Flex>
110108

0 commit comments

Comments
 (0)