@wf-financing/ui 4.4.0 → 4.5.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/CHANGELOG.md +13 -0
- package/dist/index.es.js +3788 -3805
- package/package.json +2 -2
- package/src/App.tsx +2 -18
- package/src/CtaWidget.snapshot.stories.tsx +276 -0
- package/src/CtaWidget.tsx +26 -39
- package/src/CtaWidgetContainer.tsx +32 -0
- package/src/components/banner/CtaBanner.snapshot.stories.tsx +8 -3
- package/src/components/banner/CtaBanner.tsx +3 -8
- package/src/components/modal/BulletList.tsx +3 -2
- package/src/components/modal/ConsentModal.snapshot.stories.tsx +8 -8
- package/src/components/modal/ConsentModal.tsx +21 -28
- package/src/components/modal/ModalHeader.tsx +1 -1
- package/src/hooks/useNotificationOnRender.ts +5 -5
- package/src/utils/{buildBannerConfig.ts → buildBannerProps.ts} +4 -4
- package/src/utils/buildCtaUiProps.ts +81 -0
- package/src/utils/index.ts +2 -2
- package/src/components/modal/ConsentModalContent.tsx +0 -36
- package/src/locales/en.json +0 -17
- package/src/utils/getBannerConfig.ts +0 -44
|
@@ -2,23 +2,23 @@ import { CtaResponseType, CtaStateType } from '@wf-financing/embedded-types';
|
|
|
2
2
|
|
|
3
3
|
import { useEventContext } from './useEventContext';
|
|
4
4
|
import { usePartnerContext } from './usePartnerContext';
|
|
5
|
-
import { type
|
|
5
|
+
import { type BannerProps } from '../utils';
|
|
6
6
|
|
|
7
7
|
export const useNotificationOnRender = () => {
|
|
8
8
|
const { logEvent } = useEventContext();
|
|
9
9
|
const { mountToTargetTimestamp } = usePartnerContext();
|
|
10
10
|
|
|
11
|
-
return (cta: CtaResponseType,
|
|
12
|
-
if (!cta || !
|
|
11
|
+
return (cta: CtaResponseType, bannerProps: BannerProps) => {
|
|
12
|
+
if (!cta || !bannerProps) return;
|
|
13
13
|
|
|
14
14
|
const bannerRenderingLatency = Date.now() - mountToTargetTimestamp;
|
|
15
15
|
|
|
16
16
|
const { state, data } = cta;
|
|
17
17
|
const attrs: Record<string, string | number> = {
|
|
18
18
|
cta_state: state,
|
|
19
|
-
banner_copy_version:
|
|
19
|
+
banner_copy_version: bannerProps.version,
|
|
20
20
|
banner_rendering_latency: bannerRenderingLatency,
|
|
21
|
-
copy_type:
|
|
21
|
+
copy_type: bannerProps.type,
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
if (state === CtaStateType.CONTINUE_APPLICATION) {
|
|
@@ -8,17 +8,17 @@ type CopySection = {
|
|
|
8
8
|
type: string;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export type
|
|
11
|
+
export type BannerProps = CopySection & {
|
|
12
12
|
buttonAction: () => void;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
type
|
|
15
|
+
type BuildBannerProps = (
|
|
16
16
|
copySection: CopySection,
|
|
17
17
|
buttonAction: () => void,
|
|
18
18
|
offer?: { currency: string; amount: number },
|
|
19
|
-
) =>
|
|
19
|
+
) => BannerProps;
|
|
20
20
|
|
|
21
|
-
export const
|
|
21
|
+
export const buildBannerProps: BuildBannerProps = (copySection, buttonAction, offer) => ({
|
|
22
22
|
mainText: offer
|
|
23
23
|
? replacePlaceholdersForMainText(offer.currency, offer.amount, copySection.mainText)
|
|
24
24
|
: copySection.mainText,
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Copy, ConsentModal, PartnerTemplate } from '@wf-financing/ui-assets';
|
|
2
|
+
import { CtaStateType, ApplicationRequiredActions, CtaResponseType } from '@wf-financing/embedded-types';
|
|
3
|
+
|
|
4
|
+
import { buildBannerProps, type BannerProps } from './buildBannerProps.ts';
|
|
5
|
+
|
|
6
|
+
export type ConsentModalProps = ConsentModal & {
|
|
7
|
+
onModalStateChange: () => void;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type CtaUiProps = {
|
|
11
|
+
bannerProps: BannerProps;
|
|
12
|
+
consentModalProps?: ConsentModalProps;
|
|
13
|
+
partnerTemplateProps?: PartnerTemplate;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type BuildCtaUiProps = (
|
|
17
|
+
cta: Exclude<CtaResponseType, null>,
|
|
18
|
+
copy: Copy,
|
|
19
|
+
onModalStateChange: () => void,
|
|
20
|
+
onContinueApplication: () => void,
|
|
21
|
+
) => CtaUiProps;
|
|
22
|
+
|
|
23
|
+
export const buildCtaUiProps: BuildCtaUiProps = (cta, copy, onModalStateChange, onContinueApplication) => {
|
|
24
|
+
const { state, data } = cta;
|
|
25
|
+
const {
|
|
26
|
+
genericOffer,
|
|
27
|
+
indicativeOffer,
|
|
28
|
+
completeApplication,
|
|
29
|
+
selectOffer,
|
|
30
|
+
completeKyc,
|
|
31
|
+
signContract,
|
|
32
|
+
provideAdditionalInfo,
|
|
33
|
+
consentModal,
|
|
34
|
+
partnerTemplate,
|
|
35
|
+
} = copy;
|
|
36
|
+
|
|
37
|
+
const continueApplicationMap: Record<ApplicationRequiredActions, () => ReturnType<BuildCtaUiProps>> = {
|
|
38
|
+
[ApplicationRequiredActions.COMPLETE_APPLICATION]: () => ({
|
|
39
|
+
bannerProps: buildBannerProps(completeApplication, onContinueApplication),
|
|
40
|
+
}),
|
|
41
|
+
|
|
42
|
+
[ApplicationRequiredActions.SELECT_OFFER]: () => {
|
|
43
|
+
const offer = 'offer' in data ? data.offer : undefined;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
bannerProps: buildBannerProps(selectOffer, onContinueApplication, offer),
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
[ApplicationRequiredActions.COMPLETE_KYC]: () => ({
|
|
51
|
+
bannerProps: buildBannerProps(completeKyc, onContinueApplication),
|
|
52
|
+
}),
|
|
53
|
+
|
|
54
|
+
[ApplicationRequiredActions.SIGN_CONTRACT]: () => ({
|
|
55
|
+
bannerProps: buildBannerProps(signContract, onContinueApplication),
|
|
56
|
+
}),
|
|
57
|
+
|
|
58
|
+
[ApplicationRequiredActions.PROVIDE_ADDITIONAL_INFO]: () => ({
|
|
59
|
+
bannerProps: buildBannerProps(provideAdditionalInfo, onContinueApplication),
|
|
60
|
+
}),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
switch (state) {
|
|
64
|
+
case CtaStateType.GENERIC_OFFER:
|
|
65
|
+
return {
|
|
66
|
+
bannerProps: buildBannerProps(genericOffer, onModalStateChange),
|
|
67
|
+
consentModalProps: { ...consentModal, onModalStateChange },
|
|
68
|
+
partnerTemplateProps: partnerTemplate,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
case CtaStateType.INDICATIVE_OFFER:
|
|
72
|
+
return {
|
|
73
|
+
bannerProps: buildBannerProps(indicativeOffer, onModalStateChange, data.offer),
|
|
74
|
+
consentModalProps: { ...consentModal, onModalStateChange },
|
|
75
|
+
partnerTemplateProps: partnerTemplate,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
case CtaStateType.CONTINUE_APPLICATION:
|
|
79
|
+
return continueApplicationMap[data.config.required_action]?.();
|
|
80
|
+
}
|
|
81
|
+
};
|
package/src/utils/index.ts
CHANGED
|
@@ -7,6 +7,6 @@ export { PartnerContext, type PartnerContextType } from './partnerContext';
|
|
|
7
7
|
export { replacePlaceholdersForMainText } from './replacePlaceholdersForMainText.ts';
|
|
8
8
|
export { getModalItems } from './getModalItems';
|
|
9
9
|
export { injectUrlInTemplate } from './injectUrlInTemplate';
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
10
|
+
export { buildBannerProps, type BannerProps } from './buildBannerProps.ts';
|
|
11
|
+
export { buildCtaUiProps, type CtaUiProps, type ConsentModalProps } from './buildCtaUiProps.ts';
|
|
12
12
|
export { EventContext, type EventContextValue, type EventAttributes } from './eventContext';
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
|
|
3
|
-
import { ModalFooter } from './ModalFooter.tsx';
|
|
4
|
-
import { ModalHeader } from './ModalHeader.tsx';
|
|
5
|
-
import { BulletList } from './BulletList';
|
|
6
|
-
import { Modal } from './Modal.tsx';
|
|
7
|
-
|
|
8
|
-
type ConsentModalContentProps = {
|
|
9
|
-
logoUrl: string;
|
|
10
|
-
partnerLogoUrl?: string;
|
|
11
|
-
title: string;
|
|
12
|
-
bulletPoints: string[];
|
|
13
|
-
button: string;
|
|
14
|
-
termsAndConditions: string;
|
|
15
|
-
setIsModalOpen: Dispatch<SetStateAction<boolean>>;
|
|
16
|
-
isModalOpen: boolean;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const ConsentModalContent = ({
|
|
20
|
-
title,
|
|
21
|
-
bulletPoints,
|
|
22
|
-
termsAndConditions,
|
|
23
|
-
button,
|
|
24
|
-
logoUrl,
|
|
25
|
-
partnerLogoUrl,
|
|
26
|
-
setIsModalOpen,
|
|
27
|
-
isModalOpen,
|
|
28
|
-
}: ConsentModalContentProps) => {
|
|
29
|
-
return (
|
|
30
|
-
<Modal isModalOpen={isModalOpen} setIsModalOpen={setIsModalOpen}>
|
|
31
|
-
<ModalHeader title={title} logoUrl={logoUrl} partnerLogoUrl={partnerLogoUrl} />
|
|
32
|
-
<BulletList bulletPoints={bulletPoints} />
|
|
33
|
-
<ModalFooter setIsModalOpen={setIsModalOpen} button={button} termsAndConditions={termsAndConditions} />
|
|
34
|
-
</Modal>
|
|
35
|
-
);
|
|
36
|
-
};
|
package/src/locales/en.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"common.cancel": "Cancel",
|
|
3
|
-
"common.dismiss": "Dismiss",
|
|
4
|
-
"ctaModal.call": "Get funded",
|
|
5
|
-
"ctaModal.title": "Fuel your growth with capital from Wayflyer",
|
|
6
|
-
"ctaModal.action": "Continue to Wayflyer",
|
|
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
|
-
"ctaModal.consent.privacy_policy": "Privacy Policy.",
|
|
9
|
-
"ctaModal.step1.title": "Built for businesses like yours",
|
|
10
|
-
"ctaModal.step1.subtitle": "$5B deployed to 5,000+ companies",
|
|
11
|
-
"ctaModal.step1.time": "2 mins",
|
|
12
|
-
"ctaModal.step2.title": "Your growth, your way",
|
|
13
|
-
"ctaModal.step2.subtitle": "Flexible terms that fit your business",
|
|
14
|
-
"ctaModal.step2.time": "10 mins",
|
|
15
|
-
"ctaModal.step3.title": "Quick to get started",
|
|
16
|
-
"ctaModal.step3.subtitle": "Apply in minutes and get capital in hours"
|
|
17
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { Copy } from '@wf-financing/ui-assets';
|
|
2
|
-
import { CtaStateType, ApplicationRequiredActions, CtaResponseType } from '@wf-financing/embedded-types';
|
|
3
|
-
|
|
4
|
-
import { buildBannerConfig, type BannerConfig } from './buildBannerConfig.ts';
|
|
5
|
-
|
|
6
|
-
type GetBannerConfig = (
|
|
7
|
-
cta: Exclude<CtaResponseType, null>,
|
|
8
|
-
copy: Copy,
|
|
9
|
-
handleIsModalOpen: () => void,
|
|
10
|
-
handleContinueHostedApplication: () => void,
|
|
11
|
-
) => BannerConfig;
|
|
12
|
-
|
|
13
|
-
export const getBannerConfig: GetBannerConfig = (cta, copy, handleIsModalOpen, handleContinueHostedApplication) => {
|
|
14
|
-
const { state, data } = cta;
|
|
15
|
-
const {
|
|
16
|
-
genericOffer,
|
|
17
|
-
indicativeOffer,
|
|
18
|
-
completeApplication,
|
|
19
|
-
selectOffer,
|
|
20
|
-
completeKyc,
|
|
21
|
-
signContract,
|
|
22
|
-
provideAdditionalInfo,
|
|
23
|
-
} = copy;
|
|
24
|
-
|
|
25
|
-
switch (state) {
|
|
26
|
-
case CtaStateType.GENERIC_OFFER:
|
|
27
|
-
return buildBannerConfig(genericOffer, handleIsModalOpen);
|
|
28
|
-
case CtaStateType.INDICATIVE_OFFER:
|
|
29
|
-
return buildBannerConfig(indicativeOffer, handleIsModalOpen, data.offer);
|
|
30
|
-
case CtaStateType.CONTINUE_APPLICATION:
|
|
31
|
-
switch (cta.data.config.required_action) {
|
|
32
|
-
case ApplicationRequiredActions.COMPLETE_APPLICATION:
|
|
33
|
-
return buildBannerConfig(completeApplication, handleContinueHostedApplication);
|
|
34
|
-
case ApplicationRequiredActions.SELECT_OFFER:
|
|
35
|
-
return buildBannerConfig(selectOffer, handleContinueHostedApplication, data.offer);
|
|
36
|
-
case ApplicationRequiredActions.COMPLETE_KYC:
|
|
37
|
-
return buildBannerConfig(completeKyc, handleContinueHostedApplication);
|
|
38
|
-
case ApplicationRequiredActions.SIGN_CONTRACT:
|
|
39
|
-
return buildBannerConfig(signContract, handleContinueHostedApplication);
|
|
40
|
-
case ApplicationRequiredActions.PROVIDE_ADDITIONAL_INFO:
|
|
41
|
-
return buildBannerConfig(provideAdditionalInfo, handleContinueHostedApplication);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|