-
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.
(feat) Add basicAuth as config object (#8)
- Loading branch information
1 parent
47d0a9f
commit 84b8378
Showing
4 changed files
with
43 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
export const configSchema = {}; | ||
import { Type } from '@openmrs/esm-framework'; | ||
export const configSchema = { | ||
basicAuthBase64: { | ||
_type: Type.String, | ||
_description: 'Basic auth base64 string for the API call e.g Basic someBase64String==', | ||
_default: '', | ||
}, | ||
}; | ||
|
||
export type PreAppointmentsConfig = { | ||
basicAuthBase64: string; | ||
}; |
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
10 changes: 7 additions & 3 deletions
10
packages/esm-preappointment-app/src/pre-appointments/pre-appointment.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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import useSWR from 'swr'; | ||
import { type PreAppointmentsConfig } from '../config-schema'; | ||
import { useConfig } from '@openmrs/esm-framework'; | ||
|
||
// Should use openmrsFetch to fetch data from the backend | ||
// import { openmrsFetch } from '@openmrs/esm-api'; | ||
|
||
// Add the basic auth base64 string for the API call | ||
const basicAuthBase64 = 'Basic'; | ||
const fetcher = (url) => fetch(url, { headers: { Authorization: basicAuthBase64 } }).then((r) => r.json()); | ||
const fetcher = (url, basicAuthBase64) => | ||
fetch(url, { headers: { Authorization: basicAuthBase64 } }).then((r) => r.json()); | ||
|
||
export const usePreAppointments = (locationUuid: string, yearWeek: string) => { | ||
const { basicAuthBase64 } = useConfig<PreAppointmentsConfig>(); | ||
|
||
const url = `https://ngx.ampath.or.ke/etl-latest/etl/ml-weekly-predictions?locationUuids=${locationUuid}&yearWeek=${yearWeek}`; | ||
const { data, isLoading, error, isValidating } = useSWR<PreAppointment>(url, fetcher); | ||
const { data, isLoading, error, isValidating } = useSWR<PreAppointment>(url, () => fetcher(url, basicAuthBase64)); | ||
return { preappoinments: data?.result ?? [], isLoading, error, isValidating }; | ||
}; |
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