33import Image from 'next/image' ;
44import Link from 'next/link' ;
55import { useParams , usePathname } from 'next/navigation' ;
6+ import { useQuery } from '@tanstack/react-query' ;
67import { Icon , Text } from 'opub-ui' ;
78
9+ import { GraphQL } from '@/lib/api' ;
810import { cn } from '@/lib/utils' ;
911import BreadCrumbs from '@/components/BreadCrumbs' ;
1012import { Icons } from '@/components/icons' ;
1113import { DashboardHeader } from '../components/dashboard-header' ;
14+ import LoadingPage from '../loading' ;
1215import styles from './../components/styles.module.scss' ;
16+ import { allDataSpacesListingDoc , allOrganizationsListingDoc } from './schema' ;
1317
1418const Page = ( ) => {
1519 const pathname = usePathname ( ) ;
1620
17- const params = useParams ( ) ;
21+ const params = useParams < { entityType : string } > ( ) ;
1822
19- const dataspacesList = [
20- {
21- name : 'Open Budgets India' ,
22- slug : 'open-budgets-india' ,
23- } ,
24- ] ;
23+ const allOrganizationsList : {
24+ data : any ;
25+ isLoading : boolean ;
26+ error : any ;
27+ isError : boolean ;
28+ } = useQuery ( [ `all_organizations_list_page` ] , ( ) =>
29+ GraphQL (
30+ allOrganizationsListingDoc ,
31+ {
32+ // Entity Headers if present
33+ } ,
34+ {
35+ options : {
36+ skip : params . entityType !== 'organization' ,
37+ } ,
38+ }
39+ )
40+ ) ;
2541
26- const organizationsList = [
27- {
28- name : 'CBGA' ,
29- slug : 'civicdatalab' ,
30- } ,
31- {
32- name : 'Assam Finance Department' ,
33- slug : 'civicdatalab' ,
34- } ,
35- ] ;
42+ const allDataSpacesList : {
43+ data : any ;
44+ isLoading : boolean ;
45+ error : any ;
46+ isError : boolean ;
47+ } = useQuery ( [ `all_dataspaces_list_page` ] , ( ) =>
48+ GraphQL (
49+ allDataSpacesListingDoc ,
50+ {
51+ // Entity Headers if present
52+ } ,
53+ {
54+ options : {
55+ skip : params . entityType !== 'dataspace' ,
56+ } ,
57+ }
58+ )
59+ ) ;
3660
3761 return (
3862 < div className = " bg-surfaceDefault" >
@@ -57,31 +81,34 @@ const Page = () => {
5781 </ div >
5882 < div className = "m-auto flex w-11/12 flex-col" >
5983 < DashboardHeader currentPath = { pathname } />
60- < div className = { cn ( styles . Main ) } >
61- < div className = "flex flex-wrap gap-24" >
62- { [
63- ...( params . entityType === 'organization'
64- ? organizationsList
65- : dataspacesList ) ,
66- ] ?. map ( ( orgItem ) => (
67- < div
68- key = { orgItem . slug }
69- className = "flex max-w-64 flex-col items-center gap-3 rounded-2 border-2 border-solid border-baseGraySlateSolid4 px-4 py-5 text-center"
70- >
71- < Link
72- href = { `/dashboard/${ params . entityType } /${ orgItem . slug } /dataset` }
73- id = { orgItem . slug }
84+ { allDataSpacesList . isLoading || allOrganizationsList . isLoading ? (
85+ < LoadingPage />
86+ ) : (
87+ < div className = { cn ( styles . Main ) } >
88+ < div className = "flex flex-wrap gap-24" >
89+ { [
90+ ...( params . entityType === 'organization'
91+ ? allOrganizationsList . data . organisations
92+ : allDataSpacesList . data . dataspaces ) ,
93+ ] ?. map ( ( orgItem ) => (
94+ < div
95+ key = { orgItem . slug }
96+ className = "flex max-w-64 flex-col items-center gap-3 rounded-2 border-2 border-solid border-baseGraySlateSolid4 px-4 py-5 text-center"
7497 >
75- < div className = "border-var(--border-radius-5) rounded-2 " >
76- < Image
77- src = { '/obi.jpg' }
78- width = { 200 }
79- height = { 200 }
80- alt = { 'Organization Logo' }
81- />
82- </ div >
98+ < Link
99+ href = { `/dashboard/${ params . entityType } /${ orgItem . slug } /dataset` }
100+ id = { orgItem . slug }
101+ >
102+ < div className = "border-var(--border-radius-5) rounded-2 " >
103+ < Image
104+ src = { '/obi.jpg' }
105+ width = { 200 }
106+ height = { 200 }
107+ alt = { 'Organization Logo' }
108+ />
109+ </ div >
83110
84- { /* <LinkButton
111+ { /* <LinkButton
85112 href={`/dashboard/organization/${orgItem.slug}/dataset` }
86113 >
87114 Manage Datasets
@@ -91,20 +118,21 @@ const Page = () => {
91118 >
92119 Manage Consumers
93120 </LinkButton> */ }
94- </ Link >
95- < div >
96- < Text variant = "headingMd" > { orgItem . name } </ Text >
121+ </ Link >
122+ < div >
123+ < Text variant = "headingMd" > { orgItem . name } </ Text >
124+ </ div >
97125 </ div >
126+ ) ) }
127+ < div className = "flex h-72 w-56 flex-col items-center justify-center gap-3 rounded-2 bg-baseGraySlateSolid6 p-4" >
128+ < Icon source = { Icons . plus } size = { 40 } color = "success" />
129+ < Text alignment = "center" variant = "headingMd" >
130+ { `Add New ${ params . entityType === 'organization' ? 'Organization' : 'Data Space' } ` }
131+ </ Text >
98132 </ div >
99- ) ) }
100- < div className = "flex h-72 w-56 flex-col items-center justify-center gap-3 rounded-2 bg-baseGraySlateSolid6 p-4" >
101- < Icon source = { Icons . plus } size = { 40 } color = "success" />
102- < Text alignment = "center" variant = "headingMd" >
103- { `Add New ${ params . entityType === 'organization' ? 'Organization' : 'Data Space' } ` }
104- </ Text >
105133 </ div >
106134 </ div >
107- </ div >
135+ ) }
108136 </ div >
109137 </ div >
110138 ) ;
0 commit comments