Skip to content

Commit

Permalink
Always redirect back to user list after user creation or edit
Browse files Browse the repository at this point in the history
  • Loading branch information
peterMuriuki committed Feb 11, 2025
1 parent 94e12e3 commit c03b2ea
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ConnectedCreateEditUser as BaseCreateEditUser,
CreateEditPropTypes,
URL_USER_CREDENTIALS,
FormFields,
PRACTITIONER_USER_TYPE_CODE,
SUPERVISOR_USER_TYPE_CODE,
Expand All @@ -25,7 +24,6 @@ import {
import React from 'react';
import { v4 } from 'uuid';
import { sendErrorNotification, sendSuccessNotification } from '@opensrp/notifications';
import { history } from '@onaio/connected-reducer-registry';
import { IPractitioner } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IPractitioner';
import { IBundle } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IBundle';
import { IGroup } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IGroup';
Expand Down Expand Up @@ -345,11 +343,6 @@ export const practitionerUpdater =
.catch(() => {
return sendErrorNotification(practitionerErrorMessage);
})
.finally(() => {
if (!isEditMode) {
history.push(`${URL_USER_CREDENTIALS}/${userId}/${values.username}`);
}
})
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,5 @@ test('renders correctly for new user', async () => {
},
]);

expect(history.location.pathname).toEqual(
'/admin/users/credentials/cab07278-c77b-4bc7-b154-bcbf01b7d35b/flopo'
);
expect(history.location.pathname).toEqual('/admin/users');
});
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ describe('forms/utils/submitForm', () => {
['Practitioner created successfully'],
['User Group edited successfully'],
]);
expect(historyPushMock).toHaveBeenCalledWith(
`/admin/users/credentials/${keycloakUserId}/janedoe`
);
expect(historyPushMock).toHaveBeenCalledWith(`/admin/users`);
});

it('ensures error notification is not thrown when creating new user', async () => {
Expand Down Expand Up @@ -213,9 +211,7 @@ describe('forms/utils/submitForm', () => {
});
// ensure that redirect only happens once
expect(historyPushMock).toHaveBeenCalledTimes(1);
expect(historyPushMock).toHaveBeenCalledWith(
`/admin/users/credentials/${keycloakUserId}/janedoe`
);
expect(historyPushMock).toHaveBeenCalledWith(`/admin/users`);
});

it('submits user edit correctly', async () => {
Expand Down Expand Up @@ -368,7 +364,7 @@ describe('forms/utils/submitForm', () => {
});

expect(notificationErrorMock).toHaveBeenCalledWith('There was a problem creating the user');
expect(historyPushMock).not.toHaveBeenCalled();
expect(historyPushMock).toHaveBeenCalledWith(`/admin/users`);
});

it('handles error when user edit fails', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { KeycloakUser, UserGroup } from '../../../ducks/user';
import {
KEYCLOAK_URL_USERS,
URL_USER,
URL_USER_CREDENTIALS,
KEYCLOAK_URL_USER_GROUPS,
PRACTITIONER,
SUPERVISOR,
Expand Down Expand Up @@ -76,10 +75,6 @@ export const createOrEditPractitioners = async (
}
})
.then(() => sendSuccessNotification(successMessage));

if (!isEditMode) {
history.push(`${URL_USER_CREDENTIALS}/${payload.userId}/${payload.username}`);
}
};

/**
Expand Down Expand Up @@ -212,9 +207,7 @@ export const submitForm = async (
}
});

if (isEditMode) {
history.push(URL_USER);
}
history.push(URL_USER);
};

// get the code of a practitioner resource type
Expand Down

0 comments on commit c03b2ea

Please sign in to comment.