-
Notifications
You must be signed in to change notification settings - Fork 24
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 #75 from sainingo/main
Fetch SP names from API
- Loading branch information
Showing
7 changed files
with
219 additions
and
151 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
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
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
43 changes: 43 additions & 0 deletions
43
packages/esm-report-app/src/reports-dashboard/tab-panel/tab.panel.resource.tsx
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,43 @@ | ||
import { openmrsFetch } from '@openmrs/esm-framework'; | ||
import useSWR from 'swr'; | ||
|
||
// Configuration | ||
const BASE_URL = '/ws/rest/v1/amrscore/reports'; | ||
|
||
const fetcher = async (url) => { | ||
try { | ||
const response = await openmrsFetch(url, {}); | ||
if (!response.ok) { | ||
throw new Error(`Failed to fetch data: ${response.statusText}`); | ||
} | ||
return response.json(); | ||
} catch (error) { | ||
throw new Error(`An error occurred while fetching data: ${error.message}`); | ||
} | ||
}; | ||
|
||
export const generateSpReport = (result) => { | ||
const { data, isLoading, error, isValidating } = useSWR(`${BASE_URL}/generate`, fetcher); | ||
|
||
const response = data ? (data as any)?.result : []; | ||
|
||
return { | ||
response, | ||
isLoading, | ||
error, | ||
isValidating, | ||
}; | ||
}; | ||
|
||
export const getSPReports = () => { | ||
const { data, isLoading, error, isValidating } = useSWR(BASE_URL, fetcher); | ||
|
||
const response = data ? (data as any)?.result : []; | ||
|
||
return { | ||
response, | ||
isLoading, | ||
error, | ||
isValidating, | ||
}; | ||
}; |
Oops, something went wrong.