Skip to Content

Funnel Screens

Web-to-app funnel screens: questions, a paywall with the URL discount priced in, Stripe checkout and the post-purchase redemption card.

Build your plan

What is your main goal?
import { WebFunnel } from "@dapplelight/signet-ui/screens/funnel-screens"
import { page } from "./funnel"

function WebFunnelDemo() {
  return (
    <WebFunnel
      className="w-full max-w-xl"
      page={page}
      code="WELCOME20"
      onCheckout={() => undefined}
      display={{ pro: { name: "Pro", features: ["Unlimited workouts", "Meal plans"] } }}
    />
  )
}

Installation

npm i @dapplelight/signet-ui

Usage

import {
  WebFunnel,
  FunnelQuestion,
  ExpressCheckout,
  FunnelRedemption,
} from "@dapplelight/signet-ui/screens/funnel-screens"

Props are shaped like signet-server's funnel routes JSON; actions come out as callbacks, so any client fits.

import { ExpressCheckout, WebFunnel } from "@dapplelight/signet-ui/screens/funnel-screens"
import { page, startCheckout } from "./funnel"

<WebFunnel page={page} onCheckout={startCheckout} renderCheckout={(r) => <ExpressCheckout {...r} />} />

Examples

WebFunnel

Build your plan

What is your main goal?
import { WebFunnel } from "@dapplelight/signet-ui/screens/funnel-screens"
import { page } from "./funnel"

function WebFunnelDemo() {
  return (
    <WebFunnel
      className="w-full max-w-xl"
      page={page}
      code="WELCOME20"
      onCheckout={() => undefined}
      display={{ pro: { name: "Pro", features: ["Unlimited workouts", "Meal plans"] } }}
    />
  )
}

FunnelQuestion

What is your main goal?
import { useState } from "react"
import { FunnelQuestion } from "@dapplelight/signet-ui/screens/funnel-screens"
import { page } from "./funnel"

function FunnelQuestionDemo() {
  const [value, setValue] = useState<string | string[]>()
  return (
    <FunnelQuestion
      className="w-full max-w-md"
      question={page.funnel.questions![0]}
      value={value}
      onAnswer={setValue}
    />
  )
}

ExpressCheckout

Stripe.js loads from Stripe at runtime; this demo passes a stand-in loadStripe so no key or network is needed.

or pay by card

import { ExpressCheckout } from "@dapplelight/signet-ui/screens/funnel-screens"

function ExpressCheckoutDemo() {
  // A stand-in for Stripe.js so the demo needs no network or keys.
  const loadStripe = async () => ({
    elements: () => ({
      create: () => ({
        mount: (el: HTMLElement) => {
          el.textContent = "Payment Element mounts here"
        },
        on: () => undefined,
      }),
      submit: async () => ({}),
    }),
    confirmPayment: async () => ({}),
  })
  return (
    <ExpressCheckout
      className="w-full max-w-md"
      publishableKey="pk_test_example"
      clientSecret="pi_example_secret_example"
      returnUrl="https://example.com/funnel?session=ses_8f2a"
      amount={6320}
      currency="USD"
      loadStripe={loadStripe}
    />
  )
}

FunnelRedemption

You're in. Open the app to unlock your plan.

Open the app

Or paste this code in the app

K7QX-92PD
import { FunnelRedemption } from "@dapplelight/signet-ui/screens/funnel-screens"

function FunnelRedemptionDemo() {
  return (
    <FunnelRedemption
      className="w-full max-w-md"
      data={{
        session: { id: "ses_8f2a", status: "paid", plan: "pro" },
        redemption: { link: "https://app.example.com/redeem?t=K7QX-92PD", token: "K7QX-92PD" },
      }}
    />
  )
}

API Reference

All screens accept the props of their root element and labels (Partial<FunnelLabels>, defaults in DEFAULT_FUNNEL_LABELS).

WebFunnel

PropTypeDefaultDescription
pageFunnelPageViewrequiredThe funnel, its offering and the URL's discounts per product.
codestring""The discount code from the URL, shown in the checkout step.
onStep(step: string) => void-A step was shown: a question id, "plans" or "checkout".
onCheckout(request: FunnelCheckoutRequest) => unknownrequiredStart the checkout. Its result goes to renderCheckout.
renderCheckout(result: unknown) => ReactNode-Render the gateway step, e.g. ExpressCheckout.
displayRecord<string, Partial<BillingPlan>>-Names, descriptions and features per plan key for the paywall.

FunnelQuestion

PropTypeDefaultDescription
questionFunnelQuestionViewrequiredid, title, options and multiple.
valuestring | string[]-The current answer.
onAnswer(value: string | string[]) => voidrequiredSingle choice answers on click; multiple choice on Continue.

ExpressCheckout

PropTypeDefaultDescription
publishableKeystringrequiredStripe publishable key.
clientSecretstringrequiredThe checkout's PaymentIntent client secret.
returnUrlstringrequiredWhere Stripe sends the buyer back (the funnel page with ?session=).
amountnumberrequiredAmount in minor units.
currencystringrequiredCurrency code.
loadStripe(publishableKey: string) => Promise<StripeLike>loads STRIPE_JS_URLReturn Stripe(key).

FunnelRedemption

PropTypeDefaultDescription
dataFunnelSessionView | nullrequiredThe latest session read; null while the first read is in flight. Poll until paid.

Helpers

ExportDescription
discountedOffering(offering, discounts)The offering with each valid discount priced into its product.
loadScript(src)Load a script once per page.
STRIPE_JS_URLThe Stripe.js URL.