This is a React Vite app that demonstrates some of the features of @wayflyer/sdk
You can see a live example at https://sdk-cta-ui-reference-app.vercel.app/
Use the Select Scenario button to choose a scenario and see how the UI reacts.
Use the Select Theme button to choose a theme and see how the UI reacts. The partnerDesignId prop applies a visual theme to the banner.
We love devcontainers at Wayflyer. This project contains a .devcontainer/devcontainer.json file so you can quickly get started using VS Code or one of many editors that support devcontainers. Open the command palette and choose Dev Containers: Clone Repository in Container Volume... and paste the URL of this repo.
If you don't want to use a devcontainer you can just clone the repo in the normal way.
From your terminal:
- Install dependencies with
pnpm i - Run the app with
pnpm dev
You should now be able to access the app at http://localhost:5173
This is a Vite application, and the dev mode can be quite slow. You can build and preview the app by running pnpm build && pnpm preview. Just make sure to run pnpm build again after making any changes.
The Wayflyer CTA UI SDK is initialized in src/components/banner/Banner.tsx. From there, you can see how to:
-
Create a new UI SDK instance with your company token
-
In production this would be minted from the API by exchanging your partner token; consult the documentation at https://docs.wayflyer.com for more instructions.
-
Builds a mockedMode object:
const mockedMode: MockedModeType = { isMockedMode, sdkScenario: scenario};- isMockedMode: When true, the SDK uses mock responses instead of calling the real API.
- sdkScenario: One of the predefined SdkScenarios that determines the type of banner to display.
-
Calls:
const sdk = await WayflyerUiSdk.loadSdk( targetId, partnerDesignId, partnerCallback, companyToken, mockedMode, ); sdk.mountCta();
The banner is mounted into the DOM element with the targetId provided to the component. By default, this is ui-banner-container:
<div id="ui-banner-container"></div>The UI SDK is currently still under active development and is configured to always intercept requests to the Wayflyer API and return mocked responses.
When running in mocked mode, you can preview different banner states by changing the scenario prop. These scenarios are defined in the SdkScenarios enum and typically include:
- Indicative Offer: Simulates a customer who hasn`t started an application but has an indicative offer based on partner data. Displays a personalized offer and CTA to apply.
- Generic New Application: Simulates a customer who hasn't started an application and lacks sufficient data for an indicative offer. Shows a generic invitation to apply for financing.
- Continue Application: Simulates a customer with an incomplete application. Shows progress-related messaging and CTAs encouraging them to finish applying.
- No CTA: Simulates a customer who sees no banner, either due to ineligibility or no relevant CTAs at this time.
- Simulate auth errors
The repo comes with a .env file in the root that starts the UI SDK in mocked mode with a fake company token. You can override the values in this file by creating a .env.local file. Any keys in .env.local will be used instead of the values from .env. The .gitignore is configured to ignore .env.local
To use it for real
- Use the
get-company-tokencommand to create a Company Token using your Client ID and Client Secret - Create a
.env.localif you haven't already - Override
VITE_WF_COMPANY_TOKENin.env.localwith the Company Token you just generated. - Override
VITE_WF_MOCKED_MODEto"false"(or any value except"true") in.env.local