diff --git a/components/Navbar.js b/components/Navbar.js index 3f9c20a..bd0c9b3 100644 --- a/components/Navbar.js +++ b/components/Navbar.js @@ -19,7 +19,7 @@ import { SearchRounded, SearchTwoTone } from '@mui/icons-material'; const pages = [ {name: 'Concepts', link: '/search'}, {name: 'Domains', link: '/domains'}, - {name: 'Institutions', link: '/institutions'}, + {name: 'Institutions', link: '/orgs/institutions'}, {name: 'Announcements', link: '/announcements'}, {name: 'Resources', link: '/resources'}, ]; diff --git a/pages/api/organizations.js b/pages/api/organizations.js new file mode 100644 index 0000000..4964623 --- /dev/null +++ b/pages/api/organizations.js @@ -0,0 +1,22 @@ + +import useSWR from "swr"; +import { API_BASE_URL } from '../index'; + +export const getOrganizations = () => { + const fetcher = (url) => fetch(url).then((res) => res.json()); + + const { + data, + isLoading, + isError, + mutate, + } = useSWR( + `${API_BASE_URL}/orgs?limit=1000&verbose=false&includeRetired=false`, + fetcher, + { revalidateOnFocus: false, revalidateOnReconnect: false } + ); + + return { + data, isLoading, isError, mutate + } +} \ No newline at end of file diff --git a/pages/orgs/[org]/index.js b/pages/orgs/[org]/index.js index 8ba6aff..0be62b4 100644 --- a/pages/orgs/[org]/index.js +++ b/pages/orgs/[org]/index.js @@ -1,9 +1,68 @@ -import React from 'react' +import React from "react"; +import { Box, TextField, Button, Skeleton, Stack, Alert, AlertTitle } from "@mui/material"; +import Head from "next/head"; +import { useRouter } from "next/router"; +import { DataGrid, GridColDef, GridValueGetterParams } from "@mui/x-data-grid"; +import { getOrganizations } from "@/pages/api/organizations"; -function OrgDetails() { - return ( -
OrgDetails
- ) +function InstitutionsList() { + const router = useRouter(); + const { data, isLoading, isError, mutate } = getOrganizations(); + const columns = [ + "id", + "name", + "type", + "url", + ]; + + if (isLoading) { + return ( + + + + + ); + } + + if (isError) { + return ( + + + Error + Error fetching data, please retry. + + + ); + } + + return ( + <> + + MOH KNHTS | Organizations + + + + + + + row.id} + columns={columns.map((key) => { + return { + field: key.toLowerCase(), + headerName: key.charAt(0).toUpperCase() + key.slice(1), + width: 200, + }; + })} + initialState={{ + pagination: { paginationModel: { pageSize: 25 } }, + }} + pageSizeOptions={[25, 50, 100, 250]} + /> + + + ); } -export default OrgDetails \ No newline at end of file +export default InstitutionsList;