@@ -4,11 +4,11 @@ import { FaShare } from 'react-icons/fa';
4
4
import { useTranslation } from 'react-i18next' ;
5
5
import { useApi } from '../../api' ;
6
6
import { CredentialImage } from '../Credentials/CredentialImage' ;
7
-
7
+ import CredentialInfo from '../Credentials/CredentialInfo' ;
8
8
9
9
function SelectCredentials ( { showPopup, setShowPopup, setSelectionMap, conformantCredentialsMap, verifierDomainName } ) {
10
10
const api = useApi ( ) ;
11
- const [ images , setImages ] = useState ( [ ] ) ;
11
+ const [ vcEntities , setVcEntities ] = useState ( [ ] ) ;
12
12
const navigate = useNavigate ( ) ;
13
13
const { t } = useTranslation ( ) ;
14
14
@@ -17,8 +17,7 @@ function SelectCredentials({ showPopup, setShowPopup, setSelectionMap, conforman
17
17
const [ currentSelectionMap , setCurrentSelectionMap ] = useState ( { } ) ;
18
18
const [ requestedFields , setRequestedFields ] = useState ( [ ] ) ;
19
19
const [ showRequestedFields , setShowRequestedFields ] = useState ( false ) ;
20
- const [ renderContent , setRenderContent ] = useState ( showRequestedFields ) ;
21
- const [ applyTransition , setApplyTransition ] = useState ( false ) ;
20
+ const [ credentialDisplay , setCredentialDisplay ] = useState ( { } ) ;
22
21
23
22
useEffect ( ( ) => {
24
23
const getData = async ( ) => {
@@ -30,13 +29,13 @@ function SelectCredentials({ showPopup, setShowPopup, setSelectionMap, conforman
30
29
31
30
try {
32
31
const response = await api . get ( '/storage/vc' ) ;
33
- const simplifiedCredentials = response . data . vc_list
32
+ const vcEntities = response . data . vc_list
34
33
. filter ( vcEntity =>
35
34
conformantCredentialsMap [ keys [ currentIndex ] ] . credentials . includes ( vcEntity . credentialIdentifier )
36
35
) ;
37
36
38
37
setRequestedFields ( conformantCredentialsMap [ keys [ currentIndex ] ] . requestedFields ) ;
39
- setImages ( simplifiedCredentials ) ;
38
+ setVcEntities ( vcEntities ) ;
40
39
} catch ( error ) {
41
40
console . error ( 'Failed to fetch data' , error ) ;
42
41
}
@@ -45,17 +44,6 @@ function SelectCredentials({ showPopup, setShowPopup, setSelectionMap, conforman
45
44
getData ( ) ;
46
45
} , [ api , currentIndex ] ) ;
47
46
48
- useEffect ( ( ) => {
49
- if ( showRequestedFields ) {
50
- setRenderContent ( true ) ;
51
- } else if ( applyTransition ) {
52
- setTimeout ( ( ) => setRenderContent ( false ) , 500 ) ;
53
- } else {
54
- setRenderContent ( false ) ;
55
- }
56
- } , [ showRequestedFields , applyTransition ] ) ;
57
-
58
-
59
47
const goToNextSelection = ( ) => {
60
48
setCurrentIndex ( ( i ) => i + 1 ) ;
61
49
}
@@ -66,12 +54,9 @@ function SelectCredentials({ showPopup, setShowPopup, setSelectionMap, conforman
66
54
currentMap [ descriptorId ] = credentialIdentifier ;
67
55
return currentMap ;
68
56
} ) ;
69
- setApplyTransition ( false ) ;
70
- setShowRequestedFields ( false ) ;
71
57
goToNextSelection ( ) ;
72
58
} ;
73
59
74
-
75
60
const handleCancel = ( ) => {
76
61
setShowPopup ( false ) ;
77
62
navigate ( '/' ) ; // Navigate to home page or any other route
@@ -81,10 +66,21 @@ function SelectCredentials({ showPopup, setShowPopup, setSelectionMap, conforman
81
66
return null ;
82
67
} ;
83
68
69
+ const toggleRequestedFields = ( ) => {
70
+ setShowRequestedFields ( ! showRequestedFields ) ;
71
+ } ;
72
+
73
+ const toggleCredentialDisplay = ( identifier ) => {
74
+ setCredentialDisplay ( prev => ( {
75
+ ...prev ,
76
+ [ identifier ] : ! prev [ identifier ]
77
+ } ) ) ;
78
+ } ;
79
+
84
80
return (
85
81
< div className = "fixed inset-0 flex items-center justify-center z-50" >
86
82
< div className = "absolute inset-0 bg-black opacity-50" > </ div >
87
- < div className = "bg-white p-4 rounded-lg shadow-lg w-full lg:max-w-[33.33%] sm:max-w-[66.67%] max-h-[90vh] z-10 relative m-4 overflow-y-auto" >
83
+ < div className = "bg-white p-4 rounded-lg shadow-md w-full lg:max-w-[33.33%] sm:max-w-[66.67%] max-h-[90vh] z-10 relative m-4 overflow-y-auto" >
88
84
< h2 className = "text-lg font-bold mb-2 text-custom-blue" >
89
85
< FaShare size = { 20 } className = "inline mr-1 mb-1" />
90
86
{ t ( 'selectCredentialPopup.title' ) }
@@ -94,47 +90,56 @@ function SelectCredentials({ showPopup, setShowPopup, setSelectionMap, conforman
94
90
{ t ( 'selectCredentialPopup.description' ) }
95
91
</ p >
96
92
{ requestedFields && (
97
-
98
-
99
- < div className = "lg:p-0 p-2 mt-4 w-full" >
93
+ < div className = "my-3 w-full" >
100
94
< div className = "mb-2 flex items-center" >
101
95
< button
102
- onClick = { ( ) => { setApplyTransition ( true ) ; setShowRequestedFields ( ! showRequestedFields ) } }
103
- className = "px-2 py-2 text-white cursor-pointer flex items-center bg-custom-blue hover:bg-custom-blue-hover font-medium rounded-lg text-sm px-4 py-2 text-center dark:bg-custom-blue-hover dark:hover:bg-custom-blue-hover"
96
+ onClick = { toggleRequestedFields }
97
+ className = "px-2 py-2 text-white cursor-pointer flex items-center bg-custom-blue hover:bg-custom-blue-hover font-medium rounded-lg text-xs px-4 py-2 text-center dark:bg-custom-blue-hover dark:hover:bg-custom-blue-hover"
104
98
>
105
99
{ showRequestedFields ? `${ t ( 'selectCredentialPopup.requestedFieldsHide' ) } ` : `${ t ( 'selectCredentialPopup.requestedFieldsShow' ) } ` }
106
100
</ button >
107
101
</ div >
108
102
109
- < hr className = "border-t border-gray-300 py-1" />
110
-
111
- < div
112
- className = { `overflow-hidden transition-height ${ showRequestedFields ? 'max-h-96' : 'max-h-0' } ` }
113
- style = { { transition : 'max-height 0.5s ease-in-out' } }
103
+ < hr className = "border-t border-gray-300" />
114
104
115
- >
116
- { renderContent && (
117
- < >
105
+ < div className = { `transition-all ease-in-out duration-1000 p-2 overflow-hidden rounded-xl shadow-md bg-gray-50 ${ showRequestedFields ? 'max-h-[500px] opacity-100' : 'max-h-0 opacity-0 m-0 p-0' } ` } >
106
+ < >
107
+ { verifierDomainName && (
118
108
< p className = 'mb-2 text-sm italic text-gray-700' > { t ( 'selectCredentialPopup.requestedFieldsinfo' ) } { verifierDomainName } </ p >
119
- < textarea
120
- readOnly
121
- value = { requestedFields . join ( '\n' ) }
122
- className = "w-full border rounded p-2 rounded-xl"
123
- rows = { Math . min ( 3 , Math . max ( 1 , requestedFields . length ) ) }
124
- > </ textarea >
125
- </ >
126
- ) }
109
+ ) }
110
+ < textarea
111
+ readOnly
112
+ value = { requestedFields . join ( '\n' ) }
113
+ className = "p-2 border rounded-lg text-sm"
114
+ style = { { width : '-webkit-fill-available' } }
115
+ rows = { Math . min ( 3 , Math . max ( 1 , requestedFields . length ) ) }
116
+ > </ textarea >
117
+ </ >
127
118
</ div >
128
119
</ div >
129
120
) }
130
121
131
- < div className = 'flex flex-wrap justify-center flex overflow-y-auto max-h-[40vh]' >
132
- { images . map ( image => (
133
- < div className = "m-3 flex justify-center" >
134
- < div className = "relative rounded-xl w-2/3 overflow-hidden transition-shadow shadow-md hover:shadow-lg cursor-pointer" >
135
- < CredentialImage key = { image . credentialIdentifier } credential = { image . credential } onClick = { ( ) => handleClick ( image . credentialIdentifier ) } className = { "w-full object-cover rounded-xl" } />
122
+ < div className = 'flex flex-wrap justify-center flex overflow-y-auto max-h-[40vh] custom-scrollbar bg-gray-50 shadow-md rounded-xl' >
123
+ { vcEntities . map ( vcEntity => (
124
+ < >
125
+ < div key = { vcEntity . credentialIdentifier } className = "m-3 flex flex-col items-center" >
126
+ < div className = "relative rounded-xl w-2/3 overflow-hidden transition-shadow shadow-md hover:shadow-xl cursor-pointer" >
127
+ < CredentialImage key = { vcEntity . credentialIdentifier } credential = { vcEntity . credential } onClick = { ( ) => handleClick ( vcEntity . credentialIdentifier ) } className = { "w-full object-cover rounded-xl" } />
128
+ </ div >
129
+ < div className = 'w-2/3 mt-2' >
130
+ < button
131
+ onClick = { ( ) => toggleCredentialDisplay ( vcEntity . credentialIdentifier ) }
132
+ className = "text-xs py-2 w-full bg-custom-blue hover:bg-custom-blue-hover text-white font-medium rounded-lg" >
133
+ { credentialDisplay [ vcEntity . credentialIdentifier ] ? 'Hide Details' : 'Show Details' }
134
+ </ button >
135
+ < div
136
+ className = { `transition-all ease-in-out duration-1000 overflow-hidden shadow-md rounded-lg ${ credentialDisplay [ vcEntity . credentialIdentifier ] ? 'max-h-[500px] opacity-100' : 'max-h-0 opacity-0' } ` }
137
+ >
138
+ < CredentialInfo credential = { vcEntity . credential } mainClassName = { "text-xs w-full" } />
139
+ </ div >
140
+ </ div >
136
141
</ div >
137
- </ div >
142
+ </ >
138
143
) ) }
139
144
</ div >
140
145
< button
0 commit comments