@@ -40,6 +40,14 @@ interface StepProps {
40
40
onPrev ?: ( ) => void ;
41
41
}
42
42
43
+ interface DigitalRight {
44
+ id : string ;
45
+ name : string ;
46
+ description : string ;
47
+ githubUrl : string | null ;
48
+ hash : string | null ;
49
+ }
50
+
43
51
// Step 1: File Selection Component
44
52
function FileSelectionStep ( { isActive, onNext } : StepProps ) {
45
53
const [ schemaFile , setSchemaFile ] = useState < File | null > ( null )
@@ -139,32 +147,49 @@ function FileSelectionStep({ isActive, onNext }: StepProps) {
139
147
// Step 2: Digital Rights Assignment
140
148
function DigitalRightsStep ( { isActive, onNext, onPrev } : StepProps ) {
141
149
const [ selectedRights , setSelectedRights ] = useState < string [ ] > ( [ ] )
150
+ const [ digitalRights , setDigitalRights ] = useState < DigitalRight [ ] > ( [ ] )
151
+ const [ isLoading , setIsLoading ] = useState ( true )
152
+ const [ error , setError ] = useState < string | null > ( null )
142
153
143
- if ( ! isActive ) return null
154
+ useEffect ( ( ) => {
155
+ const fetchDigitalRights = async ( ) => {
156
+ try {
157
+ const response = await fetch ( '/api/digital-rights' )
158
+ if ( ! response . ok ) {
159
+ throw new Error ( 'Failed to fetch digital rights' )
160
+ }
161
+ const data = await response . json ( )
162
+ setDigitalRights ( data )
163
+ } catch ( err ) {
164
+ setError ( 'Failed to load digital rights. Please try again.' )
165
+ console . error ( 'Error fetching digital rights:' , err )
166
+ } finally {
167
+ setIsLoading ( false )
168
+ }
169
+ }
144
170
145
- const dummyRights = [
146
- {
147
- id : '1' ,
148
- name : 'Append Data Pool' ,
149
- description : 'Permits adding new data entries to existing pools while maintaining schema requirements' ,
150
- github : 'https://github.com/ntls-io/trusted-compute-MVP/blob/main/sgx-mvp/json-append/src/lib.rs' ,
151
- hash : null
152
- } ,
153
- {
154
- id : '2' ,
155
- name : 'Execute Median WASM' ,
156
- description : 'Enables running Rust WebAssembly-based median calculations on data pools' ,
157
- github : 'https://github.com/ntls-io/WASM-Binaries-MVP/blob/master/bin/get_median_wasm.wasm' ,
158
- hash : '728445d425153350b3e353cc96d29c16d5d81978ea3d7bad21f3d2b2dd76d813'
159
- } ,
160
- {
161
- id : '3' ,
162
- name : 'Execute Median Python' ,
163
- description : 'Allows execution of Python-based median computations on data pools' ,
164
- github : 'https://github.com/ntls-io/Python-Scripts-MVP/blob/main/calculate_median.py' ,
165
- hash : 'bcda34f2af83a2dac745a5d86f18f4c4cd6cb4e61c76e0dec005a5fc9bc124f5'
171
+ if ( isActive ) {
172
+ fetchDigitalRights ( )
166
173
}
167
- ]
174
+ } , [ isActive ] )
175
+
176
+ if ( ! isActive ) return null
177
+
178
+ if ( isLoading ) {
179
+ return (
180
+ < div className = "flex justify-center items-center h-64" >
181
+ < div className = "animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" />
182
+ </ div >
183
+ )
184
+ }
185
+
186
+ if ( error ) {
187
+ return (
188
+ < Alert variant = "destructive" >
189
+ < AlertDescription > { error } </ AlertDescription >
190
+ </ Alert >
191
+ )
192
+ }
168
193
169
194
return (
170
195
< div className = "space-y-6" >
@@ -182,14 +207,14 @@ function DigitalRightsStep({ isActive, onNext, onPrev }: StepProps) {
182
207
</ TableRow >
183
208
</ TableHeader >
184
209
< TableBody >
185
- { dummyRights . map ( ( right ) => (
210
+ { digitalRights . map ( ( right ) => (
186
211
< TableRow key = { right . id } >
187
212
< TableCell className = "font-medium" > { right . name } </ TableCell >
188
213
< TableCell > { right . description } </ TableCell >
189
214
< TableCell >
190
- { right . github ? (
215
+ { right . githubUrl ? (
191
216
< a
192
- href = { right . github }
217
+ href = { right . githubUrl }
193
218
target = "_blank"
194
219
rel = "noopener noreferrer"
195
220
className = "text-blue-600 hover:text-blue-800 underline"
@@ -231,7 +256,11 @@ function DigitalRightsStep({ isActive, onNext, onPrev }: StepProps) {
231
256
< Button variant = "outline" onClick = { onPrev } className = { buttonOutlineClass } >
232
257
Previous
233
258
</ Button >
234
- < Button onClick = { onNext } className = { buttonBaseClass } >
259
+ < Button
260
+ onClick = { onNext }
261
+ disabled = { selectedRights . length === 0 }
262
+ className = { buttonBaseClass }
263
+ >
235
264
Next
236
265
</ Button >
237
266
</ div >
0 commit comments