-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from moh-kenya/feat-institution-list
Add ability to add organizations
- Loading branch information
Showing
3 changed files
with
88 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div>OrgDetails</div> | ||
) | ||
function InstitutionsList() { | ||
const router = useRouter(); | ||
const { data, isLoading, isError, mutate } = getOrganizations(); | ||
const columns = [ | ||
"id", | ||
"name", | ||
"type", | ||
"url", | ||
]; | ||
|
||
if (isLoading) { | ||
return ( | ||
<Box sx={{ pt: 0.5 }}> | ||
<Skeleton /> | ||
<Skeleton width="60%" /> | ||
</Box> | ||
); | ||
} | ||
|
||
if (isError) { | ||
return ( | ||
<Stack sx={{ width: "100%" }} spacing={2}> | ||
<Alert severity="error"> | ||
<AlertTitle>Error</AlertTitle> | ||
Error fetching data, please retry. | ||
</Alert> | ||
</Stack> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>MOH KNHTS | Organizations</title> | ||
<meta name="description" content="MOH KNHTS" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
</Head> | ||
|
||
<Box my={2} sx={{ width: "100%" }}> | ||
<DataGrid | ||
rows={Object.values(data)} | ||
getRowId={(row) => 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]} | ||
/> | ||
</Box> | ||
</> | ||
); | ||
} | ||
|
||
export default OrgDetails | ||
export default InstitutionsList; |