diff --git a/packages/esm-admin-app/src/components/users/manage-users/user-management.workspace.tsx b/packages/esm-admin-app/src/components/users/manage-users/user-management.workspace.tsx index 53b58f84..43a010b7 100644 --- a/packages/esm-admin-app/src/components/users/manage-users/user-management.workspace.tsx +++ b/packages/esm-admin-app/src/components/users/manage-users/user-management.workspace.tsx @@ -174,6 +174,7 @@ const ManageUserWorkspace: React.FC = ({ const setProvider = data.providerIdentifiers; const facility = data.primaryFacility.split(' '); const mflCode = facility[facility.length - 1]; + const providerUUID = provider[0].uuid; const providerPayload: Partial = { attributes: [ { @@ -222,7 +223,13 @@ const ManageUserWorkspace: React.FC = ({ }; try { - const response = await createUser(payload, setProvider, providerPayload, initialUserValue?.uuid ?? ''); + const response = await createUser( + payload, + setProvider, + providerPayload, + initialUserValue?.uuid ?? '', + providerUUID ?? '', + ); if (response.ok) { showSnackbar({ diff --git a/packages/esm-admin-app/src/user-management.resources.ts b/packages/esm-admin-app/src/user-management.resources.ts index 8ecd9a4e..fbe11839 100644 --- a/packages/esm-admin-app/src/user-management.resources.ts +++ b/packages/esm-admin-app/src/user-management.resources.ts @@ -26,8 +26,12 @@ export const postUser = async (user: Partial, url: string) => { return response.json(); }; -export const createProvider = async (uuid: string, identifier: string, attributes: Partial) => { - const providerUrl = `${restBaseUrl}/provider`; +export const createProvider = async ( + uuid: string, + identifier: string, + attributes: Partial, + providerUrl?: string, +) => { const providerBody = { person: uuid, identifier: identifier, @@ -49,6 +53,7 @@ export const createUser = async ( setProvider: boolean, attributes: Partial, uuid?: string, + providerUUID?: string, ) => { const url = uuid ? `${restBaseUrl}/user/${uuid}` : `${restBaseUrl}/user`; @@ -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;