@wf-financing/ui 0.1.0 → 0.1.1

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/dist/index.es.js CHANGED
@@ -90920,25 +90920,24 @@ const Htt = /* @__PURE__ */ k.forwardRef(Btt), ztt = [
90920
90920
  ]
90921
90921
  }
90922
90922
  ) }) }) });
90923
- }, Xtt = async (e, t, n) => await (await Qde(e, t)).startHostedApplication(n), Ktt = () => {
90924
- const { companyToken: e, isMockedMode: t } = k.useContext(mH);
90923
+ }, Xtt = async (e, t, n) => {
90924
+ let r = await n();
90925
+ const i = await Qde(e, t);
90926
+ return r || (r = {}), await i.startHostedApplication(r);
90927
+ }, Ktt = () => {
90928
+ const { companyToken: e, isMockedMode: t, partnerCallback: n } = k.useContext(mH);
90925
90929
  return Aye({
90926
- mutationFn: ({
90927
- partnerData: n
90928
- }) => Xtt(e, t, n)
90930
+ mutationFn: () => Xtt(e, t, n)
90929
90931
  });
90930
90932
  }, Jtt = ({ setOpen: e }) => {
90931
90933
  const { formatMessage: t } = mC(), n = Ktt(), r = () => {
90932
- const i = {};
90933
- n.mutate({
90934
- partnerData: i
90935
- }, {
90936
- onSuccess: (a) => {
90937
- const { next: o } = a;
90938
- window.open(o);
90934
+ n.mutate(void 0, {
90935
+ onSuccess: (i) => {
90936
+ const { next: a } = i;
90937
+ window.open(a);
90939
90938
  },
90940
- onError: (a) => {
90941
- console.error("Failed to start application", a);
90939
+ onError: (i) => {
90940
+ console.error("Failed to start application", i);
90942
90941
  }
90943
90942
  });
90944
90943
  };
@@ -91006,8 +91005,8 @@ const Htt = /* @__PURE__ */ k.forwardRef(Btt), ztt = [
91006
91005
  e && /* @__PURE__ */ Kt.jsx(qde, {})
91007
91006
  ] });
91008
91007
  }, rnt = () => {
91009
- const e = vH(), t = () => console.log("close widget");
91010
- return /* @__PURE__ */ Kt.jsx(Kt.Fragment, { children: !e.isLoading && /* @__PURE__ */ Kt.jsx(nnt, { closeWidget: t }) });
91008
+ const e = vH();
91009
+ return /* @__PURE__ */ Kt.jsx(Kt.Fragment, { children: !e.isLoading && /* @__PURE__ */ Kt.jsx(nnt, {}) });
91011
91010
  }, int = {
91012
91011
  "common.cancel": "Cancel",
91013
91012
  "ctaModal.call": "Get funded",
@@ -91025,37 +91024,38 @@ const Htt = /* @__PURE__ */ k.forwardRef(Btt), ztt = [
91025
91024
  "ctaModal.step3.time": "24 hrs"
91026
91025
  }, ant = new sJ(), ont = {
91027
91026
  en: int
91028
- }, snt = ({ partnerDesignId: e, companyToken: t, isMockedMode: n }) => {
91029
- const r = "en", i = VL(
91027
+ }, snt = ({ partnerDesignId: e, companyToken: t, isMockedMode: n, partnerCallback: r }) => {
91028
+ const i = "en", a = VL(
91030
91029
  {
91031
- locale: r,
91032
- messages: ont[r]
91030
+ locale: i,
91031
+ messages: ont[i]
91033
91032
  },
91034
91033
  D$()
91035
91034
  );
91036
- return /* @__PURE__ */ Kt.jsx(hye, { client: ant, children: /* @__PURE__ */ Kt.jsx(mH.Provider, { value: { companyToken: t, isMockedMode: n }, children: /* @__PURE__ */ Kt.jsx(h2e, { theme: e, intl: i, children: /* @__PURE__ */ Kt.jsx(rnt, {}) }) }) });
91037
- }, OK = /* @__PURE__ */ new Map(), NK = (e, t, n, r) => {
91038
- const i = document.getElementById(e);
91039
- if (!i) {
91035
+ return /* @__PURE__ */ Kt.jsx(hye, { client: ant, children: /* @__PURE__ */ Kt.jsx(mH.Provider, { value: { companyToken: t, isMockedMode: n, partnerCallback: r }, children: /* @__PURE__ */ Kt.jsx(h2e, { theme: e, intl: a, children: /* @__PURE__ */ Kt.jsx(rnt, {}) }) }) });
91036
+ }, OK = /* @__PURE__ */ new Map(), NK = (e, t, n, r, i) => {
91037
+ const a = document.getElementById(e);
91038
+ if (!a) {
91040
91039
  console.warn(`Target element with id "${e}" not found.`);
91041
91040
  return;
91042
91041
  }
91043
- let a = OK.get(i);
91044
- a || (a = lI.createRoot(i), OK.set(i, a)), a.render(
91042
+ let o = OK.get(a);
91043
+ o || (o = lI.createRoot(a), OK.set(a, o)), o.render(
91045
91044
  /* @__PURE__ */ Kt.jsx(
91046
91045
  snt,
91047
91046
  {
91048
91047
  partnerDesignId: t,
91049
- companyToken: n,
91050
- isMockedMode: r
91048
+ companyToken: r,
91049
+ isMockedMode: i,
91050
+ partnerCallback: n
91051
91051
  }
91052
91052
  )
91053
91053
  );
91054
- }, nrt = (e, t, n, r) => {
91054
+ }, nrt = (e, t, n, r, i) => {
91055
91055
  document.readyState === "loading" ? document.addEventListener(
91056
91056
  "DOMContentLoaded",
91057
- () => NK(e, t, n, r)
91058
- ) : NK(e, t, n, r);
91057
+ () => NK(e, t, n, r, i)
91058
+ ) : NK(e, t, n, r, i);
91059
91059
  };
91060
91060
  export {
91061
91061
  nrt as mount
package/index.ts CHANGED
@@ -1,18 +1,20 @@
1
1
  import type { Themes } from '@wayflyer/flyui';
2
+ import { PartnerCallbackType } from '@wf-financing/embedded-types';
2
3
 
3
4
  import { mountToTarget } from './src/main';
4
5
 
5
6
  export const mount = (
6
7
  targetId: string,
7
8
  partnerDesignId: Themes,
9
+ partnerCallback: PartnerCallbackType,
8
10
  companyToken: string,
9
11
  isMockedMode?: boolean,
10
12
  ) => {
11
13
  if (document.readyState === 'loading') {
12
14
  document.addEventListener('DOMContentLoaded', () =>
13
- mountToTarget(targetId, partnerDesignId, companyToken, isMockedMode),
15
+ mountToTarget(targetId, partnerDesignId, partnerCallback, companyToken, isMockedMode),
14
16
  );
15
17
  } else {
16
- mountToTarget(targetId, partnerDesignId, companyToken, isMockedMode);
18
+ mountToTarget(targetId, partnerDesignId, partnerCallback, companyToken, isMockedMode);
17
19
  }
18
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wf-financing/ui",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.es.js",
@@ -23,7 +23,7 @@
23
23
  "react-aria": "^3.41.1",
24
24
  "react-intl": "^6.2.5",
25
25
  "styled-components": "^6.1.19",
26
- "@wf-financing/embedded-types": "^0.1.3"
26
+ "@wf-financing/embedded-types": "^0.1.4"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"
package/src/App.tsx CHANGED
@@ -1,5 +1,6 @@
1
1
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
2
2
  import { FlyUIProvider, Themes } from '@wayflyer/flyui';
3
+ import { PartnerCallbackType } from '@wf-financing/embedded-types';
3
4
  import { createIntl, createIntlCache, IntlShape } from 'react-intl';
4
5
 
5
6
  import { CtaWidget } from './CtaWidget';
@@ -10,6 +11,7 @@ type AppPropsType = {
10
11
  partnerDesignId: Themes;
11
12
  companyToken: string;
12
13
  isMockedMode?: boolean;
14
+ partnerCallback: PartnerCallbackType,
13
15
  };
14
16
 
15
17
  const queryClient = new QueryClient();
@@ -17,7 +19,7 @@ const messages = {
17
19
  en: enMessages,
18
20
  };
19
21
 
20
- export const App = ({ partnerDesignId, companyToken, isMockedMode }: AppPropsType) => {
22
+ export const App = ({ partnerDesignId, companyToken, isMockedMode, partnerCallback }: AppPropsType) => {
21
23
  const locale = 'en';
22
24
 
23
25
  const intl: IntlShape = createIntl(
@@ -30,7 +32,7 @@ export const App = ({ partnerDesignId, companyToken, isMockedMode }: AppPropsTyp
30
32
 
31
33
  return (
32
34
  <QueryClientProvider client={queryClient}>
33
- <PartnerContext.Provider value={{ companyToken, isMockedMode }}>
35
+ <PartnerContext.Provider value={{ companyToken, isMockedMode, partnerCallback }}>
34
36
  <FlyUIProvider theme={partnerDesignId} intl={intl}>
35
37
  <CtaWidget />
36
38
  </FlyUIProvider>
package/src/CtaWidget.tsx CHANGED
@@ -3,12 +3,11 @@ import { useCtaBanner } from './hooks/useCtaBanner';
3
3
 
4
4
  export const CtaWidget = () => {
5
5
  const banner = useCtaBanner();
6
- const handleCloseWidget = () => console.log('close widget');
7
6
 
8
7
  return (
9
8
  <>
10
9
  {!banner.isLoading && (
11
- <CtaBanner closeWidget={handleCloseWidget} />
10
+ <CtaBanner />
12
11
  )}
13
12
  </>
14
13
  );
@@ -1,9 +1,19 @@
1
- import { StartHostedApplicationRequestType } from '@wf-financing/embedded-types';
1
+ import { PartnerCallbackType } from '@wf-financing/embedded-types';
2
2
 
3
3
  import { getHeadlessSdkInstance } from './getHeadlessSdkInstance';
4
4
 
5
- export const startHostedApplication = async (companyToken: string, isMockedMode: boolean, partnerData: StartHostedApplicationRequestType) => {
5
+ export const startHostedApplication = async (
6
+ companyToken: string,
7
+ isMockedMode: boolean,
8
+ partnerCallback: PartnerCallbackType,
9
+ ) => {
10
+ let partnerData = await partnerCallback();
6
11
  const sdk = await getHeadlessSdkInstance(companyToken, isMockedMode);
12
+
13
+ if (!partnerData) {
14
+ partnerData = {};
15
+ }
16
+
7
17
  const nextUrl = await sdk.startHostedApplication(partnerData);
8
18
 
9
19
  return nextUrl;
@@ -13,16 +13,11 @@ export const ModalFooter = ({ setOpen }: ModalFooterType) => {
13
13
  const startHostedAppMutation = useStartHostedApplication();
14
14
 
15
15
  const handleStartApplication = () => {
16
- const partnerData = {};
17
-
18
- startHostedAppMutation.mutate({
19
- partnerData,
20
- }, {
21
- onSuccess: (nextUrl: StartHostedApplicationResponseType) => {
22
- const { next } = nextUrl;
23
-
24
- window.open(next);
25
- },
16
+ startHostedAppMutation.mutate(undefined, {
17
+ onSuccess: (nextUrl: StartHostedApplicationResponseType) => {
18
+ const { next } = nextUrl;
19
+ window.open(next);
20
+ },
26
21
  onError: (error) => {
27
22
  console.error('Failed to start application', error);
28
23
  },
@@ -1,4 +1,4 @@
1
- import { StartHostedApplicationRequestType } from '@wf-financing/embedded-types';
1
+ import { PartnerCallbackType } from '@wf-financing/embedded-types';
2
2
  import { useContext } from "react";
3
3
 
4
4
  import { PartnerContext } from "../utils/partnerContext";
@@ -6,19 +6,16 @@ import { PartnerContext } from "../utils/partnerContext";
6
6
  type PartnerDataType = {
7
7
  companyToken: string;
8
8
  isMockedMode: boolean;
9
+ partnerCallback: PartnerCallbackType;
9
10
  };
10
11
 
11
12
  import { useMutation } from '@tanstack/react-query';
12
13
  import { startHostedApplication } from '../api/startHostedApplication';
13
14
 
14
15
  export const useStartHostedApplication = () => {
15
- const { companyToken, isMockedMode } = useContext(PartnerContext) as PartnerDataType;
16
+ const { companyToken, isMockedMode, partnerCallback } = useContext(PartnerContext) as PartnerDataType;
16
17
 
17
18
  return useMutation({
18
- mutationFn: ({
19
- partnerData,
20
- }: {
21
- partnerData: StartHostedApplicationRequestType;
22
- }) => startHostedApplication(companyToken, isMockedMode, partnerData),
19
+ mutationFn: () => startHostedApplication(companyToken, isMockedMode, partnerCallback),
23
20
  });
24
- }
21
+ };
package/src/main.tsx CHANGED
@@ -1,11 +1,15 @@
1
+ import type { Themes } from '@wayflyer/flyui';
2
+ import { PartnerCallbackType } from '@wf-financing/embedded-types';
1
3
  import ReactDOM from 'react-dom/client';
4
+
2
5
  import { App } from './App';
3
6
 
4
7
  const roots = new Map<HTMLElement, ReactDOM.Root>();
5
8
 
6
9
  export const mountToTarget = (
7
10
  targetId: string,
8
- partnerDesignId: 'wayflyer' | 'defaultTheme' | 'staff' | 'whiteLabel' | 'bigCommerce',
11
+ partnerDesignId: Themes,
12
+ partnerCallback: PartnerCallbackType,
9
13
  companyToken: string,
10
14
  isMockedMode?: boolean,
11
15
  ) => {
@@ -28,6 +32,7 @@ export const mountToTarget = (
28
32
  partnerDesignId={partnerDesignId}
29
33
  companyToken={companyToken}
30
34
  isMockedMode={isMockedMode}
35
+ partnerCallback={partnerCallback}
31
36
  />
32
37
  );
33
38
  };
@@ -1,8 +1,10 @@
1
+ import { PartnerCallbackType } from '@wf-financing/embedded-types';
1
2
  import { createContext } from "react";
2
3
 
3
4
  type PartnerContextType = {
4
5
  companyToken: string;
5
6
  isMockedMode?: boolean;
7
+ partnerCallback: PartnerCallbackType,
6
8
  } | null;
7
9
 
8
10
  export const PartnerContext = createContext<PartnerContextType>(null);
package/tsconfig.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
4
  "rootDir": ".",
5
- "baseUrl": ".",
5
+ "baseUrl": "."
6
6
  },
7
7
  "include": ["**/*.ts", "**.ts", "**/*.tsx", "**.tsx"],
8
8
  "exclude": ["dist", "mocks", "tests", "playground"]