@opexa/portal-components 0.0.222 → 0.0.223

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.
@@ -89,7 +89,15 @@ export function useCamera(options = {}) {
89
89
  video.currentTime = 1;
90
90
  const videoRect = video.getBoundingClientRect();
91
91
  const lowResolution = video.videoWidth < 640 || video.videoHeight < 480;
92
- const scaleFactor = lowResolution ? (opts.scale ?? 2) : 1.25;
92
+ const hdResolution = video.videoWidth >= 1280 && video.videoHeight >= 720;
93
+ const highResolution = video.videoWidth >= 1920 && video.videoHeight >= 1080;
94
+ const scaleFactor = lowResolution
95
+ ? (opts.scale ?? 2)
96
+ : highResolution
97
+ ? 1
98
+ : hdResolution
99
+ ? 1.15
100
+ : 1.25;
93
101
  let x = 0;
94
102
  let y = 0;
95
103
  let w = video.videoWidth;
@@ -19,7 +19,7 @@ export const useClaimCashbackBonusMutation = (config) => {
19
19
  },
20
20
  });
21
21
  queryClient.setQueryData(getCashbackBonusesQueryKey(), (prev) => prev?.map((bonus) => {
22
- if (bonus.id !== id) {
22
+ if (bonus.id === id) {
23
23
  return {
24
24
  ...bonus,
25
25
  balance: '0',
@@ -24,7 +24,9 @@ import { Popover } from '../../ui/Popover/index.js';
24
24
  import { Progress } from '../../ui/Progress/index.js';
25
25
  import { SegmentGroup } from '../../ui/SegmentGroup/index.js';
26
26
  import { formatNumber } from '../../utils/formatNumber.js';
27
+ import { getQueryClient } from '../../utils/getQueryClient.js';
27
28
  import { parseDecimal } from '../../utils/parseDecimal.js';
29
+ import { getCashbackBonusesQueryKey } from '../../utils/queryKeys.js';
28
30
  import { ClaimSpotBonus } from './ClaimSpotBonus.js';
29
31
  const TabSchema = z
30
32
  .enum(['all', 'active', 'cashbacks'])
@@ -84,11 +86,15 @@ function CashbackBonus(props) {
84
86
  const bonus = props.data;
85
87
  const cashback = bonus.cashback;
86
88
  const localeInfo = useLocaleInfo();
89
+ const queryClient = getQueryClient();
87
90
  const claimCashbackBonusMutation = useClaimCashbackBonusMutation({
88
91
  onSuccess() {
89
92
  toaster.success({
90
93
  description: 'Bonus claimed successfully!',
91
94
  });
95
+ queryClient.invalidateQueries({
96
+ queryKey: getCashbackBonusesQueryKey(),
97
+ });
92
98
  },
93
99
  onError(error) {
94
100
  toaster.error({
@@ -1,5 +1,5 @@
1
1
  import { type CSSProperties, type Ref } from 'react';
2
- type ErrorCode = 'FILE_NAME_TOO_LONG' | 'FILE_SIZE_TOO_LARGE' | 'FILE_TYPE_NOT_SUPPORTED';
2
+ import { type ValidateFileError } from '../../utils/validateFile';
3
3
  export interface IdDocumentFieldProps {
4
4
  ref?: Ref<HTMLDivElement>;
5
5
  id?: string;
@@ -12,7 +12,6 @@ export interface IdDocumentFieldProps {
12
12
  readOnly?: boolean;
13
13
  disabled?: boolean;
14
14
  required?: boolean;
15
- onError?: (code: ErrorCode) => void;
15
+ onError?: (error: ValidateFileError) => void;
16
16
  }
17
17
  export declare function IdDocumentField(props: IdDocumentFieldProps): import("react/jsx-runtime").JSX.Element;
18
- export {};
@@ -22,6 +22,7 @@ import { Button } from '../../ui/Button/index.js';
22
22
  import { Dialog } from '../../ui/Dialog/index.js';
23
23
  import { Portal } from '../../ui/Portal/index.js';
24
24
  import { dataAttr } from '../../utils/dataAttr.js';
25
+ import { validateFile } from '../../utils/validateFile.js';
25
26
  export function IdDocumentField(props) {
26
27
  const field = useFieldContext();
27
28
  const [value, setValue] = useControllableState({
@@ -131,24 +132,3 @@ export function IdDocumentField(props) {
131
132
  camera.reset();
132
133
  }, children: [_jsx(RefreshCcw01Icon, { className: "size-5" }), " Retake"] })] }))] }) })] }) })] }));
133
134
  }
134
- function validateFile(file) {
135
- if (![
136
- /**/
137
- 'image/png',
138
- 'image/jpg',
139
- 'image/jpeg',
140
- ].includes(file.type)) {
141
- return 'FILE_TYPE_NOT_SUPPORTED';
142
- }
143
- if (10 < file.size / (1024 * 1024)) {
144
- return 'FILE_SIZE_TOO_LARGE';
145
- }
146
- if (48 <
147
- file.name
148
- .split('.')
149
- .filter((_, i, self) => i + 1 < self.length)
150
- .join('.').length) {
151
- return 'FILE_NAME_TOO_LONG';
152
- }
153
- return null;
154
- }
@@ -1,5 +1,5 @@
1
1
  import { type CSSProperties, type Ref } from 'react';
