@wf-financing/ui 1.1.2 → 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/global.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { IWayflyerUiCtaSdkConstructor, IHeadlessWayflyerCtaSdkConstructor } from '@wf-financing/embedded-types';
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: IHeadlessWayflyerCtaSdkConstructor;
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.1.2",
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.5"
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 { IHeadlessWayflyerCtaSdk, MockedModeType } from '@wf-financing/embedded-types';
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: IHeadlessWayflyerCtaSdk | null = null;
6
+ let cachedSdkInstance: IHeadlessWayflyerSdk | null = null;
7
7
 
8
8
  export const getHeadlessSdkInstance = async (companyToken: string, mockedMode?: MockedModeType) => {
9
9
  try {
@@ -33,7 +33,7 @@ export const getHeadlessSdkInstance = async (companyToken: string, mockedMode?:
33
33
 
34
34
  document.head.appendChild(script);
35
35
 
36
- const headlessSdk: IHeadlessWayflyerCtaSdk = await loadScriptAndInitializeSdk(script, companyToken, mockedMode);
36
+ const headlessSdk: IHeadlessWayflyerSdk = await loadScriptAndInitializeSdk(script, companyToken, mockedMode);
37
37
  cachedSdkInstance = headlessSdk;
38
38
 
39
39
  return headlessSdk;
@@ -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/useCtaBanner';
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/useCtaBanner';
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 handleButtonClick = () => {
29
+ const handleContinueHostedApplication = () => {
28
30
  switch (state) {
29
31
  case CtaStateType.CONTINUE_APPLICATION:
30
- window.open(config?.redirect_url, '_blank');
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={handleButtonClick}>
50
+ <Button variant="Primary" fullWidth onClick={handleContinueHostedApplication}>
41
51
  {config?.button_label}
42
52
  </Button>
43
53
  <ConsentModal isModalOpen={isModalOpen} setIsModalOpen={setIsModalOpen} />
@@ -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
+ };
@@ -1,6 +1,6 @@
1
- import { IHeadlessWayflyerCtaSdk, MockedModeType } from '@wf-financing/embedded-types';
1
+ import { IHeadlessWayflyerSdk, MockedModeType } from '@wf-financing/embedded-types';
2
2
 
3
- export const initializeHeadlessSdk = (companyToken: string, mockedMode?: MockedModeType): IHeadlessWayflyerCtaSdk => {
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 { IHeadlessWayflyerCtaSdk, MockedModeType } from '@wf-financing/embedded-types';
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<IHeadlessWayflyerCtaSdk> => {
10
- return new Promise<IHeadlessWayflyerCtaSdk>((resolve, reject) => {
9
+ ): Promise<IHeadlessWayflyerSdk> => {
10
+ return new Promise<IHeadlessWayflyerSdk>((resolve, reject) => {
11
11
  script.onload = () => {
12
12
  try {
13
13
  resolve(initializeHeadlessSdk(companyToken, mockedMode));