@wf-financing/ui 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/index.es.js +6828 -6791
- package/global.d.ts +2 -2
- package/package.json +2 -2
- package/src/api/continueHostedApplication.ts +12 -0
- package/src/api/getHeadlessSdkInstance.ts +3 -4
- package/src/components/banner/{CtaBanner.stories.tsx → CtaBanner.snapshot.stories.tsx} +1 -1
- package/src/components/banner/CtaBannerContent.tsx +1 -1
- package/src/components/banner/ProceedFundingButton.tsx +14 -4
- package/src/components/modal/{ConsentModal.stories.tsx → ConsentModal.snapshot.stories.tsx} +1 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useContinueHostedApplication.ts +12 -0
- package/src/locales/en.json +1 -1
- package/src/utils/initializeHeadlessSdk.ts +2 -2
- package/src/utils/loadScriptAndInitializeSdk.ts +3 -3
- package/src/components/banner/BulletList.stories.tsx +0 -15
- /package/src/components/banner/{BannerContent.stories.tsx → BannerContent.snapshot.stories.tsx} +0 -0
package/global.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { IWayflyerUiCtaSdkConstructor,
|
|
1
|
+
import { IWayflyerUiCtaSdkConstructor, IHeadlessWayflyerSdkConstructor } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
interface Window {
|
|
5
5
|
WayflyerUiCtaSdk: IWayflyerUiCtaSdkConstructor;
|
|
6
|
-
WayflyerHeadlessSdk:
|
|
6
|
+
WayflyerHeadlessSdk: IHeadlessWayflyerSdkConstructor;
|
|
7
7
|
}
|
|
8
8
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wf-financing/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"import": "./dist/index.es.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"react-aria": "^3.41.1",
|
|
39
39
|
"react-intl": "^6.2.5",
|
|
40
40
|
"styled-components": "^6.1.19",
|
|
41
|
-
"@wf-financing/embedded-types": "0.2.
|
|
41
|
+
"@wf-financing/embedded-types": "0.2.6"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ContinueHostedApplicationResponseType, MockedModeType } from '@wf-financing/embedded-types';
|
|
2
|
+
|
|
3
|
+
import { getHeadlessSdkInstance } from './getHeadlessSdkInstance';
|
|
4
|
+
|
|
5
|
+
export const continueHostedApplication = async (
|
|
6
|
+
companyToken: string,
|
|
7
|
+
mockedMode?: MockedModeType,
|
|
8
|
+
): Promise<ContinueHostedApplicationResponseType> => {
|
|
9
|
+
const sdk = await getHeadlessSdkInstance(companyToken, mockedMode);
|
|
10
|
+
|
|
11
|
+
return await sdk.continueHostedApplication();
|
|
12
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IHeadlessWayflyerSdk, MockedModeType } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
3
|
import { HEADLESS_SDK_URL, WAYFLYER_HEADLESS_SDK_ID } from '../config';
|
|
4
4
|
import { initializeHeadlessSdk, loadScriptAndInitializeSdk } from '../utils';
|
|
5
5
|
|
|
6
|
-
let cachedSdkInstance:
|
|
6
|
+
let cachedSdkInstance: IHeadlessWayflyerSdk | null = null;
|
|
7
7
|
|
|
8
8
|
export const getHeadlessSdkInstance = async (companyToken: string, mockedMode?: MockedModeType) => {
|
|
9
9
|
try {
|
|
@@ -31,10 +31,9 @@ export const getHeadlessSdkInstance = async (companyToken: string, mockedMode?:
|
|
|
31
31
|
script.id = WAYFLYER_HEADLESS_SDK_ID;
|
|
32
32
|
script.async = true;
|
|
33
33
|
|
|
34
|
-
console.log(script, 'script');
|
|
35
34
|
document.head.appendChild(script);
|
|
36
35
|
|
|
37
|
-
const headlessSdk:
|
|
36
|
+
const headlessSdk: IHeadlessWayflyerSdk = await loadScriptAndInitializeSdk(script, companyToken, mockedMode);
|
|
38
37
|
cachedSdkInstance = headlessSdk;
|
|
39
38
|
|
|
40
39
|
return headlessSdk;
|
|
@@ -34,7 +34,7 @@ const meta: Meta<typeof CtaBanner> = {
|
|
|
34
34
|
sdkScenario: SdkScenarios.GENERIC_NEW_APPLICATION,
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
|
-
decorators: [(
|
|
37
|
+
decorators: [(_, context) => <Template {...(context.args as CtaBannerStoryArgs)} />],
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
export default meta;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Flex, Text } from '@wayflyer/flyui';
|
|
2
2
|
import type { CtaResponseType } from '@wf-financing/embedded-types';
|
|
3
3
|
|
|
4
|
-
import { useCtaBanner } from '../../hooks
|
|
4
|
+
import { useCtaBanner } from '../../hooks';
|
|
5
5
|
import { BulletList } from './BulletList';
|
|
6
6
|
|
|
7
7
|
type CtaBannerContentProps = {
|
|
@@ -4,10 +4,11 @@ import {
|
|
|
4
4
|
CtaGenericOfferType,
|
|
5
5
|
CtaIndicativeOfferType,
|
|
6
6
|
CtaStateType,
|
|
7
|
+
ContinueHostedApplicationResponseType,
|
|
7
8
|
} from '@wf-financing/embedded-types';
|
|
8
9
|
import { useState } from 'react';
|
|
9
10
|
|
|
10
|
-
import { useCtaBanner } from '../../hooks
|
|
11
|
+
import { useCtaBanner, useContinueHostedApplication } from '../../hooks';
|
|
11
12
|
import { ConsentModal } from '../modal/ConsentModal';
|
|
12
13
|
|
|
13
14
|
type CtaResponseType = CtaGenericOfferType | CtaIndicativeOfferType | CtaContinueFundingType;
|
|
@@ -16,6 +17,7 @@ export const ProceedFundingButton = () => {
|
|
|
16
17
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
17
18
|
const sdkResponse = useCtaBanner();
|
|
18
19
|
const sdk = sdkResponse.data as CtaResponseType;
|
|
20
|
+
const continueHostedApplicationMutation = useContinueHostedApplication();
|
|
19
21
|
|
|
20
22
|
if (!sdk) return null;
|
|
21
23
|
|
|
@@ -24,10 +26,18 @@ export const ProceedFundingButton = () => {
|
|
|
24
26
|
data: { config },
|
|
25
27
|
} = sdk;
|
|
26
28
|
|
|
27
|
-
const
|
|
29
|
+
const handleContinueHostedApplication = () => {
|
|
28
30
|
switch (state) {
|
|
29
31
|
case CtaStateType.CONTINUE_APPLICATION:
|
|
30
|
-
|
|
32
|
+
continueHostedApplicationMutation.mutate(undefined, {
|
|
33
|
+
onSuccess: (nextUrl: ContinueHostedApplicationResponseType) => {
|
|
34
|
+
const { next } = nextUrl;
|
|
35
|
+
window.open(next);
|
|
36
|
+
},
|
|
37
|
+
onError: (error) => {
|
|
38
|
+
console.error('Failed to continue application', error);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
31
41
|
break;
|
|
32
42
|
default:
|
|
33
43
|
setIsModalOpen(true);
|
|
@@ -37,7 +47,7 @@ export const ProceedFundingButton = () => {
|
|
|
37
47
|
|
|
38
48
|
return (
|
|
39
49
|
<>
|
|
40
|
-
<Button variant="Primary" fullWidth onClick={
|
|
50
|
+
<Button variant="Primary" fullWidth onClick={handleContinueHostedApplication}>
|
|
41
51
|
{config?.button_label}
|
|
42
52
|
</Button>
|
|
43
53
|
<ConsentModal isModalOpen={isModalOpen} setIsModalOpen={setIsModalOpen} />
|
|
@@ -34,7 +34,7 @@ export const WithContent: Story = {
|
|
|
34
34
|
<div style={{ padding: '20px', background: 'white' }}>
|
|
35
35
|
<h2>Consent Agreement</h2>
|
|
36
36
|
<p>Please agree to the terms to proceed.</p>
|
|
37
|
-
<button>Continue
|
|
37
|
+
<button>Continue to Wayflyer</button>
|
|
38
38
|
<button>Cancel</button>
|
|
39
39
|
</div>
|
|
40
40
|
</ConsentModal>
|
package/src/hooks/index.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { usePartnerContext } from './usePartnerContext';
|
|
|
2
2
|
export { useCtaBanner } from './useCtaBanner';
|
|
3
3
|
export { useStartHostedApplication } from './useStartHostedApplication';
|
|
4
4
|
export { useDetectSmallScreen } from './useDetectSmallScreen';
|
|
5
|
+
export { useContinueHostedApplication } from './useContinueHostedApplication';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/react-query';
|
|
2
|
+
|
|
3
|
+
import { continueHostedApplication } from '../api/continueHostedApplication';
|
|
4
|
+
import { usePartnerContext } from './usePartnerContext';
|
|
5
|
+
|
|
6
|
+
export const useContinueHostedApplication = () => {
|
|
7
|
+
const { companyToken, mockedMode } = usePartnerContext();
|
|
8
|
+
|
|
9
|
+
return useMutation({
|
|
10
|
+
mutationFn: () => continueHostedApplication(companyToken, mockedMode),
|
|
11
|
+
});
|
|
12
|
+
};
|
package/src/locales/en.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"common.dismiss": "Dismiss",
|
|
4
4
|
"ctaModal.call": "Get funded",
|
|
5
5
|
"ctaModal.title": "Fuel your growth with capital from Wayflyer",
|
|
6
|
-
"ctaModal.action": "Continue
|
|
6
|
+
"ctaModal.action": "Continue to Wayflyer",
|
|
7
7
|
"ctaModal.consent": "By proceeding, you consent to us sharing your information with Wayflyer so they can assess your eligibility for financing, in accordance with the Wayflyer ",
|
|
8
8
|
"ctaModal.consent.privacy_policy": "Privacy Policy.",
|
|
9
9
|
"ctaModal.step1.title": "Built for businesses like yours",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IHeadlessWayflyerSdk, MockedModeType } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
|
-
export const initializeHeadlessSdk = (companyToken: string, mockedMode?: MockedModeType):
|
|
3
|
+
export const initializeHeadlessSdk = (companyToken: string, mockedMode?: MockedModeType): IHeadlessWayflyerSdk => {
|
|
4
4
|
if (!window.WayflyerHeadlessSdk) {
|
|
5
5
|
throw new Error('Failed to load WayflyerHeadlessSdk from the script.');
|
|
6
6
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IHeadlessWayflyerSdk, MockedModeType } from '@wf-financing/embedded-types';
|
|
2
2
|
|
|
3
3
|
import { initializeHeadlessSdk } from './initializeHeadlessSdk';
|
|
4
4
|
|
|
@@ -6,8 +6,8 @@ export const loadScriptAndInitializeSdk = (
|
|
|
6
6
|
script: HTMLScriptElement,
|
|
7
7
|
companyToken: string,
|
|
8
8
|
mockedMode?: MockedModeType,
|
|
9
|
-
): Promise<
|
|
10
|
-
return new Promise<
|
|
9
|
+
): Promise<IHeadlessWayflyerSdk> => {
|
|
10
|
+
return new Promise<IHeadlessWayflyerSdk>((resolve, reject) => {
|
|
11
11
|
script.onload = () => {
|
|
12
12
|
try {
|
|
13
13
|
resolve(initializeHeadlessSdk(companyToken, mockedMode));
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { BulletList } from './BulletList';
|
|
3
|
-
|
|
4
|
-
const meta: Meta<typeof BulletList> = {
|
|
5
|
-
title: 'BulletList',
|
|
6
|
-
component: BulletList,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export default meta;
|
|
10
|
-
|
|
11
|
-
type Story = StoryObj<typeof BulletList>;
|
|
12
|
-
|
|
13
|
-
export const Default: Story = {
|
|
14
|
-
render: () => <BulletList items={['Item 1', 'Item 2', 'Item 3']} />,
|
|
15
|
-
};
|
/package/src/components/banner/{BannerContent.stories.tsx → BannerContent.snapshot.stories.tsx}
RENAMED
|
File without changes
|