@wf-financing/ui 3.3.0 → 3.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wf-financing/ui",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.es.js",
@@ -46,6 +46,7 @@
46
46
  "dev": "vite",
47
47
  "build": "vite build",
48
48
  "preview": "vite preview",
49
+ "analyze": "vite build --mode analyze-html && npx http-server dist/bundle-stats -p 8083",
49
50
  "publish-sdk-cta-ui": "pnpm clean && pnpm build && pnpm publish --access public --no-git-checks",
50
51
  "test": "vitest",
51
52
  "test:coverage": "vitest --coverage"
package/sdk/index.ts CHANGED
@@ -8,8 +8,8 @@ export class WayflyerUiSdk {
8
8
  private readonly partnerTheme: PartnerTheme;
9
9
 
10
10
  constructor(
11
- private readonly companyToken: string,
12
- private readonly options?: SdkOptionsType,
11
+ readonly companyToken: string,
12
+ readonly options?: SdkOptionsType,
13
13
  ) {
14
14
  const partnerId = getPartnerIdFromToken(companyToken);
15
15
  this.partnerTheme = getPartnerThemeById(partnerId);
@@ -17,7 +17,7 @@ export const ProceedFundingButton = ({ isOnDarkTheme }: { isOnDarkTheme: boolean
17
17
  const [isModalOpen, setIsModalOpen] = useState(false);
18
18
  const sdkResponse = useCtaBanner();
19
19
  const sdk = sdkResponse.data as CtaResponseType;
20
- const continueHostedApplicationMutation = useContinueHostedApplication();
20
+ const { mutate, isPending: isLoading } = useContinueHostedApplication();
21
21
  const invalidateCta = useInvalidateCta();
22
22
 
23
23
  if (!sdk) return null;
@@ -30,7 +30,7 @@ export const ProceedFundingButton = ({ isOnDarkTheme }: { isOnDarkTheme: boolean
30
30
  const handleContinueHostedApplication = () => {
31
31
  switch (state) {
32
32
  case CtaStateType.CONTINUE_APPLICATION:
33
- continueHostedApplicationMutation.mutate(undefined, {
33
+ mutate(undefined, {
34
34
  onSuccess: (nextUrl: ContinueHostedApplicationResponseType) => {
35
35
  const { next } = nextUrl;
36
36
  window.open(next);
@@ -49,7 +49,12 @@ export const ProceedFundingButton = ({ isOnDarkTheme }: { isOnDarkTheme: boolean
49
49
 
50
50
  return (
51
51
  <>
52
- <Button variant={isOnDarkTheme ? 'PrimaryOnDark' : 'Primary'} fullWidth onClick={handleContinueHostedApplication}>
52
+ <Button
53
+ variant={isOnDarkTheme ? 'PrimaryOnDark' : 'Primary'}
54
+ fullWidth
55
+ onClick={handleContinueHostedApplication}
56
+ loading={isLoading}
57
+ >
53
58
  {config?.button_label}
54
59
  </Button>
55
60
  <ConsentModal isModalOpen={isModalOpen} setIsModalOpen={setIsModalOpen} />
@@ -11,12 +11,12 @@ type ModalFooterType = {
11
11
 
12
12
  export const ModalFooter = ({ setOpen }: ModalFooterType) => {
13
13
  const { isMobile } = useDetectDeviceSize();
14
- const startHostedAppMutation = useStartHostedApplication();
14
+ const { mutate, isPending: isLoading } = useStartHostedApplication();
15
15
  const isSmallScreen = useDetectSmallScreen();
16
16
  const invalidateCta = useInvalidateCta();
17
17
 
18
18
  const handleStartApplication = () => {
19
- startHostedAppMutation.mutate(undefined, {
19
+ mutate(undefined, {
20
20
  onSuccess: (nextUrl: StartHostedApplicationResponseType) => {
21
21
  const { next } = nextUrl;
22
22
  setOpen(false);
@@ -36,9 +36,9 @@ export const ModalFooter = ({ setOpen }: ModalFooterType) => {
36
36
  return (
37
37
  <Flex direction="column" gap="3">
38
38
  <Flex gap="2" direction={isSmallScreen || isMobile ? 'column' : 'row'}>
39
- <Button fullWidth onClick={handleStartApplication} variant="Primary" external>
39
+ <Button fullWidth onClick={handleStartApplication} loading={isLoading} variant="Primary" external>
40
40
  <FormattedMessage id="ctaModal.action" />
41
- <IconArrowOnSquareUpRight16Line />
41
+ {!isLoading && <IconArrowOnSquareUpRight16Line />}
42
42
  </Button>
43
43
  <Button fullWidth variant="Secondary" onClick={() => setOpen(false)}>
44
44
  <FormattedMessage id="common.cancel" />
@@ -1,15 +1,17 @@
1
1
  import { Themes } from '@wayflyer/flyui';
2
2
 
3
3
  export type PartnerTheme = Exclude<Themes, 'staff'>;
4
- export type PartnerId = (typeof WHITELISTED_PARTNER_IDS)[PartnerTheme];
4
+ export type PartnerId = keyof typeof WHITELISTED_PARTNER_IDS;
5
5
 
6
6
  /**
7
7
  * List of partner IDs that are allowed to use custom CTA themes
8
8
  * when embedded into their platform.
9
9
  */
10
10
  export const WHITELISTED_PARTNER_IDS = {
11
- whiteLabel: '2416e2af-c9f7-40ac-a2f0-f37dcfe59674',
12
- wayflyer: '1f309265-5324-4f8b-88d7-9b0d5c77a27c',
13
- athena: '970df87a-e7d5-4942-9450-a77cf771dca3',
11
+ '2416e2af-c9f7-40ac-a2f0-f37dcfe59674': 'whiteLabel',
12
+ '1f309265-5324-4f8b-88d7-9b0d5c77a27c': 'wayflyer',
13
+ '970df87a-e7d5-4942-9450-a77cf771dca3': 'athena',
14
+ '01756129-a8a8-4314-8813-97057195dcfa': 'athena',
15
+
14
16
  defaultTheme: 'defaultTheme',
15
- } as const satisfies Record<PartnerTheme, string>;
17
+ } as const satisfies Record<string, PartnerTheme>;
@@ -1,9 +1,5 @@
1
1
  import { PartnerId, PartnerTheme, WHITELISTED_PARTNER_IDS } from '../config';
2
2
 
3
- const PARTNER_BY_VALUE: Record<PartnerId, PartnerTheme> = Object.fromEntries(
4
- Object.entries(WHITELISTED_PARTNER_IDS).map(([k, v]) => [v, k]),
5
- ) as Record<PartnerId, PartnerTheme>;
6
-
7
3
  export const getPartnerThemeById = (value: PartnerId): PartnerTheme => {
8
- return PARTNER_BY_VALUE[value] || 'whiteLabel';
4
+ return WHITELISTED_PARTNER_IDS[value] || 'whiteLabel';
9
5
  };
@@ -0,0 +1,44 @@
1
+ import react from '@vitejs/plugin-react';
2
+ import path from 'path';
3
+ import { defineConfig, type ConfigEnv, type UserConfig, type PluginOption } from 'vite';
4
+ import { visualizer } from 'rollup-plugin-visualizer';
5
+ import inject from '@rollup/plugin-inject';
6
+
7
+ const visualizerOptions = {
8
+ 'analyze-html': { emitFile: true, filename: `bundle-stats/index.html`, gzipSize: true },
9
+ 'analyze-json': { emitFile: true, filename: `bundle-stats/stats.json`, template: 'raw-data', gzipSize: true },
10
+ };
11
+
12
+ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
13
+ return {
14
+ plugins: [react(), ...(mode?.includes('analyze') ? [visualizer(visualizerOptions[mode])] : [])] as PluginOption[],
15
+ optimizeDeps: {
16
+ exclude: ['@wayflyer/*'],
17
+ },
18
+ define: {
19
+ 'process.env': {},
20
+ 'process.env.NODE_ENV': JSON.stringify(mode),
21
+ },
22
+ server: {
23
+ host: true,
24
+ port: 5176,
25
+ strictPort: true,
26
+ },
27
+ build: {
28
+ lib: {
29
+ entry: path.resolve(__dirname, 'index.ts'),
30
+ name: 'sdkCtaUiComponents',
31
+ fileName: (format) => `index.${format}.js`,
32
+ formats: ['es'],
33
+ },
34
+ rollupOptions: {
35
+ external: [],
36
+ plugins: [
37
+ inject({
38
+ process: 'process',
39
+ }),
40
+ ],
41
+ },
42
+ },
43
+ };
44
+ });
package/vite.config.ts DELETED
@@ -1,37 +0,0 @@
1
- /// <reference types="vitest/config" />
2
- import react from '@vitejs/plugin-react';
3
- import path from 'path';
4
- import { defineConfig } from 'vite';
5
- import inject from '@rollup/plugin-inject';
6
-
7
- export default defineConfig(({ mode }) => ({
8
- plugins: [react()],
9
- optimizeDeps: {
10
- exclude: ['@wayflyer/*'],
11
- },
12
- define: {
13
- 'process.env': {},
14
- 'process.env.NODE_ENV': JSON.stringify(mode),
15
- },
16
- server: {
17
- host: true,
18
- port: 5176,
19
- strictPort: true,
20
- },
21
- build: {
22
- lib: {
23
- entry: path.resolve(__dirname, 'index.ts'),
24
- name: 'sdkCtaUiComponents',
25
- fileName: (format) => `index.${format}.js`,
26
- formats: ['es'],
27
- },
28
- rollupOptions: {
29
- external: [],
30
- plugins: [
31
- inject({
32
- process: 'process',
33
- }),
34
- ],
35
- },
36
- },
37
- }));