Skip to content

Commit

Permalink
add edit provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Ogollah committed Jan 10, 2025
1 parent 6ea0719 commit 4548098
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ const ManageUserWorkspace: React.FC<ManageUserWorkspaceProps> = ({
const setProvider = data.providerIdentifiers;
const facility = data.primaryFacility.split(' ');
const mflCode = facility[facility.length - 1];
const providerUUID = provider[0].uuid;
const providerPayload: Partial<Provider> = {
attributes: [
{
Expand Down Expand Up @@ -222,7 +223,13 @@ const ManageUserWorkspace: React.FC<ManageUserWorkspaceProps> = ({
};

try {
const response = await createUser(payload, setProvider, providerPayload, initialUserValue?.uuid ?? '');
const response = await createUser(
payload,
setProvider,
providerPayload,
initialUserValue?.uuid ?? '',
providerUUID ?? '',
);

if (response.ok) {
showSnackbar({
Expand Down
12 changes: 9 additions & 3 deletions packages/esm-admin-app/src/user-management.resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ export const postUser = async (user: Partial<User>, url: string) => {
return response.json();
};

export const createProvider = async (uuid: string, identifier: string, attributes: Partial<Provider>) => {
const providerUrl = `${restBaseUrl}/provider`;
export const createProvider = async (
uuid: string,
identifier: string,
attributes: Partial<Provider>,
providerUrl?: string,
) => {
const providerBody = {
person: uuid,
identifier: identifier,
Expand All @@ -49,6 +53,7 @@ export const createUser = async (
setProvider: boolean,
attributes: Partial<Provider>,
uuid?: string,
providerUUID?: string,
) => {
const url = uuid ? `${restBaseUrl}/user/${uuid}` : `${restBaseUrl}/user`;

Expand All @@ -57,7 +62,8 @@ export const createUser = async (
if (setProvider || (response.person && response.person.uuid)) {
const personUUID = response.person.uuid;
const identifier = response.systemId;
return await createProvider(personUUID, identifier, attributes);
const providerUrl = providerUUID ? `${restBaseUrl}/provider/${providerUUID}` : `${restBaseUrl}/provider`;
return await createProvider(personUUID, identifier, attributes, providerUrl);
}

return response;
Expand Down

0 comments on commit 4548098

Please sign in to comment.