2
- type ErrorCode = 'FILE_NAME_TOO_LONG' | 'FILE_SIZE_TOO_LARGE' | 'FILE_TYPE_NOT_SUPPORTED';
2
+ import { type ValidateFileError } from '../../utils/validateFile';
3
3
  export interface SelfieFieldProps {
4
4
  ref?: Ref<HTMLDivElement>;
5
5
  id?: string;
@@ -12,7 +12,6 @@ export interface SelfieFieldProps {
12
12
  readOnly?: boolean;
13
13
  disabled?: boolean;
14
14
  required?: boolean;
15
- onError?: (code: ErrorCode) => void;
15
+ onError?: (error: ValidateFileError) => void;
16
16
  }
17
17
  export declare function SelfieField(props: SelfieFieldProps): import("react/jsx-runtime").JSX.Element;
18
- export {};
@@ -21,6 +21,7 @@ import { Button } from '../../ui/Button/index.js';
21
21
  import { Dialog } from '../../ui/Dialog/index.js';
22
22
  import { Portal } from '../../ui/Portal/index.js';
23
23
  import { dataAttr } from '../../utils/dataAttr.js';
24
+ import { validateFile } from '../../utils/validateFile.js';
24
25
  export function SelfieField(props) {
25
26
  const field = useFieldContext();
26
27
  const [value, setValue] = useControllableState({
@@ -125,24 +126,3 @@ export function SelfieField(props) {
125
126
  camera.reset();
126
127
  }, children: [_jsx(RefreshCcw01Icon, { className: "size-5" }), " Retake"] })] }))] }) })] }) })] }));
127
128
  }
128
- function validateFile(file) {
129
- if (![
130
- /**/
131
- 'image/png',
132
- 'image/jpg',
133
- 'image/jpeg',
134
- ].includes(file.type)) {
135
- return 'FILE_TYPE_NOT_SUPPORTED';
136
- }
137
- if (10 < file.size / (1024 * 1024)) {
138
- return 'FILE_SIZE_TOO_LARGE';
139
- }
140
- if (48 <
141
- file.name
142
- .split('.')
143
- .filter((_, i, self) => i + 1 < self.length)
144
- .join('.').length) {
145
- return 'FILE_NAME_TOO_LONG';
146
- }
147
- return null;
148
- }
@@ -0,0 +1,28 @@
1
+ export interface ValidateFileOptions {
2
+ /**
3
+ * @description Maximum file size in MB.
4
+ * @default 10
5
+ */
6
+ maxFileSize?: number;
7
+ /**
8
+ * @description Maximum file name length.
9
+ * @default 48
10
+ */
11
+ maxFileName?: number;
12
+ /**
13
+ * @description Supported mime types.
14
+ * @default
15
+ * [
16
+ * 'image/png',
17
+ * 'image/jpg',
18
+ * 'image/jpeg'
19
+ * ]
20
+ */
21
+ supportedFiles?: string[];
22
+ }
23
+ export type ValidateFileErrorName = 'FILE_NAME_TOO_LONG' | 'FILE_SIZE_TOO_LARGE' | 'FILE_TYPE_NOT_SUPPORTED';
24
+ export interface ValidateFileError {
25
+ name: ValidateFileErrorName;
26
+ message: string;
27
+ }
28
+ export declare function validateFile(file: File, options?: ValidateFileOptions): ValidateFileError | null;
@@ -0,0 +1,37 @@
1
+ export function validateFile(file, options) {
2
+ const maxFileSize = options?.maxFileSize ?? 10;
3
+ const maxFileName = options?.maxFileName ?? 48;
4
+ const supportedFiles = options?.supportedFiles ?? [
5
+ 'image/png',
6
+ 'image/jpg',
7
+ 'image/jpeg',
8
+ ];
9
+ if (!supportedFiles.includes(file.type)) {
10
+ return {
11
+ name: 'FILE_TYPE_NOT_SUPPORTED',
12
+ message: 'File type not supported.',
13
+ };
14
+ }
15
+ if (mb(file.size) > maxFileSize) {
16
+ return {
17
+ name: 'FILE_SIZE_TOO_LARGE',
18
+ message: 'File size too large.',
19
+ };
20
+ }
21
+ if (basename(file.name).length > maxFileName) {
22
+ return {
23
+ name: 'FILE_NAME_TOO_LONG',
24
+ message: 'File name is too long.',
25
+ };
26
+ }
27
+ return null;
28
+ }
29
+ function mb(bytes) {
30
+ return bytes / (1024 * 1024);
31
+ }
32
+ function basename(name) {
33
+ return name
34
+ .split('.')
35
+ .filter((_, i, self) => i + 1 < self.length)
36
+ .join('.');
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opexa/portal-components",
3
- "version": "0.0.222",
3
+ "version": "0.0.223",
4
4
  "exports": {
5
5
  "./ui/*": {
6
6
  "types": "./dist/ui/*/index.d.ts",