1- import React , { useState } from "react" ;
1+ import React , { useState } from 'react' ;
2+ import ViewExternalDocumentsModal from '../pages/viewExternalDocuments' ;
23
34const DocumentSelector = ( { item } ) => {
4- const [ isDropdownOpen , setIsDropdownOpen ] = useState ( false ) ;
5+ const [ isDropdownOpen , setIsDropdownOpen ] = useState ( false ) ;
56
6- const toggleDropdown = ( ) => {
7- setIsDropdownOpen ( ! isDropdownOpen ) ;
8- } ;
9- const handleDocumentOnClick = ( urls : string ) => {
10- const url = `#/view-external-document?fileUrl=${ encodeURIComponent ( urls ) } &backUrl=${ encodeURIComponent ( "/" ) } &title=${ encodeURIComponent ( "Documents Preview" ) } ` ;
11- window . open ( url , "_blank" ) ;
12- } ;
13- return (
14- < div className = "relative inline-block" >
15- < button
16- className = "bg-blue-500 text-white py-2 px-4 rounded-lg font-semibold hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500"
17- onClick = { toggleDropdown }
18- >
19- Select Attachment
20- </ button >
7+ const toggleDropdown = ( ) => {
8+ setIsDropdownOpen ( ! isDropdownOpen ) ;
9+ } ;
10+ const handleDocumentOnClick = ( urls : string ) => {
11+ const url = `#/view-external-document?fileUrl=${ encodeURIComponent (
12+ urls
13+ ) } &backUrl=${ encodeURIComponent ( '/' ) } &title=${ encodeURIComponent (
14+ 'Documents Preview'
15+ ) } `;
16+ window . open ( url , '_blank' ) ;
17+ } ;
18+ const [ show , setShow ] = useState ( false ) ;
19+ const [ fileUrl , setFileUrl ] = useState ( '' ) ;
20+ const viewExternalDocumentsModal = ( url : any ) => {
21+ setFileUrl ( url ) ;
22+ setShow ( true ) ;
23+ } ;
24+ const onClose = ( ) => {
25+ setShow ( false ) ;
26+ } ;
27+ return (
28+ < div className = "relative inline-block" >
29+ < button
30+ className = "bg-blue-500 text-white py-2 px-4 rounded-lg font-semibold hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500"
31+ onClick = { toggleDropdown }
32+ >
33+ Select Attachment
34+ </ button >
2135
22- { isDropdownOpen && (
23- < ul className = "dark:text-white dark:bg-dark-tertiary absolute mt-2 border border-gray-300 rounded-lg shadow-lg w-48 z-50" >
24- { item ?. idDocumentUrl && (
25- < li >
26- < button
27- className = "w-full text-left px-4 py-2 text-white hover:bg-gray-100 hover:text-blue-500 focus:outline-none"
28- onClick = { ( ) => {
29- handleDocumentOnClick ( item . idDocumentUrl ) ;
30- setIsDropdownOpen ( false ) ;
31- } }
32- >
33- ID Card
34- </ button >
35- </ li >
36- ) }
37- { item ?. resumeUrl && (
38- < li >
39- < button
40- className = "w-full text-left px-4 py-2 text-white hover:bg-gray-100 hover:text-blue-500 focus:outline-none"
41- onClick = { ( ) => {
42- handleDocumentOnClick ( item . resumeUrl ) ;
43- setIsDropdownOpen ( false ) ;
44- } }
45- >
46- Resume
47- </ button >
48- </ li >
49- ) }
50- { item ?. coverLetterUrl && (
51- < li >
52- < button
53- className = "w-full text-left px-4 py-2 text-white hover:bg-gray-100 hover:text-blue-500 focus:outline-none"
54- onClick = { ( ) => {
55- handleDocumentOnClick ( item . coverLetterUrl ) ;
56- setIsDropdownOpen ( false ) ;
57- } }
58- >
59- Cover Letter
60- </ button >
61- </ li >
62- ) }
63- </ ul >
64- ) }
65- </ div >
66- ) ;
36+ { isDropdownOpen && (
37+ < ul className = "dark:text-white dark:bg-dark-tertiary absolute mt-2 border border-gray-300 rounded-lg shadow-lg w-48 z-50" >
38+ { item ?. idDocumentUrl && (
39+ < li >
40+ < button
41+ className = "w-full text-left px-4 py-2 text-white hover:bg-gray-100 hover:text-blue-500 focus:outline-none"
42+ onClick = { ( ) => {
43+ viewExternalDocumentsModal ( item . idDocumentUrl ) ;
44+ setIsDropdownOpen ( false ) ;
45+ } }
46+ >
47+ ID Card
48+ </ button >
49+ </ li >
50+ ) }
51+ { item ?. resumeUrl && (
52+ < li >
53+ < button
54+ className = "w-full text-left px-4 py-2 text-white hover:bg-gray-100 hover:text-blue-500 focus:outline-none"
55+ onClick = { ( ) => {
56+ viewExternalDocumentsModal ( item . resumeUrl ) ;
57+ setIsDropdownOpen ( false ) ;
58+ } }
59+ >
60+ Resume
61+ </ button >
62+ </ li >
63+ ) }
64+ { item ?. coverLetterUrl && (
65+ < li >
66+ < button
67+ className = "w-full text-left px-4 py-2 text-white hover:bg-gray-100 hover:text-blue-500 focus:outline-none"
68+ onClick = { ( ) => {
69+ viewExternalDocumentsModal ( item . coverLetterUrl ) ;
70+ setIsDropdownOpen ( false ) ;
71+ } }
72+ >
73+ Cover Letter
74+ </ button >
75+ </ li >
76+ ) }
77+ </ ul >
78+ ) }
79+ < ViewExternalDocumentsModal
80+ show = { show }
81+ onClose = { onClose }
82+ fileUrl = { fileUrl }
83+ />
84+ </ div >
85+ ) ;
6786} ;
6887
69- export default DocumentSelector ;
88+ export default DocumentSelector ;
0 commit comments