diff --git a/pages/api/sources.js b/pages/api/sources.js new file mode 100644 index 0000000..b099539 --- /dev/null +++ b/pages/api/sources.js @@ -0,0 +1,22 @@ + +import useSWR from "swr"; +import { API_BASE_URL } from '../index'; + +export const getSources = () => { + const fetcher = (url) => fetch(url).then((res) => res.json()); + + const { + data, + isLoading, + isError, + mutate, + } = useSWR( + `${API_BASE_URL}/orgs/MOH-KENYA/sources?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]/sources/[source]/concepts/[concept]/index.js b/pages/orgs/[org]/sources/[source]/concepts/[concept]/index.js index 0f3b847..ec83e4b 100644 --- a/pages/orgs/[org]/sources/[source]/concepts/[concept]/index.js +++ b/pages/orgs/[org]/sources/[source]/concepts/[concept]/index.js @@ -27,7 +27,6 @@ function ConceptDetail() { isLoading, } = getConceptDetail(org, source, concept); - // console.log("---conceptDetal", conceptDetail) const conceptDetail1 = { uuid: "231999", @@ -464,7 +463,7 @@ function ConceptDetail() { {org} + + + + ); + } + + if (isError) { + return ( + + + Error + Error fetching data, please retry. + + + ); + } + + const handleSearch = (event) => { + event.preventDefault(); + mutate(); + }; + const handleClick = (params) =>{ + const rowId = params.id; + router.push(`/orgs/[orgs]/sources/${rowId}`); + } + const filteredData = Object.values(data).filter((row) => + Object.values(row).some( + (value) => + typeof value === "string" && value.toLowerCase().includes(searchTerm.toLowerCase()) + ) + ); -function SourcesList() { return ( -
SourcesList
- ) + <> + + MOH KNHTS | Organizations + + + + + + setSearchTerm(e.target.value)} + sx={{ + flexGrow: 1, + backgroundColor: "#fcfcfc", + borderRadius: "8px", + }} + id="searchTerm" + name="searchTerm" + label="Search Sources" + variant="outlined" + color={"info"} + /> + + + + row.id} + columns={columns.map((key) => { + return { + field: key.toLowerCase(), + headerName: key.charAt(0).toUpperCase() + key.slice(1), + width: 200, + }; + })} + onRowClick={handleClick} + initialState={{ + pagination: { paginationModel: { pageSize: 25 } }, + }} + pageSizeOptions={[25, 50, 100, 250]} + /> + + + ); } -export default SourcesList \ No newline at end of file +export default SourceList;