@opexa/portal-components 0.0.495 → 0.0.497

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.
@@ -4,4 +4,4 @@ export interface KYCSumsubProps extends KYCReminderProps {
4
4
  provider: 'sumsub';
5
5
  logo: ImageProps['src'];
6
6
  }
7
- export declare function KYCSumsub(props: KYCSumsubProps): Promise<import("react/jsx-runtime").JSX.Element>;
7
+ export declare function KYCSumsub(props: KYCSumsubProps): import("react/jsx-runtime").JSX.Element;
@@ -1,24 +1,28 @@
1
+ 'use client';
1
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
3
  import Sumsub from '@sumsub/websdk-react';
3
4
  import { isObject } from 'lodash-es';
4
- import { useEffect, useState } from 'react';
5
+ import { useEffect, useRef, useState } from 'react';
5
6
  import { useShallow } from 'zustand/shallow';
6
7
  import { useGenerateSumsubVerificationTokenMutation } from '../../client/hooks/useGenerateSumsubVerificationTokenMutation.js';
7
8
  import { useGlobalStore } from '../../client/hooks/useGlobalStore.js';
8
9
  import { useSessionQuery } from '../../client/hooks/useSessionQuery.js';
9
- import { Spinner02Icon } from '../../icons/Spinner02Icon.js';
10
10
  import { Dialog } from '../../ui/Dialog/index.js';
11
11
  import { Portal } from '../../ui/Portal/index.js';
12
12
  import { getQueryClient } from '../../utils/getQueryClient.js';
13
13
  import { getAccountQueryKey, getMemberVerificationQueryKey, getProfileCompletionQueryKey, } from '../../utils/queryKeys.js';
14
14
  import { KYCReminder } from './KYCReminder.js';
