@wf-financing/ui 3.8.1 → 3.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wf-financing/ui",
3
- "version": "3.8.1",
3
+ "version": "3.9.1",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.es.js",
package/src/CtaWidget.tsx CHANGED
@@ -1,14 +1,14 @@
1
1
  import { AnimatePresence } from 'framer-motion';
2
-
3
2
  import { useState } from 'react';
3
+
4
4
  import { AnimationWrapper } from './components/banner/AnimationWrapper';
5
5
  import { CtaBanner } from './components/banner/CtaBanner';
6
6
  import { useCtaBanner, usePartnerContext } from './hooks';
7
7
 
8
8
  export const CtaWidget = () => {
9
- const { isLoading, data, isSuccess } = useCtaBanner();
10
- const [skipAnimation] = useState(() => isSuccess);
11
- const { onWidgetClose, isWidgetDismissed } = usePartnerContext();
9
+ const { isLoading, data } = useCtaBanner();
10
+ const { onWidgetClose, isWidgetDismissed, options } = usePartnerContext();
11
+ const [skipAnimation] = useState(() => !!options?.skipAnimations);
12
12
 
13
13
  const showBanner = !isLoading && data && !isWidgetDismissed;
14
14
 
@@ -8,7 +8,7 @@ import {
8
8
  } from '@wf-financing/embedded-types';
9
9
  import { useState } from 'react';
10
10
 
11
- import { useCtaBanner, useContinueHostedApplication, useInvalidateCta } from '../../hooks';
11
+ import { useCtaBanner, useContinueHostedApplication } from '../../hooks';
12
12
  import { ConsentModal } from '../modal/ConsentModal';
13
13
 
14
14
  type CtaResponseType = CtaGenericOfferType | CtaIndicativeOfferType | CtaContinueFundingType;
@@ -18,7 +18,6 @@ export const ProceedFundingButton = ({ isOnDarkTheme }: { isOnDarkTheme: boolean
18
18
  const sdkResponse = useCtaBanner();
19
19
  const sdk = sdkResponse.data as CtaResponseType;
20
20
  const { mutate, isPending: isLoading } = useContinueHostedApplication();
21
- const invalidateCta = useInvalidateCta();
22
21
 
23
22
  if (!sdk) return null;
24
23
 
@@ -34,7 +33,6 @@ export const ProceedFundingButton = ({ isOnDarkTheme }: { isOnDarkTheme: boolean
34
33
  onSuccess: (nextUrl: ContinueHostedApplicationResponseType) => {
35
34
  const { next } = nextUrl;
36
35
  window.open(next);
37
- invalidateCta();
38
36
  },
39
37
  onError: (error) => {
40
38
  console.error('Failed to continue application', error);
@@ -3,7 +3,7 @@ import { IconArrowOnSquareUpRight16Line } from '@wayflyer/flyui-icons/16/line';
3
3
  import { StartHostedApplicationResponseType } from '@wf-financing/embedded-types';
4
4
  import { FormattedMessage } from 'react-intl';
5
5
 
6
- import { useDetectSmallScreen, useStartHostedApplication, useInvalidateCta } from '../../hooks';
6
+ import { useDetectSmallScreen, useStartHostedApplication } from '../../hooks';
7
7
 
8
8
  type ModalFooterType = {
9
9
  setOpen: (isOpen: boolean) => void;
@@ -13,7 +13,6 @@ export const ModalFooter = ({ setOpen }: ModalFooterType) => {
13
13
  const { isMobile } = useDetectDeviceSize();
14
14
  const { mutate, isPending: isLoading } = useStartHostedApplication();
15
15
  const isSmallScreen = useDetectSmallScreen();
16
- const invalidateCta = useInvalidateCta();
17
16
 
18
17
  const handleStartApplication = () => {
19
18
  mutate(undefined, {
@@ -21,7 +20,6 @@ export const ModalFooter = ({ setOpen }: ModalFooterType) => {
21
20
  const { next } = nextUrl;
22
21
  setOpen(false);
23
22
  window.open(next);
24
- invalidateCta();
25
23
  },
26
24
  onError: (error) => {
27
25
  console.error('Failed to start application', error);
@@ -6,4 +6,3 @@ export { useContinueHostedApplication } from './useContinueHostedApplication';
6
6
  export { useDismissCta } from './useDismissCta';
7
7
  export { useRemoveInerted } from './useRemoveInerted';
8
8
  export { usePreloadImage } from './usePreloadImage';
9
- export { useInvalidateCta } from './useInvalidateCta';
@@ -9,9 +9,8 @@ export const useCtaBanner = () => {
9
9
  return useQuery({
10
10
  queryKey: ['cta', companyToken],
11
11
  queryFn: () => fetchCtaBanner(companyToken, options),
12
- staleTime: Infinity,
13
- refetchOnWindowFocus: false,
14
- placeholderData: keepPreviousData,
15
12
  enabled: !!companyToken,
13
+ placeholderData: keepPreviousData,
14
+ refetchOnMount: false,
16
15
  });
17
16
  };
@@ -2,16 +2,13 @@ import { useMutation } from '@tanstack/react-query';
2
2
 
3
3
  import { dismissCta } from '../api';
4
4
  import { usePartnerContext } from './usePartnerContext';
5
- import { useInvalidateCta } from './useInvalidateCta';
6
5
 
7
6
  export const useDismissCta = () => {
8
7
  const { companyToken, options } = usePartnerContext();
9
- const invalidateCta = useInvalidateCta();
10
8
 
11
9
  return useMutation({
12
10
  mutationFn: async () => {
13
11
  await dismissCta(companyToken, options);
14
- await invalidateCta();
15
12
  },
16
13
  });
17
14
  };
package/src/main.tsx CHANGED
@@ -7,6 +7,9 @@ import { App } from './App';
7
7
  import { PartnerTheme } from './config';
8
8
  import { applyFont, createRoots } from './utils';
9
9
 
10
+ let root: ReactDOM.Root | undefined;
11
+ let savedTargetId: string | undefined;
12
+
10
13
  export const mountToTarget = async (
11
14
  targetId: string,
12
15
  partnerTheme: PartnerTheme,
@@ -14,8 +17,14 @@ export const mountToTarget = async (
14
17
  companyToken: string,
15
18
  options?: SdkOptionsType,
16
19
  ): Promise<void> => {
17
- const hostEl = document.getElementById(targetId);
18
- if (!hostEl) throw new Error(`Target element with id "${targetId}" not found.`);
20
+ const isNewTargetId = targetId !== savedTargetId;
21
+
22
+ if (isNewTargetId) {
23
+ savedTargetId = targetId;
24
+ }
25
+
26
+ const hostEl = document.getElementById(savedTargetId as string);
27
+ if (!hostEl) throw new Error(`Target element with id "${savedTargetId}" not found.`);
19
28
 
20
29
  const shadow = hostEl.shadowRoot ?? hostEl.attachShadow({ mode: 'open' });
21
30
 
@@ -26,11 +35,15 @@ export const mountToTarget = async (
26
35
  }
27
36
 
28
37
  const { styledComponentsStyleRoot, portalRoot, bannerRoot } = createRoots(shadow);
29
- const root = ReactDOM.createRoot(bannerRoot);
38
+
39
+ if (isNewTargetId || !root) {
40
+ root = ReactDOM.createRoot(bannerRoot);
41
+ }
30
42
 
31
43
  const handleCloseWidget = () => {
32
44
  if (!root) throw new Error('Root is not found');
33
45
  root.unmount();
46
+ root = undefined;
34
47
  };
35
48
 
36
49
  MotionGlobalConfig.skipAnimations = options?.skipAnimations;
@@ -1,13 +0,0 @@
1
- import { useQueryClient } from '@tanstack/react-query';
2
-
3
- import { usePartnerContext } from './usePartnerContext';
4
-
5
- export const useInvalidateCta = () => {
6
- const queryClient = useQueryClient();
7
- const { companyToken } = usePartnerContext();
8
-
9
- return () =>
10
- queryClient.invalidateQueries({
11
- queryKey: ['cta', companyToken],
12
- });
13
- };