Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion hosted/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ describe("an account with no plan", () => {
expect(buyButton("Founding")).toBeNull();
});

it("tells a lapsed founder why a card's checkout is at the list price", async () => {
vi.mocked(api.getHostedVoice).mockResolvedValue({ entitled: false, on: false });
vi.mocked(api.getBilling).mockResolvedValue({ ...NO_PLAN, founding: null, foundingLapsed: true });
await mount(ENROLLMENT);
await act(async () => buyButton("Hosted monthly")!.click());
expect(container.querySelector('input[name="plan"]')).toBeNull();
expect(text()).toContain("subscribing again is at the list price");
});

it("offers founding at the server's open cohort, the price checkout charges", async () => {
vi.mocked(api.getHostedVoice).mockResolvedValue({ entitled: false, on: false });
vi.mocked(api.getBilling).mockResolvedValue({ ...NO_PLAN, founding: { cohort: 1, seatsLeft: 3 } });
Expand All @@ -318,7 +327,9 @@ describe("an account with no plan", () => {
vi.mocked(api.getBilling).mockResolvedValue(NO_PLAN);
await mount(ENROLLMENT);
await act(async () => buyButton("Hosted monthly")!.click());
expect(container.querySelector<HTMLInputElement>('input[value="monthly"]')!.checked).toBe(true);
// The card chose: checkout names that plan alone, with no others to pick.
expect(container.querySelector('input[name="plan"]')).toBeNull();
expect(text()).toContain("Hosted monthly$10/month");
await tick("agree-terms");
await tick("agree-renewal");
await click("Continue to payment");
Expand Down
111 changes: 67 additions & 44 deletions hosted/src/Checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,45 @@ function Terms({ offer }: { offer: Tier }) {
);
}

/** A plan's name and price, and the line under it. */
function OfferLine({ offer, billing }: { offer: Tier; billing: BillingSummary }) {
return (
<span className="min-w-0 flex-1">
<span className="flex flex-wrap items-baseline justify-between gap-x-3">
<span className="font-display text-lg">{offer.name}</span>
<span>
{offer.listPrice && <s className={`mr-2 ${MUTED_TEXT_CLASS}`}>${offer.listPrice}</s>}
<span className="font-display text-lg">{perInterval(offer.price, planInterval(offer.id))}</span>
</span>
</span>
{offer.id === "founding" && billing.founding && (
<span className={`block text-sm ${MUTED_TEXT_CLASS}`}>
Locked while you stay subscribed. {billing.founding.seatsLeft} left at this price.
</span>
)}
{offer.id === "yearly" && (
<span className={`block text-sm ${MUTED_TEXT_CLASS}`}>Two months free against monthly.</span>
)}
</span>
);
}

/**
* The plans on sale, what each commits the buyer to, and the purchase action
* behind affirmative agreement to the current terms and to automatic renewal.
*/
export function Checkout({
billing,
plan,
picked = false,
busy,
onPurchase,
}: {
billing: BillingSummary;
/** The plan the link named, chosen first when on sale. */
plan: Plan | null;
/** Chosen already, on a plan card: shown alone while on sale, the others a step back. */
picked?: boolean;
busy: string;
/** With the price shown beside the renewal the buyer agreed to. */
onPurchase: (plan: Plan, price: number) => void;
Expand All @@ -57,56 +83,53 @@ export function Checkout({
const [terms, setTerms] = useState(false);
const [renewal, setRenewal] = useState(false);
const offer = offers.find((each) => each.id === chosen)!;
// Sold out since its card was clicked, the plan offers the rest to choose from.
const alone = picked && offer.id === plan;
function submit(event: FormEvent) {
event.preventDefault();
if (terms && renewal && !busy) onPurchase(chosen, offer.price);
}
return (
<form onSubmit={submit}>
<fieldset>
<legend className="mb-3 font-display text-xl">Choose a plan</legend>
{billing.foundingLapsed && (
<p className={HELP_CLASS}>Your founding price ended with your earlier subscription, so subscribing again is at the list price.</p>
)}
{offers.map((each) => (
<label
key={each.id}
className={`${CARD_CLASS} mb-2 flex cursor-pointer items-start gap-3 ${each.id === chosen ? ACCENT_BORDER_CLASS : ""}`}
>
<input
id={`${each.id}-plan`}
type="radio"
name="plan"
value={each.id}
className={CHECK_CLASS}
checked={each.id === chosen}
disabled={!!busy}
onChange={() => {
setChosen(each.id);
// Renewal was agreed at the other plan's price and interval.
setRenewal(false);
}}
/>
<span className="min-w-0 flex-1">
<span className="flex flex-wrap items-baseline justify-between gap-x-3">
<span className="font-display text-lg">{each.name}</span>
<span>
{each.listPrice && <s className={`mr-2 ${MUTED_TEXT_CLASS}`}>${each.listPrice}</s>}
<span className="font-display text-lg">{perInterval(each.price, planInterval(each.id))}</span>
</span>
</span>
{each.id === "founding" && billing.founding && (
<span className={`block text-sm ${MUTED_TEXT_CLASS}`}>
Locked while you stay subscribed. {billing.founding.seatsLeft} left at this price.
</span>
)}
{each.id === "yearly" && (
<span className={`block text-sm ${MUTED_TEXT_CLASS}`}>Two months free against monthly.</span>
)}
</span>
</label>
))}
</fieldset>
{alone ? (
<>
{billing.foundingLapsed && (
<p className={HELP_CLASS}>Your founding price ended with your earlier subscription, so subscribing again is at the list price.</p>
)}
<div className={`${CARD_CLASS} ${ACCENT_BORDER_CLASS} flex`}>
<OfferLine offer={offer} billing={billing} />
</div>
</>
) : (
<fieldset>
<legend className="mb-3 font-display text-xl">Choose a plan</legend>
{billing.foundingLapsed && (
<p className={HELP_CLASS}>Your founding price ended with your earlier subscription, so subscribing again is at the list price.</p>
)}
{offers.map((each) => (
<label
key={each.id}
className={`${CARD_CLASS} mb-2 flex cursor-pointer items-start gap-3 ${each.id === chosen ? ACCENT_BORDER_CLASS : ""}`}
>
<input
id={`${each.id}-plan`}
type="radio"
name="plan"
value={each.id}
className={CHECK_CLASS}
checked={each.id === chosen}
disabled={!!busy}
onChange={() => {
setChosen(each.id);
// Renewal was agreed at the other plan's price and interval.
setRenewal(false);
}}
/>
<OfferLine offer={each} billing={billing} />
</label>
))}
</fieldset>
)}
<Terms offer={offer} />
<WithdrawalRight />
<label className="mt-6 flex items-start gap-3">
Expand Down
10 changes: 8 additions & 2 deletions hosted/src/HostedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ export function HostedPage({
</>
);

/** Checkout for `plan`, or why it cannot show; `ref` overrides the one this load arrived with. */
/**
* Checkout for `plan`, or why it cannot show. With `ref`, overriding the one
* this load arrived with, the plan was picked on a card.
*/
const checkoutFor = (plan: Plan | null, ref?: HostedRef) =>
!summary ? (
billingUnread
Expand All @@ -179,6 +182,7 @@ export function HostedPage({
key={summary.founding?.cohort ?? "closed"}
billing={summary}
plan={plan}
picked={!!ref}
busy={busy}
onPurchase={ref ? (chosen, price) => purchase(chosen, price, ref) : purchase}
/>
Expand Down Expand Up @@ -345,6 +349,8 @@ export function HostedPage({
{confirmed && (
<p className={HELP_CLASS}>Buying to approve a computer? Open the link from Dormouse on it again.</p>
)}
{/* A founder's one choice, ahead of the plan's details. */}
<div className="mb-6 empty:hidden">{founders}</div>
<PlanConfirmation billing={{ ...summary, plan: summary.plan }} busy={busy} onManage={manageBilling} />
{summary.withdrawal && (
<WithdrawalFunction offer={summary.withdrawal} plan={summary.plan} busy={busy} onWithdraw={withdraw} />
Expand All @@ -354,9 +360,9 @@ export function HostedPage({
<>
<p className={HELP_CLASS}>This account has no plan.</p>
<ChoosePlan />
{founders}
</>
)}
{founders}
{backToAccount}
</section>
) : session ? (
Expand Down
5 changes: 3 additions & 2 deletions hosted/src/stories/Enrollment.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ export const NoPlanCheckoutOpen: Story = {
// Pressed directly: the button unmounts as it is pressed, which the
// instrumented focus of a user click cannot follow across the frame.
canvas.getByRole("button", { name: "Buy Founding" }).click();
await expect(await canvas.findByRole("radio", { name: /Founding/ })).toBeChecked();
await expect(canvas.getByRole("button", { name: "Continue to payment" })).toBeDisabled();
// The card chose, so checkout names Founding alone.
await expect(await canvas.findByRole("button", { name: "Continue to payment" })).toBeDisabled();
await expect(canvas.queryByRole("radio")).toBeNull();
},
};
export const InvalidLink: Story = { args: { enrolling: { code: null } } };
Expand Down
Loading