forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WEBREL-1132 / refactor file uploader (deriv-com#10457)
* chore: useFileUploader hook * chore: update types for file uploader * feat: 🎨 migrate File upload to TS * chore: update types and cleanup proof-of-address-form * fix: ts types and promise resolution * chore: update types, hook and test cases for poa address form * fix: update types & removed unused imports * chore: test case for useFileUploader * chore: add apiprovider in cfd * chore: update cfd-poa test case * chore: removed unused import * fix: exported required type * chore: refactored deprecated isMobile & updated test cases * fix: update file uploader to pass eslint in cfd * chore: removed unused import * chore: declare module for binary file uploader to fix failing trader build * chore: update types and fix the file selection in poa * fix: getChangeableFields when account_settings is not yet populated --------- Co-authored-by: Likhith Kolayari <likhith@regentmarkets.com>
- Loading branch information
1 parent
9ff6169
commit d99a695
Showing
21 changed files
with
422 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
declare module '@binary-com/binary-document-uploader' { | ||
import { DocumentUploadRequest } from '@deriv/api-types'; | ||
|
||
class DocumentUploader { | ||
constructor(settings: { connection: any }); | ||
upload(file: { | ||
documentType?: DocumentUploadRequest['document_type']; | ||
documentFormat?: string | Omit<string, DocumentUploadRequest['document_format']>; | ||
documentId?: DocumentUploadRequest['document_id']; | ||
expirationDate?: string; | ||
lifetimeValid?: DocumentUploadRequest['lifetime_valid']; | ||
pageType?: DocumentUploadRequest['page_type']; | ||
[key: string]: unknown; | ||
}): Promise<{ message?: string; warning?: string; [key: string]: any }>; | ||
} | ||
|
||
export default DocumentUploader; // Export the class as default | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 28 additions & 45 deletions
73
packages/account/src/Components/file-uploader-container/file-uploader-container.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,42 @@ | ||
import React from 'react'; | ||
import { Text } from '@deriv/components'; | ||
import { isMobile, WS } from '@deriv/shared'; | ||
import type { TSettings } from '@deriv/shared/src/utils/files/file-uploader-utils'; | ||
import { Localize } from '@deriv/translations'; | ||
import FileUploader from './file-uploader'; | ||
import { TFile } from '../../Types'; | ||
import { observer, useStore } from '@deriv/stores'; | ||
|
||
type TFileUploaderContainer = { | ||
getSocket?: () => WebSocket; | ||
onFileDrop: (file: TFile | undefined) => void; | ||
onRef: (ref: React.RefObject<null | { upload: () => void }> | undefined) => void; | ||
settings?: Partial<TSettings>; | ||
onFileDrop: (files: File[]) => void; | ||
files_description: React.ReactNode; | ||
examples: React.ReactNode; | ||
onError?: (error_message: string) => void; | ||
}; | ||
|
||
const FileUploaderContainer = ({ | ||
examples, | ||
files_description, | ||
getSocket, | ||
onFileDrop, | ||
onRef, | ||
settings, | ||
}: TFileUploaderContainer) => { | ||
const ref = React.useRef(null); | ||
|
||
const getSocketFunc = getSocket ?? WS.getSocket; | ||
|
||
React.useEffect(() => { | ||
if (ref) { | ||
if (typeof onRef === 'function') onRef(ref); | ||
} | ||
return () => onRef(undefined); | ||
}, [onRef, ref]); | ||
|
||
return ( | ||
<div className='file-uploader__container' data-testid='dt_file_uploader_container'> | ||
{files_description} | ||
<Text size={isMobile() ? 'xxs' : 'xs'} as='div' className='file-uploader__file-title' weight='bold'> | ||
<Localize i18n_default_text='Upload file' /> | ||
</Text> | ||
<div className='file-uploader__file-dropzone-wrapper'> | ||
<FileUploader getSocket={getSocketFunc} ref={ref} onFileDrop={onFileDrop} settings={settings} /> | ||
</div> | ||
<div className='file-uploader__file-supported-formats'> | ||
<Text size={isMobile() ? 'xxxs' : 'xxs'}> | ||
<Localize i18n_default_text='Supported formats: JPEG, JPG, PNG, PDF and GIF only' /> | ||
</Text> | ||
<Text size={isMobile() ? 'xxxs' : 'xxs'}> | ||
<Localize i18n_default_text='Maximum size: 8MB' /> | ||
const FileUploaderContainer = observer( | ||
({ examples, files_description, onFileDrop, onError }: TFileUploaderContainer) => { | ||
const { | ||
ui: { is_mobile }, | ||
} = useStore(); | ||
return ( | ||
<div className='file-uploader__container' data-testid='dt_file_uploader_container'> | ||
{files_description} | ||
<Text size={is_mobile ? 'xxs' : 'xs'} as='div' className='file-uploader__file-title' weight='bold'> | ||
<Localize i18n_default_text='Upload file' /> | ||
</Text> | ||
<div className='file-uploader__file-dropzone-wrapper'> | ||
<FileUploader onError={onError} onFileDrop={onFileDrop} /> | ||
</div> | ||
<div className='file-uploader__file-supported-formats'> | ||
<Text size={is_mobile ? 'xxxs' : 'xxs'}> | ||
<Localize i18n_default_text='Supported formats: JPEG, JPG, PNG, PDF and GIF only' /> | ||
</Text> | ||
<Text size={is_mobile ? 'xxxs' : 'xxs'}> | ||
<Localize i18n_default_text='Maximum size: 8MB' /> | ||
</Text> | ||
</div> | ||
{examples} | ||
</div> | ||
{examples} | ||
</div> | ||
); | ||
}; | ||
); | ||
} | ||
); | ||
|
||
export default FileUploaderContainer; |
Oops, something went wrong.