15
- export async function KYCSumsub(props) {
15
+ export function KYCSumsub(props) {
16
16
  const [open, setOpen] = useGlobalStore(useShallow((ctx) => [ctx.kyc.open, ctx.kyc.setOpen]));
17
+ const dummyRef = useRef(null);
17
18
  const { data: session } = useSessionQuery();
18
- const { mutate, mutateAsync, reset, isPending, isIdle } = useGenerateSumsubVerificationTokenMutation();
19
+ const { mutate, mutateAsync, reset, isIdle } = useGenerateSumsubVerificationTokenMutation();
19
20
  const [token, setToken] = useState('');
20
21
  useEffect(() => {
21
- if (open === true && isIdle && !token) {
22
+ if (session?.status === 'authenticated' &&
23
+ open === true &&
24
+ isIdle &&
25
+ !token) {
22
26
  mutate(undefined, {
23
27
  onSuccess(token) {
24
28
  setToken(token);
@@ -31,124 +35,121 @@ export async function KYCSumsub(props) {
31
35
  token,
32
36
  isIdle,
33
37
  mutate,
38
+ session?.status,
34
39
  ]);
35
40
  return (_jsxs(_Fragment, { children: [_jsx(Dialog.Root, { open: open && session?.status === 'authenticated', onOpenChange: (details) => {
36
41
  setOpen(details.open);
37
- }, lazyMount: true, unmountOnExit: true, closeOnEscape: false, closeOnInteractOutside: false, onExitComplete: () => {
42
+ }, lazyMount: true, unmountOnExit: true, closeOnEscape: false, initialFocusEl: () => dummyRef.current, closeOnInteractOutside: false, restoreFocus: false, onExitComplete: () => {
38
43
  reset();
39
44
  setToken('');
40
- }, children: _jsxs(Portal, { children: [_jsx(Dialog.Backdrop, {}), _jsx(Dialog.Positioner, { className: "flex items-center justify-center lg:block", children: _jsx(Dialog.Content, { autoFocus: false, className: "mx-auto flex h-full w-[calc(100%-2rem)] flex-col items-center justify-center overflow-y-auto rounded-md bg-transparent p-0 lg:mt-3 lg:block lg:h-auto lg:w-[600px]", children: isPending ? (_jsx("div", { className: "w-full rounded-md bg-[#20252c] px-4 py-12", children: _jsx(Spinner02Icon, { className: "mx-auto size-8" }) })) : (_jsx("div", { className: "max-h-[calc(96dvh-2rem)] w-full overflow-y-auto lg:h-auto lg:max-h-[unset]", children: _jsx(Sumsub, { accessToken: token, expirationHandler: async () => {
41
- const token = await mutateAsync();
42
- return token;
43
- }, config: {
44
- lang: 'en',
45
- theme: 'dark',
46
- }, options: {
47
- debug: process.env.NODE_ENV === 'development',
48
- addViewportTag: false,
49
- adaptIframeHeight: true,
50
- enableScrollIntoView: true,
51
- }, onMessage: (type, payload) => {
52
- /*
53
-
54
- ------------------------
55
- REJECTED
56
- ------------------------
57
-
58
- {
59
- "type": "idCheck.onApplicantStatusChanged",
60
- "payload": {
61
- "reviewId": "toJnn",
62
- "attemptId": "ooaKO",
63
- "attemptCnt": 1,
64
- "elapsedSincePendingMs": 1072,
65
- "elapsedSinceQueuedMs": 1072,
66
- "reprocessing": true,
67
- "levelName": "id-and-liveness",
68
- "levelAutoCheckMode": null,
69
- "createDate": "2025-07-18 02:08:16+0000",
70
- "reviewDate": "2025-07-18 02:08:17+0000",
71
- "reviewResult": {
72
- "moderationComment": "We couldn’t verify your...",
73
- "reviewAnswer": "RED",
74
- "reviewRejectType": "FINAL"
75
- },
76
- "reviewStatus": "completed",
77
- "priority": 0
45
+ }, children: _jsxs(Portal, { children: [_jsx(Dialog.Backdrop, {}), _jsx(Dialog.Positioner, { className: "flex items-center justify-center lg:block", children: _jsxs(Dialog.Content, { className: "mx-auto flex h-full w-[calc(100%-2rem)] flex-col items-center justify-center overflow-y-auto rounded-md bg-transparent p-0 lg:mt-3 lg:block lg:h-auto lg:w-[600px]", children: [_jsx("div", { ref: dummyRef, tabIndex: -1 }), token && (_jsx("div", { className: "max-h-[calc(96dvh-2rem)] w-full overflow-y-auto lg:h-auto lg:max-h-[unset]", children: _jsx(Sumsub, { accessToken: token, expirationHandler: async () => {
46
+ const token = await mutateAsync();
47
+ return token;
48
+ }, config: {
49
+ lang: 'en',
50
+ theme: 'dark',
51
+ }, options: {
52
+ debug: process.env.NODE_ENV === 'development',
53
+ addViewportTag: false,
54
+ adaptIframeHeight: true,
55
+ enableScrollIntoView: true,
56
+ }, onMessage: (type, payload) => {
57
+ /*
58
+
59
+ ------------------------
60
+ REJECTED
61
+ ------------------------
62
+
63
+ {
64
+ "type": "idCheck.onApplicantStatusChanged",
65
+ "payload": {
66
+ "reviewId": "toJnn",
67
+ "attemptId": "ooaKO",
68
+ "attemptCnt": 1,
69
+ "elapsedSincePendingMs": 1072,
70
+ "elapsedSinceQueuedMs": 1072,
71
+ "reprocessing": true,
72
+ "levelName": "id-and-liveness",
73
+ "levelAutoCheckMode": null,
74
+ "createDate": "2025-07-18 02:08:16+0000",
75
+ "reviewDate": "2025-07-18 02:08:17+0000",
76
+ "reviewResult": {
77
+ "moderationComment": "We couldn’t verify your...",
78
+ "reviewAnswer": "RED",
79
+ "reviewRejectType": "FINAL"
80
+ },
81
+ "reviewStatus": "completed",
82
+ "priority": 0
83
+ }
78
84
  }
79
- }
80
-
81
- ------------------------
82
- APPROVED
83
- ------------------------
84
-
85
- {
86
- "type": "idCheck.onApplicantStatusChanged",
87
- "payload": {
88
- "reviewId": "RCAdU",
89
- "attemptId": "iaOXv",
90
- "attemptCnt": 1,
91
- "elapsedSincePendingMs": 1956,
92
- "elapsedSinceQueuedMs": 1956,
93
- "reprocessing": true,
94
- "levelName": "id-and-selfie",
95
- "levelAutoCheckMode": null,
96
- "createDate": "2025-07-18 02:17:52+0000",
97
- "reviewDate": "2025-07-18 02:17:54+0000",
98
- "reviewResult": {
99
- "reviewAnswer": "GREEN"
100
- },
101
- "reviewStatus": "completed",
102
- "priority": 0
85
+
86
+ ------------------------
87
+ APPROVED
88
+ ------------------------
89
+
90
+ {
91
+ "type": "idCheck.onApplicantStatusChanged",
92
+ "payload": {
93
+ "reviewId": "RCAdU",
94
+ "attemptId": "iaOXv",
95
+ "attemptCnt": 1,
96
+ "elapsedSincePendingMs": 1956,
97
+ "elapsedSinceQueuedMs": 1956,
98
+ "reprocessing": true,
99
+ "levelName": "id-and-selfie",
100
+ "levelAutoCheckMode": null,
101
+ "createDate": "2025-07-18 02:17:52+0000",
102
+ "reviewDate": "2025-07-18 02:17:54+0000",
103
+ "reviewResult": {
104
+ "reviewAnswer": "GREEN"
105
+ },
106
+ "reviewStatus": "completed",
107
+ "priority": 0
108
+ }
103
109
  }
104
- }
105
-
106
- */
107
- console.log({
108
- type,
109
- payload,
110
- });
111
- const queryClient = getQueryClient();
112
- if (type === 'idCheck.onApplicantStatusChanged' &&
113
- isObject(payload) &&
114
- 'reviewStatus' in payload &&
115
- payload.reviewStatus === 'completed' &&
116
- 'reviewResult' in payload &&
117
- isObject(payload.reviewResult) &&
118
- 'reviewAnswer' in payload.reviewResult &&
119
- payload.reviewResult.reviewAnswer === 'GREEN') {
120
- queryClient.setQueryData(getMemberVerificationQueryKey(), (prev) => ({
121
- id: '',
122
- address: '',
123
- nationality: '',
124
- natureOfWork: '',
125
- placeOfBirth: '',
126
- sourceOfIncome: '',
127
- permanentAddress: '',
128
- selfieImage: { id: '', url: '', status: 'READY' },
129
- idFrontImage: { id: '', url: '', status: 'READY' },
130
- ...(prev ?? {}),
131
- status: 'APPROVED',
132
- sumsubVerified: true,
133
- }));
134
- queryClient.setQueryData(getAccountQueryKey(), (prev) => {
135
- if (!prev)
136
- return prev;
137
- return {
138
- ...prev,
139
- verified: true,
140
- };
141
- });
142
- queryClient.setQueryData(getProfileCompletionQueryKey(), (prev) => {
143
- if (!prev)
144
- return prev;
145
- return {
146
- ...prev,
147
- accountVerification: true,
148
- };
149
- });
150
- }
151
- }, onError: (error) => {
152
- console.warn(error);
153
- }, className: "block max-h-full w-full overflow-y-auto rounded-md", force: true }) })) }) })] }) }), _jsx(KYCReminder, { ...props })] }));
110
+
111
+ */
112
+ const queryClient = getQueryClient();
113
+ if (type === 'idCheck.onApplicantStatusChanged' &&
114
+ isObject(payload) &&
115
+ 'reviewStatus' in payload &&
116
+ payload.reviewStatus === 'completed' &&
117
+ 'reviewResult' in payload &&
118
+ isObject(payload.reviewResult) &&
119
+ 'reviewAnswer' in payload.reviewResult &&
120
+ payload.reviewResult.reviewAnswer === 'GREEN') {
121
+ queryClient.setQueryData(getMemberVerificationQueryKey(), (prev) => ({
122
+ id: '',
123
+ address: '',
124
+ nationality: '',
125
+ natureOfWork: '',
126
+ placeOfBirth: '',
127
+ sourceOfIncome: '',
128
+ permanentAddress: '',
129
+ selfieImage: { id: '', url: '', status: 'READY' },
130
+ idFrontImage: { id: '', url: '', status: 'READY' },
131
+ ...(prev ?? {}),
132
+ status: 'APPROVED',
133
+ sumsubVerified: true,
134
+ }));
135
+ queryClient.setQueryData(getAccountQueryKey(), (prev) => {
136
+ if (!prev)
137
+ return prev;
138
+ return {
139
+ ...prev,
140
+ verified: true,
141
+ };
142
+ });
143
+ queryClient.setQueryData(getProfileCompletionQueryKey(), (prev) => {
144
+ if (!prev)
145
+ return prev;
146
+ return {
147
+ ...prev,
148
+ accountVerification: true,
149
+ };
150
+ });
151
+ }
152
+ }, onError: (error) => {
153
+ console.warn(error);
154
+ }, className: "block max-h-full w-full overflow-y-auto rounded-md", force: true }) }))] }) })] }) }), _jsx(KYCReminder, { ...props })] }));
154
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opexa/portal-components",
3
- "version": "0.0.495",
3
+ "version": "0.0.497",
4
4
  "exports": {
5
5
  "./ui/*": {
6
6
  "types": "./dist/ui/*/index.d.ts",