@opexa/portal-components 0.0.185 → 0.0.187
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/components/Quests/DailyCheckInQuest.js +10 -11
- package/dist/components/SignUp/SignUp.d.ts +2 -2
- package/dist/components/SignUp/SignUp.js +3 -3
- package/dist/components/SignUp/SignUpForm.js +1 -2
- package/dist/components/SignUp/SignUpKYC/CaptureIdDocument.d.ts +1 -0
- package/dist/components/SignUp/SignUpKYC/CaptureIdDocument.js +198 -0
- package/dist/components/SignUp/SignUpKYC/CaptureSelfie.d.ts +1 -0
- package/dist/components/SignUp/SignUpKYC/CaptureSelfie.js +251 -0
- package/dist/components/SignUp/SignUpKYC/ImageUploader.d.ts +10 -0
- package/dist/components/SignUp/SignUpKYC/ImageUploader.js +41 -0
- package/dist/components/SignUp/SignUpKYC/SignUpFormKYC.d.ts +1 -0
- package/dist/components/SignUp/SignUpKYC/SignUpFormKYC.js +429 -0
- package/dist/components/SignUp/SignUpKYC/SignUpKYC.lazy.d.ts +13 -0
- package/dist/components/SignUp/SignUpKYC/SignUpKYC.lazy.js +26 -0
- package/dist/components/SignUp/SignUpKYC/SignUpKYCContext.d.ts +7 -0
- package/dist/components/SignUp/SignUpKYC/SignUpKYCContext.js +2 -0
- package/dist/components/SignUp/SignUpKYC/useImageUploader.d.ts +11 -0
- package/dist/components/SignUp/SignUpKYC/useImageUploader.js +20 -0
- package/dist/ui/AlertDialog/AlertDialog.d.ts +121 -121
- package/dist/ui/AlertDialog/alertDialog.recipe.d.ts +8 -8
- package/dist/ui/Avatar/Avatar.d.ts +9 -9
- package/dist/ui/Badge/Badge.d.ts +12 -12
- package/dist/ui/Badge/badge.anatomy.d.ts +1 -1
- package/dist/ui/Badge/badge.recipe.d.ts +3 -3
- package/dist/ui/Carousel/Carousel.d.ts +45 -45
- package/dist/ui/Carousel/carousel.recipe.d.ts +5 -5
- package/dist/ui/Checkbox/Checkbox.d.ts +23 -23
- package/dist/ui/Checkbox/checkbox.recipe.d.ts +3 -3
- package/dist/ui/Clipboard/Clipboard.d.ts +18 -18
- package/dist/ui/Clipboard/clipboard.recipe.d.ts +3 -3
- package/dist/ui/Collapsible/Collapsible.d.ts +32 -32
- package/dist/ui/Combobox/Combobox.d.ts +42 -42
- package/dist/ui/Combobox/combobox.recipe.d.ts +3 -3
- package/dist/ui/DatePicker/DatePicker.d.ts +72 -72
- package/dist/ui/DatePicker/datePicker.recipe.d.ts +3 -3
- package/dist/ui/Dialog/Dialog.d.ts +121 -121
- package/dist/ui/Dialog/dialog.recipe.d.ts +8 -8
- package/dist/ui/Drawer/Drawer.d.ts +33 -33
- package/dist/ui/Drawer/drawer.recipe.d.ts +3 -3
- package/dist/ui/Field/Field.d.ts +21 -21
- package/dist/ui/Menu/Menu.d.ts +144 -144
- package/dist/ui/Menu/menu.recipe.d.ts +5 -5
- package/dist/ui/NumberInput/NumberInput.d.ts +24 -24
- package/dist/ui/PasswordInput/PasswordInput.d.ts +18 -18
- package/dist/ui/PasswordInput/passwordInput.recipe.d.ts +3 -3
- package/dist/ui/PinInput/PinInput.d.ts +12 -12
- package/dist/ui/Popover/Popover.d.ts +88 -88
- package/dist/ui/Progress/Progress.d.ts +27 -27
- package/dist/ui/Progress/progress.recipe.d.ts +3 -3
- package/dist/ui/QrCode/QrCode.d.ts +25 -25
- package/dist/ui/QrCode/qrCode.recipe.d.ts +5 -5
- package/dist/ui/SegmentGroup/SegmentGroup.d.ts +18 -18
- package/dist/ui/Select/Select.d.ts +45 -45
- package/dist/ui/Select/select.recipe.d.ts +3 -3
- package/dist/ui/Table/Table.d.ts +21 -21
- package/dist/ui/Table/table.anatomy.d.ts +1 -1
- package/dist/ui/Table/table.recipe.d.ts +3 -3
- package/dist/ui/Tabs/Tabs.d.ts +15 -15
- package/dist/ui/Tabs/tabs.recipe.d.ts +3 -3
- package/dist/ui/Tooltip/tooltip.recipe.d.ts +5 -5
- package/package.json +1 -1
- package/dist/components/KYC/backup/Header.d.ts +0 -1
- package/dist/components/KYC/backup/Header.js +0 -8
- package/dist/components/KYC/backup/Indicator.d.ts +0 -1
- package/dist/components/KYC/backup/Indicator.js +0 -9
- package/dist/components/KYC/backup/KYC.d.ts +0 -1
- package/dist/components/KYC/backup/KYC.js +0 -14
- package/dist/components/KYC/backup/KYC.lazy.d.ts +0 -1
- package/dist/components/KYC/backup/KYC.lazy.js +0 -26
- package/dist/components/KYC/backup/KYCContext.d.ts +0 -6
- package/dist/components/KYC/backup/KYCContext.js +0 -2
- package/dist/components/KYC/backup/Step1.d.ts +0 -1
- package/dist/components/KYC/backup/Step1.js +0 -13
- package/dist/components/KYC/backup/Step2.d.ts +0 -1
- package/dist/components/KYC/backup/Step2.js +0 -13
- package/dist/components/KYC/backup/Step3.d.ts +0 -1
- package/dist/components/KYC/backup/Step3.js +0 -13
- package/dist/components/KYC/backup/Step4.d.ts +0 -1
- package/dist/components/KYC/backup/Step4.js +0 -7
- package/dist/components/KYC/backup/useKYC.d.ts +0 -10
- package/dist/components/KYC/backup/useKYC.js +0 -8
- package/dist/components/KYC/loadModels.d.ts +0 -1
- package/dist/components/KYC/loadModels.js +0 -9
- package/dist/components/Messages/Message.d.ts +0 -1
- package/dist/components/Messages/Message.js +0 -35
- package/dist/components/Messages/MessageContext.d.ts +0 -6
- package/dist/components/Messages/MessageContext.js +0 -2
- package/dist/components/Messages/MessagePopup.d.ts +0 -1
- package/dist/components/Messages/MessagePopup.js +0 -20
- package/dist/components/Messages/MessageTrigger.d.ts +0 -8
- package/dist/components/Messages/MessageTrigger.js +0 -19
- package/dist/components/Quests/CountdownTimer.d.ts +0 -15
- package/dist/components/Quests/CountdownTimer.js +0 -33
- package/dist/components/Quests/DailyCheckInQuest/DailyCheckInQuest.d.ts +0 -4
- package/dist/components/Quests/DailyCheckInQuest/DailyCheckInQuest.js +0 -78
- package/dist/components/Quests/DailyCheckInQuest/DailyCheckInQuestModal.d.ts +0 -8
- package/dist/components/Quests/DailyCheckInQuest/DailyCheckInQuestModal.js +0 -9
- package/dist/components/Quests/OnboardingQuest/OnboardingQuest.d.ts +0 -4
- package/dist/components/Quests/OnboardingQuest/OnboardingQuest.js +0 -4
- package/dist/components/Quests/WageringQuest/WageringQuest.d.ts +0 -4
- package/dist/components/Quests/WageringQuest/WageringQuest.js +0 -20
- package/dist/components/Quests/WageringQuest/WageringQuestModal.d.ts +0 -9
- package/dist/components/Quests/WageringQuest/WageringQuestModal.js +0 -9
- package/dist/constants/BranchCode.d.ts +0 -4
- package/dist/constants/BranchCode.js +0 -42
- package/dist/icons/BellRingIcon.d.ts +0 -2
- package/dist/icons/BellRingIcon.js +0 -4
- package/dist/utils/dataUrlToBlob.d.ts +0 -1
- package/dist/utils/dataUrlToBlob.js +0 -11
- package/dist/utils/resizeImageSize.d.ts +0 -2
- package/dist/utils/resizeImageSize.js +0 -11
|
@@ -8,7 +8,6 @@ import { useDisclosure } from '../../client/hooks/useDisclosure.js';
|
|
|
8
8
|
import { useLocaleInfo } from '../../client/hooks/useLocaleInfo.js';
|
|
9
9
|
import { useRemainingTime } from '../../client/hooks/useRemainingTime.js';
|
|
10
10
|
import { toaster } from '../../client/utils/toaster.js';
|
|
11
|
-
import { CalendarIcon } from '../../icons/CalendarIcon.js';
|
|
12
11
|
import { CheckIcon } from '../../icons/CheckIcon.js';
|
|
13
12
|
import { InfoCircleIcon } from '../../icons/InfoCircleIcon.js';
|
|
14
13
|
import { XIcon } from '../../icons/XIcon.js';
|
|
@@ -59,22 +58,22 @@ export function DailyCheckInQuest() {
|
|
|
59
58
|
});
|
|
60
59
|
const remainingTime = useRemainingTime(endDateTime);
|
|
61
60
|
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "border-border-primary bg-bg-tertiary flex h-full w-full flex-col space-y-6 rounded-2xl border px-4 pb-6 pt-5", children: [_jsxs("div", { className: "flex flex-col space-y-2", children: [_jsxs("div", { className: "flex max-h-7.5 items-start justify-between", children: [_jsx(RemainingTime, {}), _jsx("button", { type: "button", className: "bg-bg-primary border-border-secondary flex size-9 cursor-pointer items-center justify-center rounded-md border", onClick: () => disclosure.setOpen(true), "aria-label": "View Rules", children: _jsx(InfoCircleIcon, { className: "text-text-disabled size-5" }) })] }), _jsx("p", { className: "text-xl font-semibold", children: name }), _jsx("div", { className: "text-text-secondary-700 text-wrap text-sm font-normal", dangerouslySetInnerHTML: { __html: description } })] }), _jsxs("div", { className: "flex w-full flex-col space-y-2", children: [_jsx("div", { className: "grid grid-cols-7", children: dailyCheckedInData.map((item) => {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return (_jsx("div", { className: twMerge('flex items-center justify-center', item.day <= (checkInStreak || 0)
|
|
70
|
-
? 'text-brand-400'
|
|
71
|
-
: 'text-text-secondary-700'), children: _jsx("p", { children: reward }) }, item.day));
|
|
61
|
+
const done = item.day <= (checkInStreak ?? 0);
|
|
62
|
+
const reward = item.reward ? (`+${formatNumber(item.reward, {
|
|
63
|
+
currency: localeInfo.currency.code,
|
|
64
|
+
minDecimalPlaces: 0,
|
|
65
|
+
maxDecimalPlaces: 0,
|
|
66
|
+
})}`) : done ? (_jsx(CheckIcon, { className: "size-4" })) : ('-');
|
|
67
|
+
return (_jsx("div", { className: twMerge('flex items-center justify-center', done ? 'text-brand-400' : 'text-text-secondary-700'), children: _jsx("p", { children: reward }) }, item.day));
|
|
72
68
|
}) }), _jsx("div", { className: "bg-bg-primary h-2 w-full overflow-hidden rounded-full", children: _jsx("div", { className: "bg-utility-brand-600 h-full rounded-full transition-all duration-300", style: { width: `${progressPercentage}%` } }) }), _jsx("div", { className: "grid grid-cols-7 place-items-center", children: dailyCheckedInData.map((item) => (_jsxs("div", { className: "text-text-secondary-700 ui-active:text-brand-400 group relative size-fit", "data-active": dataAttr(item.day <= (checkInStreak ?? 0)), children: [_jsx(CalendarIcon, { className: "h-4.5 w-auto" }), _jsx("p", { className: "absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 text-2xs leading-none", children: item.day })] }, item.day))) })] }), _jsx(Button, { onClick: () => checkInDailyQuestMutation.mutate(id), className: "disabled:bg-bg-primary disabled:text-text-disabled", disabled: status === 'COMPLETED' ||
|
|
73
69
|
status === 'FAILED' ||
|
|
74
70
|
remainingTime.expired ||
|
|
75
71
|
hasCheckedInToday ||
|
|
76
72
|
checkInDailyQuestMutation.isPending, children: hasCheckedInToday && status === 'IN_PROGRESS' ? (_jsx(RemainingTimeTilTomorrow, {})) : (_jsx("span", { children: "Check-In" })) })] }), _jsx(Rules, { open: disclosure.open, onOpenChange: disclosure.setOpen })] }));
|
|
77
73
|
}
|
|
74
|
+
function CalendarIcon(props) {
|
|
75
|
+
return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "17", height: "18", viewBox: "0 0 17 18", fill: "none", ...props, children: _jsx("path", { d: "M11.5477 0.666687V4.00002M4.88102 0.666687V4.00002M4.71436 17.3334H11.7144C13.1145 17.3334 13.8146 17.3334 14.3493 17.0609C14.8197 16.8212 15.2022 16.4387 15.4419 15.9683C15.7144 15.4336 15.7144 14.7335 15.7144 13.3334V6.33335C15.7144 4.93322 15.7144 4.23316 15.4419 3.69838C15.2022 3.22797 14.8197 2.84552 14.3493 2.60584C13.8146 2.33335 13.1145 2.33335 11.7144 2.33335H4.71436C3.31422 2.33335 2.61416 2.33335 2.07938 2.60584C1.60897 2.84552 1.22652 3.22797 0.986839 3.69838C0.714355 4.23316 0.714355 4.93322 0.714355 6.33335V13.3334C0.714355 14.7335 0.714355 15.4336 0.986839 15.9683C1.22652 16.4387 1.60897 16.8212 2.07938 17.0609C2.61416 17.3334 3.31422 17.3334 4.71436 17.3334Z", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
76
|
+
}
|
|
78
77
|
function RemainingTimeTilTomorrow() {
|
|
79
78
|
const queryClient = getQueryClient();
|
|
80
79
|
const remainingTime = useRemainingTime(startOfDay(addDays(new Date(), 1)), {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { SignUpProps } from './SignUpDefault/SignUp.lazy';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function SignUp(props: SignUpProps |
|
|
2
|
+
import type { SignUpKYCProps } from './SignUpKYC/SignUpKYC.lazy';
|
|
3
|
+
export declare function SignUp(props: SignUpProps | SignUpKYCProps): import("react/jsx-runtime").JSX.Element | null;
|
|
4
4
|
export type { SignUpProps };
|
|
@@ -7,7 +7,7 @@ const SignUpDefault = dynamic(() => import('./SignUpDefault/SignUp.lazy.js').the
|
|
|
7
7
|
ssr: false,
|
|
8
8
|
loading: () => null,
|
|
9
9
|
});
|
|
10
|
-
const
|
|
10
|
+
const SignUpKYC = dynamic(() => import('./SignUpKYC/SignUpKYC.lazy.js').then((m) => m.SignUpKYC), {
|
|
11
11
|
ssr: false,
|
|
12
12
|
loading: () => null,
|
|
13
13
|
});
|
|
@@ -15,8 +15,8 @@ export function SignUp(props) {
|
|
|
15
15
|
const touched = useGlobalStore(useShallow((ctx) => ctx.signUp['~touched']));
|
|
16
16
|
if (!touched)
|
|
17
17
|
return null;
|
|
18
|
-
if (props.layout === '
|
|
19
|
-
return _jsx(
|
|
18
|
+
if (props.layout === 'kyc') {
|
|
19
|
+
return _jsx(SignUpKYC, { ...props });
|
|
20
20
|
}
|
|
21
21
|
return _jsx(SignUpDefault, { ...props });
|
|
22
22
|
}
|
|
@@ -192,7 +192,6 @@ export function SignUpForm() {
|
|
|
192
192
|
mobileNumber: mobileNumberParser.format(mobileNumber),
|
|
193
193
|
verificationCode: verificationCode.join(''),
|
|
194
194
|
referralCode: search.get('referralCode') ?? undefined,
|
|
195
|
-
domain: search.get('domain') ?? undefined,
|
|
196
195
|
btag: search.get('btag') ?? undefined,
|
|
197
196
|
});
|
|
198
197
|
const name = mobileNumberParser.format(mobileNumber);
|
|
@@ -252,7 +251,7 @@ export function SignUpForm() {
|
|
|
252
251
|
o.field.onChange(details.value);
|
|
253
252
|
}, onValueComplete: () => {
|
|
254
253
|
form2Ref.current?.requestSubmit();
|
|
255
|
-
}, children: [_jsxs(PinInput.Control, { className: "grid-cols-[1fr_1fr_1fr_auto_1fr_1fr_1fr] items-center gap-md", children: [_jsx(PinInput.Input, { index: 0 }), _jsx(PinInput.Input, { index: 1 }), _jsx(PinInput.Input, { index: 2 }), _jsx("span", { className: "text-text-placeholder-subtle text-2xl font-medium", children: "\u2013" }), _jsx(PinInput.Input, { index: 3 }), _jsx(PinInput.Input, { index: 4 }), _jsx(PinInput.Input, { index: 5 })] }), _jsx(PinInput.HiddenInput, {})] }), _jsx(Field.ErrorText, { children: o.formState.errors.verificationCode?.message })] })) }), _jsx(Button, { type: "submit", className: "mt-4xl", disabled: step2Form.formState.isSubmitting, children: "Verify" }), _jsxs("div", { className: "mt-3 flex w-full items-center justify-center gap-xs text-sm", children: [_jsx("span", { className: "text-text-secondary-700", children: "Didn't recieve the code?" }), _jsx("button", { type: "button", className: "text-button-secondary-fg font-semibold disabled:cursor-not-allowed disabled:opacity-75", disabled: cooldown.cooling, onClick: async () => {
|
|
254
|
+
}, blurOnComplete: true, readOnly: step2Form.formState.isSubmitting, type: "numeric", children: [_jsxs(PinInput.Control, { className: "grid-cols-[1fr_1fr_1fr_auto_1fr_1fr_1fr] items-center gap-md", children: [_jsx(PinInput.Input, { index: 0 }), _jsx(PinInput.Input, { index: 1 }), _jsx(PinInput.Input, { index: 2 }), _jsx("span", { className: "text-text-placeholder-subtle text-2xl font-medium", children: "\u2013" }), _jsx(PinInput.Input, { index: 3 }), _jsx(PinInput.Input, { index: 4 }), _jsx(PinInput.Input, { index: 5 })] }), _jsx(PinInput.HiddenInput, {})] }), _jsx(Field.ErrorText, { children: o.formState.errors.verificationCode?.message })] })) }), _jsx(Button, { type: "submit", className: "mt-4xl", disabled: step2Form.formState.isSubmitting, children: "Verify" }), _jsxs("div", { className: "mt-3 flex w-full items-center justify-center gap-xs text-sm", children: [_jsx("span", { className: "text-text-secondary-700", children: "Didn't recieve the code?" }), _jsx("button", { type: "button", className: "text-button-secondary-fg font-semibold disabled:cursor-not-allowed disabled:opacity-75", disabled: cooldown.cooling, onClick: async () => {
|
|
256
255
|
await sendVerificationCodeMutation.mutateAsync({
|
|
257
256
|
channel: 'SMS',
|
|
258
257
|
recipient: mobileNumberParser.format(step1Form.getValues('mobileNumber')),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function CaptureIdDocument(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { twMerge } from 'tailwind-merge';
|
|
5
|
+
import { ArrowLeftIcon } from '../../../icons/ArrowLeftIcon.js';
|
|
6
|
+
import { Camera01Icon } from '../../../icons/Camera01Icon.js';
|
|
7
|
+
import { CheckCircleIcon } from '../../../icons/CheckCircleIcon.js';
|
|
8
|
+
import { XIcon } from '../../../icons/XIcon.js';
|
|
9
|
+
import { Button } from '../../../ui/Button/index.js';
|
|
10
|
+
import { Dialog } from '../../../ui/Dialog/index.js';
|
|
11
|
+
import { Portal } from '../../../ui/Portal/index.js';
|
|
12
|
+
import { dataURLtoBlob, resizeFile } from '../../KYC/utils.js';
|
|
13
|
+
import { useSignUpKYCPropsContext } from './SignUpKYCContext.js';
|
|
14
|
+
export function CaptureIdDocument() {
|
|
15
|
+
const props = useSignUpKYCPropsContext();
|
|
16
|
+
const [videoStream, setVideoStream] = useState(null);
|
|
17
|
+
const [cameraError, setCameraError] = useState(null);
|
|
18
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
19
|
+
const [selectedImage, setSelectedImage] = useState(null);
|
|
20
|
+
const [captureInProgress, setCaptureInProgress] = useState(false);
|
|
21
|
+
const [proccessImageCanvas, setProccessImageCanvas] = useState(null);
|
|
22
|
+
const videoElement = useRef(null);
|
|
23
|
+
const containerRef = useRef(null);
|
|
24
|
+
function stopCamera() {
|
|
25
|
+
if (videoStream) {
|
|
26
|
+
videoStream.getTracks().forEach((track) => track.stop());
|
|
27
|
+
setVideoStream(null);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
return () => {
|
|
32
|
+
stopCamera();
|
|
33
|
+
};
|
|
34
|
+
}, [videoStream]);
|
|
35
|
+
async function startCamera() {
|
|
36
|
+
try {
|
|
37
|
+
setIsLoading(true);
|
|
38
|
+
setCameraError(null);
|
|
39
|
+
setCaptureInProgress(true);
|
|
40
|
+
console.log('Starting camera...');
|
|
41
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
42
|
+
video: {
|
|
43
|
+
facingMode: 'environment',
|
|
44
|
+
aspectRatio: 16 / 9,
|
|
45
|
+
width: { ideal: 1920, max: 1920 },
|
|
46
|
+
height: { ideal: 1080, max: 1080 },
|
|
47
|
+
frameRate: {
|
|
48
|
+
ideal: 30,
|
|
49
|
+
max: 60,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
audio: false,
|
|
53
|
+
});
|
|
54
|
+
// Set the stream directly to the video element
|
|
55
|
+
if (videoElement.current) {
|
|
56
|
+
videoElement.current.srcObject = stream;
|
|
57
|
+
videoElement.current.onloadedmetadata = () => {
|
|
58
|
+
console.log('Video metadata loaded, starting playback...');
|
|
59
|
+
videoElement.current
|
|
60
|
+
?.play()
|
|
61
|
+
.then(() => {
|
|
62
|
+
setVideoStream(stream);
|
|
63
|
+
setIsLoading(false);
|
|
64
|
+
})
|
|
65
|
+
.catch(() => {
|
|
66
|
+
setCameraError('Failed to start camera stream. Please try again.');
|
|
67
|
+
setIsLoading(false);
|
|
68
|
+
// Stop the stream if playback fails
|
|
69
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
videoElement.current.onerror = (err) => {
|
|
73
|
+
console.error('Video element error:', err);
|
|
74
|
+
setCameraError('Video playback error. Please try again.');
|
|
75
|
+
setIsLoading(false);
|
|
76
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.error('Video element not available');
|
|
81
|
+
setCameraError('Camera initialization failed. Please try again.');
|
|
82
|
+
setCaptureInProgress(false);
|
|
83
|
+
setIsLoading(false);
|
|
84
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
setIsLoading(false);
|
|
89
|
+
if (error instanceof DOMException) {
|
|
90
|
+
console.error('Error accessing camera:', error.message);
|
|
91
|
+
setCameraError(error.message);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
console.error('Unknown error accessing camera:', error);
|
|
95
|
+
setCameraError('An unknown error occurred. Please check permissions and try again.');
|
|
96
|
+
}
|
|
97
|
+
setCaptureInProgress(false);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function captureAndProcessImage() {
|
|
101
|
+
if (!videoElement.current || !videoStream) {
|
|
102
|
+
console.error('Video element or stream not available for capture');
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const canvas = document.createElement('canvas');
|
|
107
|
+
const parentDiv = document.getElementById('parent');
|
|
108
|
+
canvas.width = parentDiv?.clientWidth || videoElement.current.width;
|
|
109
|
+
canvas.height = parentDiv?.clientHeight || videoElement.current.height;
|
|
110
|
+
const ctx = canvas.getContext('2d');
|
|
111
|
+
if (!ctx) {
|
|
112
|
+
console.error('Could not get 2D context for canvas');
|
|
113
|
+
setCameraError('Failed to process image. Please try again.');
|
|
114
|
+
setCaptureInProgress(false);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
ctx.drawImage(videoElement.current, 0, 0, canvas.width, canvas.height);
|
|
118
|
+
const imageSrc = canvas.toDataURL('image/png', 1.0);
|
|
119
|
+
setSelectedImage({ src: imageSrc });
|
|
120
|
+
setCaptureInProgress(false);
|
|
121
|
+
stopCamera();
|
|
122
|
+
const newImg = document.createElement('img');
|
|
123
|
+
newImg.src = imageSrc;
|
|
124
|
+
//@ts-expect-error jscanify is not typed
|
|
125
|
+
const scanner = new jscanify();
|
|
126
|
+
newImg.onload = () => {
|
|
127
|
+
try {
|
|
128
|
+
if (containerRef.current) {
|
|
129
|
+
// containerRef.current.innerHTML = '';
|
|
130
|
+
const paperWidth = parentDiv?.clientWidth || videoElement.current?.videoWidth;
|
|
131
|
+
const paperHeight = parentDiv?.clientHeight || videoElement.current?.videoHeight;
|
|
132
|
+
//@ts-expect-error jscanify is not typed
|
|
133
|
+
const contour = scanner.findPaperContour(cv.imread(newImg));
|
|
134
|
+
const cornerPoints = scanner.getCornerPoints(contour);
|
|
135
|
+
const resultCanvas = scanner.extractPaper(newImg, paperWidth, paperHeight, cornerPoints);
|
|
136
|
+
newImg.className =
|
|
137
|
+
'absolute inset-0 m-auto w-full h-auto md:max-h-[333px] md:max-w-[643px] aspect-video rounded-lg object-contain';
|
|
138
|
+
setProccessImageCanvas(resultCanvas);
|
|
139
|
+
containerRef.current.appendChild(resultCanvas);
|
|
140
|
+
setCaptureInProgress(false);
|
|
141
|
+
setSelectedImage({ src: resultCanvas.toDataURL('image/png') });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
console.error('Error processing image:', error);
|
|
146
|
+
setCameraError('Failed to process image. Please try again.');
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
newImg.onerror = () => {
|
|
150
|
+
console.error('Error loading image');
|
|
151
|
+
setCameraError('Failed to load image. Please try again.');
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
console.error('Error capturing image:', error);
|
|
156
|
+
setCameraError('Failed to capture image. Please try again.');
|
|
157
|
+
setCaptureInProgress(false);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async function uploadPhoto() {
|
|
161
|
+
if (!proccessImageCanvas) {
|
|
162
|
+
console.error('Failed to process the image. Please try again.');
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const blob = proccessImageCanvas.toDataURL('image/png', 1.0);
|
|
166
|
+
const processedBlob = dataURLtoBlob(blob);
|
|
167
|
+
const img = new File([processedBlob], 'frontImage', { type: 'image/jpeg' });
|
|
168
|
+
const resizedImage = (await resizeFile(img));
|
|
169
|
+
if (resizedImage) {
|
|
170
|
+
props.setFrontImage(resizedImage);
|
|
171
|
+
props.setCapturing(null);
|
|
172
|
+
stopCamera();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function retakePhoto() {
|
|
176
|
+
setSelectedImage(null);
|
|
177
|
+
setCaptureInProgress(true);
|
|
178
|
+
setCameraError(null);
|
|
179
|
+
if (containerRef.current) {
|
|
180
|
+
const canvas = containerRef.current.querySelector('canvas');
|
|
181
|
+
if (canvas) {
|
|
182
|
+
canvas.width = canvas.width;
|
|
183
|
+
}
|
|
184
|
+
containerRef.current.innerHTML = '';
|
|
185
|
+
}
|
|
186
|
+
if (videoElement.current) {
|
|
187
|
+
videoElement.current.play();
|
|
188
|
+
}
|
|
189
|
+
startCamera();
|
|
190
|
+
}
|
|
191
|
+
return (_jsx(Dialog.Root, { open: props.capturing === 'ID_DOCUMENT', lazyMount: true, unmountOnExit: true, closeOnEscape: false, closeOnInteractOutside: false, children: _jsxs(Portal, { children: [_jsx(Dialog.Backdrop, {}), _jsx(Dialog.Positioner, { children: _jsx(Dialog.Content, { className: twMerge('bg-bg-primary-alt mx-auto h-full w-full items-start p-3xl pb-4xl lg:h-auto lg:w-fit lg:rounded-xl', props.className), children: _jsxs("div", { className: "w-full p-4 lg:w-[640px] lg:px-12 lg:py-4xl", children: [_jsxs("button", { type: "button", className: "flex items-center gap-lg lg:absolute lg:right-5 lg:top-5 lg:p-md", onClick: () => {
|
|
192
|
+
stopCamera();
|
|
193
|
+
props.setCapturing(null);
|
|
194
|
+
}, children: [_jsx(XIcon, { className: "text-text-senary-300 hidden size-5 lg:block" }), _jsx(ArrowLeftIcon, { className: "text-text-senary-300 size-5 lg:hidden" }), _jsx("span", { className: "text-lg font-semibold lg:hidden", children: "Back" })] }), _jsx(Dialog.Title, { className: "mt-6 text-center text-lg font-semibold lg:mt-0", children: "Take a Picture of Your Front ID" }), _jsxs(Dialog.Description, { className: "lg:max-w-auto text-text-tertiary-600 mx-auto mt-sm max-w-[19rem] text-center text-sm lg:max-w-full", children: ["Make sure your ID is clearly visible, well-lit, and not blurry.", _jsx("br", { className: "hidden lg:block" }), " Avoid glare or reflections, and ensure all corners are within the frame."] }), _jsx("div", { id: "parent", className: "border-border-disabled mt-6 aspect-video rounded-xl border bg-black lg:mt-8", children: cameraError ? (_jsx("div", { className: "flex h-full items-center justify-center p-4", children: _jsxs("div", { className: "text-center", children: [_jsx("p", { className: "text-red-500 mb-2 text-sm", children: "Camera Error" }), _jsx("p", { className: "text-gray-400 text-xs", children: cameraError })] }) })) : captureInProgress ? (_jsxs("div", { className: "relative flex h-fit w-full flex-col items-center justify-center", children: [_jsx("video", { ref: videoElement, autoPlay: true, muted: true, playsInline: true, className: "relative h-[60vh] w-full rounded-lg object-cover md:aspect-video md:max-h-[333px]", width: "100%", height: "100%" }), _jsxs("div", { className: "pointer-events-none absolute inset-0 z-50", children: [_jsx("div", { className: twMerge('absolute inset-0 w-full bg-black/60 backdrop-blur-sm [clip-path:polygon(0%_0%,0%_100%,calc(50%-158px)_100%,calc(50%-158px)_calc(50%-100px),calc(50%+158px)_calc(50%-100px),calc(50%+158px)_calc(50%+100px),calc(50%-158px)_calc(50%+100px),calc(50%-158px)_100%,100%_100%,100%_0%)] md:[clip-path:polygon(0%_0%,0%_100%,calc(50%-225px)_100%,calc(50%-225px)_calc(50%-142px),calc(50%+225px)_calc(50%-142px),calc(50%+225px)_calc(50%+142px),calc(50%-225px)_calc(50%+142px),calc(50%-225px)_100%,100%_100%,100%_0%)]') }), _jsx("div", { className: "absolute inset-0 z-[60] mx-auto flex items-center justify-center", children: _jsx("div", { className: "relative aspect-[1011/638] h-[200px] md:h-[295px] md:w-[450px]", children: _jsx("div", { className: "h-full w-full rounded-lg border-4 border-dashed border-[#B54708]" }) }) })] })] })) : (_jsx("div", { ref: containerRef, className: "relative grid h-full w-full place-items-center rounded-lg object-contain md:max-h-[333px]" })) }), cameraError ? (_jsx("div", { className: "mt-4 text-center", children: _jsx(Button, { className: "mx-auto px-xl lg:w-fit", onClick: () => {
|
|
195
|
+
setCameraError(null);
|
|
196
|
+
startCamera();
|
|
197
|
+
}, children: "Try Again" }) })) : captureInProgress ? (_jsxs(Button, { className: "disabled:bg-bg-disabled disabled:text-text-disabled mx-auto mt-6 px-xl disabled:opacity-100 lg:mt-8 lg:w-fit", onClick: captureAndProcessImage, children: ["Capture Image", _jsx(Camera01Icon, { className: "size-5" })] })) : selectedImage && selectedImage.src ? (_jsxs("div", { className: "mt-4 flex flex-col items-center justify-center gap-2 md:flex-row", children: [_jsxs(Button, { className: "lg:w-fit", type: "button", onClick: retakePhoto, children: ["Retake Photo ", _jsx(Camera01Icon, { className: "ml-1" })] }), _jsxs(Button, { className: "lg:w-fit", type: "button", onClick: uploadPhoto, children: ["Use Photo ", _jsx(CheckCircleIcon, { className: "ml-1" })] })] })) : (_jsxs(Button, { className: "disabled:bg-bg-disabled disabled:text-text-disabled mx-auto mt-6 px-xl disabled:opacity-100 lg:mt-8 lg:w-fit", onClick: startCamera, disabled: isLoading || !!videoStream, children: [isLoading ? 'Starting Camera...' : 'Start Camera', _jsx(Camera01Icon, { className: "size-5" })] }))] }) }) })] }) }));
|
|
198
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function CaptureSelfie(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as faceapi from 'face-api.js';
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { twMerge } from 'tailwind-merge';
|
|
6
|
+
import { ArrowLeftIcon } from '../../../icons/ArrowLeftIcon.js';
|
|
7
|
+
import { Camera01Icon } from '../../../icons/Camera01Icon.js';
|
|
8
|
+
import { XIcon } from '../../../icons/XIcon.js';
|
|
9
|
+
import { Button } from '../../../ui/Button/index.js';
|
|
10
|
+
import { Dialog } from '../../../ui/Dialog/index.js';
|
|
11
|
+
import { Portal } from '../../../ui/Portal/index.js';
|
|
12
|
+
import { onMobileDevice } from '../../../utils/onMobileDevice.js';
|
|
13
|
+
import PersonOverlayDesktop from '../../KYC/PersonOverlayDesktop.js';
|
|
14
|
+
import { dataURLtoBlob, loadFaceApiModels, resizeFile } from '../../KYC/utils.js';
|
|
15
|
+
import { useSignUpKYCPropsContext } from './SignUpKYCContext.js';
|
|
16
|
+
export function CaptureSelfie() {
|
|
17
|
+
const props = useSignUpKYCPropsContext();
|
|
18
|
+
const mobileDevice = onMobileDevice();
|
|
19
|
+
const [modelsLoaded, setModelsLoaded] = useState(false);
|
|
20
|
+
const [videoStream, setVideoStream] = useState(null);
|
|
21
|
+
const [cameraError, setCameraError] = useState(null);
|
|
22
|
+
const [captureInProgress, setCaptureInProgress] = useState(false);
|
|
23
|
+
const [selectedImage, setSelectedImage] = useState(null);
|
|
24
|
+
const [isFaceCentered, setIsFaceCentered] = useState(false);
|
|
25
|
+
const [isCapturing, setIsCapturing] = useState(false);
|
|
26
|
+
const [countdown, setCountdown] = useState(3);
|
|
27
|
+
const videoRef = useRef(null);
|
|
28
|
+
const faceCanvasRef = useRef(null);
|
|
29
|
+
const detectionIntervalRef = useRef(null);
|
|
30
|
+
const countdownTimerRef = useRef(null);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
loadFaceApiModels()
|
|
33
|
+
.then(() => setModelsLoaded(true))
|
|
34
|
+
.catch(() => setModelsLoaded(false));
|
|
35
|
+
}, []);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (captureInProgress) {
|
|
38
|
+
startFaceDetection();
|
|
39
|
+
}
|
|
40
|
+
}, [captureInProgress]);
|
|
41
|
+
async function startCamera() {
|
|
42
|
+
setCaptureInProgress(true);
|
|
43
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
44
|
+
video: {
|
|
45
|
+
facingMode: mobileDevice ? 'user' : 'environment',
|
|
46
|
+
aspectRatio: mobileDevice ? 9 / 16 : 16 / 9,
|
|
47
|
+
width: { ideal: 1920 },
|
|
48
|
+
height: { ideal: 1080 },
|
|
49
|
+
},
|
|
50
|
+
audio: false,
|
|
51
|
+
});
|
|
52
|
+
setVideoStream(stream);
|
|
53
|
+
if (videoRef.current) {
|
|
54
|
+
videoRef.current.srcObject = stream;
|
|
55
|
+
videoRef.current.onloadedmetadata = () => {
|
|
56
|
+
videoRef.current
|
|
57
|
+
?.play()
|
|
58
|
+
.then(() => {
|
|
59
|
+
if (modelsLoaded) {
|
|
60
|
+
startFaceDetection();
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
.catch((error) => {
|
|
64
|
+
console.error('Error playing video:', error);
|
|
65
|
+
setCameraError('Failed to play video stream. Please check your camera settings.');
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function startFaceDetection() {
|
|
71
|
+
if (!modelsLoaded) {
|
|
72
|
+
console.error('Cannot start face detection: video element not ready or models not loaded');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (!faceCanvasRef.current) {
|
|
76
|
+
faceCanvasRef.current = faceapi.createCanvasFromMedia(videoRef.current);
|
|
77
|
+
const parentDiv = document.getElementById('parent');
|
|
78
|
+
faceCanvasRef.current.className = `absolute inset-0 m-auto h-${parentDiv?.clientHeight} w-${parentDiv?.clientWidth} md:aspect-video object-cover md:object-contain`;
|
|
79
|
+
faceCanvasRef.current.style.width = `${videoRef.current?.clientWidth}px`;
|
|
80
|
+
faceCanvasRef.current.style.height = `${videoRef.current?.clientHeight}px`;
|
|
81
|
+
}
|
|
82
|
+
const displaySize = {
|
|
83
|
+
width: videoRef.current?.clientWidth || 643,
|
|
84
|
+
height: videoRef.current?.clientHeight || 333,
|
|
85
|
+
};
|
|
86
|
+
// Clear any existing interval
|
|
87
|
+
if (detectionIntervalRef.current) {
|
|
88
|
+
clearInterval(detectionIntervalRef.current);
|
|
89
|
+
}
|
|
90
|
+
faceapi.matchDimensions(faceCanvasRef.current, displaySize);
|
|
91
|
+
let countdownInterval = null;
|
|
92
|
+
detectionIntervalRef.current = window.setInterval(async () => {
|
|
93
|
+
if (!videoRef.current || !faceCanvasRef.current) {
|
|
94
|
+
console.error('Video or canvas element is not ready');
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const detection = await faceapi
|
|
99
|
+
.detectSingleFace(videoRef.current, new faceapi.TinyFaceDetectorOptions())
|
|
100
|
+
.withFaceLandmarks();
|
|
101
|
+
if (detection) {
|
|
102
|
+
const resizedDetection = faceapi.resizeResults(detection, displaySize);
|
|
103
|
+
const frame_height = resizedDetection.detection.box.height;
|
|
104
|
+
const frame_width = resizedDetection.detection.box.width;
|
|
105
|
+
const frame_x = resizedDetection.detection.box.x;
|
|
106
|
+
const frame_y = resizedDetection.detection.box.y;
|
|
107
|
+
const faceCenterX = frame_x + frame_width / 2;
|
|
108
|
+
const faceCenterY = frame_y + frame_height / 2;
|
|
109
|
+
const screenCenterX = displaySize.width / 2;
|
|
110
|
+
const screenCenterY = displaySize.height / 2;
|
|
111
|
+
const centerThresholdX = displaySize.width * 0.15;
|
|
112
|
+
const centerThresholdY = displaySize.height * 0.15;
|
|
113
|
+
const isFaceCentered = Math.abs(faceCenterX - screenCenterX) <= centerThresholdX &&
|
|
114
|
+
Math.abs(faceCenterY - screenCenterY) <= centerThresholdY;
|
|
115
|
+
setIsFaceCentered(isFaceCentered);
|
|
116
|
+
const faceDetectionConfidence = detection.detection.score * 100;
|
|
117
|
+
// const context = faceCanvasRef.current.getContext('2d');
|
|
118
|
+
// if (context) {
|
|
119
|
+
// context.clearRect(
|
|
120
|
+
// 0,
|
|
121
|
+
// 0,
|
|
122
|
+
// faceCanvasRef.current.width,
|
|
123
|
+
// faceCanvasRef.current.height,
|
|
124
|
+
// );
|
|
125
|
+
// faceapi.draw.drawDetections(
|
|
126
|
+
// faceCanvasRef.current,
|
|
127
|
+
// resizedDetection,
|
|
128
|
+
// );
|
|
129
|
+
// faceapi.draw.drawFaceLandmarks(
|
|
130
|
+
// faceCanvasRef.current,
|
|
131
|
+
// resizedDetection,
|
|
132
|
+
// );
|
|
133
|
+
// }
|
|
134
|
+
//adjust the faceDetectionConfidence if need
|
|
135
|
+
if (isFaceCentered && faceDetectionConfidence >= 65) {
|
|
136
|
+
if (!countdownInterval) {
|
|
137
|
+
setIsCapturing(true);
|
|
138
|
+
countdownInterval = setInterval(() => {
|
|
139
|
+
setCountdown((prev) => {
|
|
140
|
+
if (prev === 1) {
|
|
141
|
+
clearInterval(countdownInterval);
|
|
142
|
+
countdownInterval = null;
|
|
143
|
+
captureImage();
|
|
144
|
+
return 3;
|
|
145
|
+
}
|
|
146
|
+
return prev - 1;
|
|
147
|
+
});
|
|
148
|
+
}, 1000);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
if (countdownInterval) {
|
|
153
|
+
clearInterval(countdownInterval);
|
|
154
|
+
countdownInterval = null;
|
|
155
|
+
setCountdown(3);
|
|
156
|
+
setIsCapturing(false);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
console.error('Error during face detection:', error);
|
|
163
|
+
setCameraError('An error occurred while detecting your face. Please try again.');
|
|
164
|
+
}
|
|
165
|
+
}, 100);
|
|
166
|
+
}
|
|
167
|
+
function stopCamera() {
|
|
168
|
+
setCaptureInProgress(false);
|
|
169
|
+
if (detectionIntervalRef.current) {
|
|
170
|
+
clearInterval(detectionIntervalRef.current);
|
|
171
|
+
detectionIntervalRef.current = null;
|
|
172
|
+
}
|
|
173
|
+
if (countdownTimerRef.current) {
|
|
174
|
+
clearInterval(countdownTimerRef.current);
|
|
175
|
+
countdownTimerRef.current = null;
|
|
176
|
+
}
|
|
177
|
+
if (videoStream) {
|
|
178
|
+
videoStream.getTracks().forEach((track) => track.stop());
|
|
179
|
+
setVideoStream(null);
|
|
180
|
+
}
|
|
181
|
+
if (videoRef.current && videoRef.current.srcObject) {
|
|
182
|
+
const stream = videoRef.current.srcObject;
|
|
183
|
+
stream.getTracks().forEach((track) => {
|
|
184
|
+
track.stop();
|
|
185
|
+
});
|
|
186
|
+
videoRef.current.srcObject = null;
|
|
187
|
+
videoRef.current.pause();
|
|
188
|
+
videoRef.current.currentTime = 0;
|
|
189
|
+
videoRef.current.load();
|
|
190
|
+
}
|
|
191
|
+
setCountdown(3);
|
|
192
|
+
}
|
|
193
|
+
function captureImage() {
|
|
194
|
+
if (videoRef.current && faceCanvasRef.current) {
|
|
195
|
+
const canvas = document.createElement('canvas');
|
|
196
|
+
canvas.width = videoRef.current.videoWidth;
|
|
197
|
+
canvas.height = videoRef.current.videoHeight;
|
|
198
|
+
const context = canvas.getContext('2d');
|
|
199
|
+
if (context) {
|
|
200
|
+
context.drawImage(videoRef.current, 0, 0, canvas.width, canvas.height);
|
|
201
|
+
const imageData = canvas.toDataURL('image/png');
|
|
202
|
+
setSelectedImage(imageData);
|
|
203
|
+
stopCamera();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function retakePhoto() {
|
|
208
|
+
setSelectedImage(null);
|
|
209
|
+
setCaptureInProgress(true);
|
|
210
|
+
setCameraError(null);
|
|
211
|
+
if (faceCanvasRef.current) {
|
|
212
|
+
const canvas = faceCanvasRef.current.querySelector('canvas');
|
|
213
|
+
if (canvas) {
|
|
214
|
+
canvas.width = canvas.width;
|
|
215
|
+
}
|
|
216
|
+
faceCanvasRef.current.innerHTML = '';
|
|
217
|
+
}
|
|
218
|
+
if (videoRef.current) {
|
|
219
|
+
videoRef.current.play();
|
|
220
|
+
}
|
|
221
|
+
startCamera();
|
|
222
|
+
}
|
|
223
|
+
async function usePhoto() {
|
|
224
|
+
if (!selectedImage) {
|
|
225
|
+
console.error('No photo selected to use');
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const blob = dataURLtoBlob(selectedImage);
|
|
229
|
+
const img = new File([blob], 'image', { type: blob.type });
|
|
230
|
+
const resizedImage = (await resizeFile(img));
|
|
231
|
+
if (resizedImage) {
|
|
232
|
+
props.setSelfieImage(resizedImage);
|
|
233
|
+
props.setCapturing(null);
|
|
234
|
+
stopCamera();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
return () => {
|
|
239
|
+
if (detectionIntervalRef.current) {
|
|
240
|
+
clearInterval(detectionIntervalRef.current);
|
|
241
|
+
}
|
|
242
|
+
if (countdownTimerRef.current) {
|
|
243
|
+
clearInterval(countdownTimerRef.current);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}, []);
|
|
247
|
+
return (_jsx(Dialog.Root, { open: props.capturing === 'SELFIE', lazyMount: true, unmountOnExit: true, closeOnEscape: false, closeOnInteractOutside: false, children: _jsxs(Portal, { children: [_jsx(Dialog.Backdrop, {}), _jsx(Dialog.Positioner, { children: _jsx(Dialog.Content, { className: twMerge('bg-bg-primary-alt mx-auto h-full w-full items-start p-3xl pb-4xl lg:h-auto lg:w-fit lg:rounded-xl', props.className), children: _jsxs("div", { className: "w-full p-4 lg:w-[640px] lg:px-12 lg:py-4xl", children: [_jsxs("button", { type: "button", className: "flex items-center gap-lg lg:absolute lg:right-5 lg:top-5 lg:p-md", onClick: () => {
|
|
248
|
+
stopCamera();
|
|
249
|
+
props.setCapturing(null);
|
|
250
|
+
}, children: [_jsx(XIcon, { className: "text-text-senary-300 hidden size-5 lg:block" }), _jsx(ArrowLeftIcon, { className: "text-text-senary-300 size-5 lg:hidden" }), _jsx("span", { className: "text-lg font-semibold lg:hidden", children: "Back" })] }), _jsx(Dialog.Title, { className: "mt-6 text-center text-lg font-semibold lg:mt-0", children: "Take a Selfie Holding Your ID" }), _jsx(Dialog.Description, { className: "text-text-tertiary-600 mx-auto mt-sm max-w-[19rem] text-center text-sm lg:max-w-full", children: "Make sure your face and ID are clearly visible, with no glare or blur." }), _jsx("div", { id: "parent", className: "border-border-disabled mt-6 aspect-video rounded-xl border bg-black lg:mt-8", children: captureInProgress ? (_jsxs("div", { className: "relative flex h-fit w-full flex-col items-center justify-center", children: [_jsx("video", { ref: videoRef, autoPlay: true, muted: true, className: "h-[60vh] w-full rounded-lg object-cover md:aspect-video md:h-[333px]", width: "100%", height: "100%" }), _jsx("canvas", { ref: faceCanvasRef, className: "absolute inset-0 h-[60vh] w-full object-cover md:aspect-video md:h-[333px] md:object-contain", width: "100%", height: "100%" }), isCapturing && (_jsx("span", { className: "absolute inset-x-0 bottom-8 flex items-center justify-center text-5xl font-bold text-[#713B12CC] md:bottom-4", children: countdown })), !isFaceCentered && (_jsx("span", { className: "absolute inset-x-0 bottom-12 mx-auto w-1/2 text-center text-xs text-white md:bottom-3", children: "Please center your face in the camera view. Make sure your ID is clearly visible next to your face." })), _jsx(PersonOverlayDesktop, { isFaceCentered: isFaceCentered, width: videoRef.current?.clientWidth || 543, height: videoRef.current?.clientHeight || 333 })] })) : (selectedImage && (_jsx("img", { src: selectedImage, alt: "Captured Photo", className: "h-full w-full rounded-lg object-cover md:aspect-video md:h-[333px]" }))) }), selectedImage && (_jsxs("div", { className: "flex flex-col items-center justify-center gap-2 md:flex-row", children: [_jsxs(Button, { className: "disabled:bg-bg-disabled disabled:text-text-disabled mx-auto mt-4 px-xl disabled:opacity-100", size: "sm", onClick: retakePhoto, type: "button", children: ["Retake Photo", _jsx(Camera01Icon, { className: "size-5" })] }), _jsxs(Button, { className: "disabled:bg-bg-disabled disabled:text-text-disabled mx-auto mt-4 px-xl disabled:opacity-100", size: "sm", onClick: usePhoto, type: "button", children: ["Use Photo", _jsx(Camera01Icon, { className: "size-5" })] })] })), !captureInProgress && (_jsxs(Button, { className: twMerge('mx-auto mt-6 px-xl lg:mt-8', selectedImage && 'hidden'), onClick: startCamera, disabled: !modelsLoaded, type: "button", children: ["Start Camera", _jsx(Camera01Icon, { className: "size-5" })] }))] }) }) })] }) }));
|
|
251
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CaptureSubject } from '../../KYC/useKYC';
|
|
2
|
+
interface FileUploadProps {
|
|
3
|
+
name: string;
|
|
4
|
+
value: File | null;
|
|
5
|
+
hasDescription?: boolean;
|
|
6
|
+
onChange?: (id: File) => void;
|
|
7
|
+
captureObject: CaptureSubject;
|
|
8
|
+
}
|
|
9
|
+
declare function ImageUploader({ value, name, hasDescription, onChange, captureObject, }: FileUploadProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export default ImageUploader;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import Image from 'next/image';
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { UploadCloud02Icon } from '../../../icons/UploadCloud02Icon.js';
|
|
6
|
+
import { Button } from '../../../ui/Button/index.js';
|
|
7
|
+
import { validateFile } from '../../KYC/utils.js';
|
|
8
|
+
import { useSignUpKYCPropsContext } from './SignUpKYCContext.js';
|
|
9
|
+
function ImageUploader({ value, name, hasDescription = true, onChange, captureObject, }) {
|
|
10
|
+
const props = useSignUpKYCPropsContext();
|
|
11
|
+
const [previewUrl, setPreviewUrl] = useState(null);
|
|
12
|
+
const [error, setError] = useState(null);
|
|
13
|
+
const fileInputRef = useRef(null);
|
|
14
|
+
const handleFileChange = (event) => {
|
|
15
|
+
const file = event.target.files?.[0];
|
|
16
|
+
if (!file) {
|
|
17
|
+
setError('No file selected');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const validationError = validateFile(file);
|
|
21
|
+
if (validationError) {
|
|
22
|
+
setError(validationError);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
setError(null);
|
|
26
|
+
const url = URL.createObjectURL(file);
|
|
27
|
+
setPreviewUrl(url);
|
|
28
|
+
onChange?.(file);
|
|
29
|
+
return () => URL.revokeObjectURL(url);
|
|
30
|
+
};
|
|
31
|
+
const handleUploadClick = () => {
|
|
32
|
+
fileInputRef.current?.click();
|
|
33
|
+
};
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (value) {
|
|
36
|
+
setPreviewUrl(URL.createObjectURL(value));
|
|
37
|
+
}
|
|
38
|
+
}, [value]);
|
|
39
|
+
return (_jsxs("div", { className: "border-border-primary bg-bg-primary flex min-h-[11.25rem] flex-col items-center justify-center gap-lg rounded-xl border px-3xl py-xl", children: [error && (_jsx("p", { className: "text-text-error-600 mb-2 text-center text-sm", children: error })), previewUrl ? (_jsxs("div", { className: "flex w-full flex-col items-center", children: [_jsx("div", { className: "relative h-[9.25rem] w-full overflow-hidden rounded-md", children: _jsx(Image, { src: previewUrl, alt: "Uploaded image preview", fill: true, className: "object-contain", draggable: false, priority: true }) }), _jsx(Button, { size: "xs", variant: "outline", className: "mt-4 w-fit", type: "button", onClick: handleUploadClick, children: "Reupload" })] })) : (hasDescription && (_jsxs(_Fragment, { children: [_jsx("div", { className: "border-border-primary shadow-xs flex size-8 items-center justify-center rounded-sm border", children: _jsx(UploadCloud02Icon, { className: "text-text-quinary size-4" }) }), _jsxs("p", { className: "text-text-tertiary-600 text-center text-sm", children: [_jsx("span", { className: "text-button-secondary-fg cursor-pointer font-semibold hover:underline", onClick: handleUploadClick, children: "Click to upload" }), ' ', "or drag and drop", _jsx("br", {}), "PNG, JPG, or JPEG (max. 10MB)"] })] }))), _jsx("input", { type: "file", id: `file-upload-${name}`, name: name, ref: fileInputRef, onChange: handleFileChange, accept: "image/png,image/jpg,image/jpeg", className: "hidden", "aria-label": "Upload image file" }), _jsx(Button, { size: "xs", variant: "outline", className: "mt-4 w-fit", onClick: () => props.setCapturing(captureObject), type: "button", children: value ? 'Retake Photo' : 'Take a Photo' })] }));
|
|
40
|
+
}
|
|
41
|
+
export default ImageUploader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function SignUpFormKYC(): import("react/jsx-runtime").JSX.Element;
|