Skip to content

Commit

Permalink
show notification when health id registration fails (#7114)
Browse files Browse the repository at this point in the history
  • Loading branch information
khavinshankar authored Feb 8, 2024
1 parent faeb462 commit 4fa0533
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 49 deletions.
27 changes: 14 additions & 13 deletions cypress/e2e/facility_spec/facility_manage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ describe("Facility Manage Functions", () => {
const facilityUpdatedMiddleware = "updated.coronasafe.live";
const facilityMiddlewareSuccessfullNotification =
"Facility updated successfully";
const facilityHrfidUpdateButton = "Link Health Facility";
const facilityHrfidSuccessfullNotification =
"Health Facility config updated successfully";
const facilityHrfId = uuidv4();
const facilityUpdatedHrfId = uuidv4();
const facilityHfridUpdateButton = "Link Health Facility";
const facilityHfridToastNotificationText =
/Health Facility config updated successfully|Health ID registration failed/;
const facilityHfrId = "IN180000018";
const facilityUpdatedHfrId = uuidv4();
const doctorCapacity = "5";
const doctorModifiedCapacity = "7";
const totalCapacity = "100";
Expand Down Expand Up @@ -80,28 +80,29 @@ describe("Facility Manage Functions", () => {
facilityPage.clickManageFacilityDropdown();
facilityManage.clickFacilityConfigureButton();
// verify mandatory field error message
facilityManage.clickButtonWithText(facilityHrfidUpdateButton);
facilityManage.clearHfrId();
facilityManage.clickButtonWithText(facilityHfridUpdateButton);
facilityManage.checkErrorMessageVisibility(
"Health Facility Id is required"
);
// add facility health ID and verify notification
facilityManage.typeHrfId(facilityHrfId);
facilityManage.clickButtonWithText(facilityHrfidUpdateButton);
facilityManage.typeHfrId(facilityHfrId);
facilityManage.clickButtonWithText(facilityHfridUpdateButton);
facilityManage.verifySuccessMessageVisibilityAndContent(
facilityHrfidSuccessfullNotification
facilityHfridToastNotificationText
);
// update the existing middleware
facilityPage.clickManageFacilityDropdown();
facilityManage.clickFacilityConfigureButton();
facilityManage.typeHrfId(facilityUpdatedHrfId);
facilityManage.clickButtonWithText(facilityHrfidUpdateButton);
facilityManage.typeHfrId(facilityUpdatedHfrId);
facilityManage.clickButtonWithText(facilityHfridUpdateButton);
facilityManage.verifySuccessMessageVisibilityAndContent(
facilityHrfidSuccessfullNotification
facilityHfridToastNotificationText
);
// verify its reflection
facilityPage.clickManageFacilityDropdown();
facilityManage.clickFacilityConfigureButton();
facilityManage.verifyHrfIdValue(facilityUpdatedHrfId);
facilityManage.verifyHfrIdValue(facilityUpdatedHfrId);
});

it("Modify doctor capacity in Facility detail page", () => {
Expand Down
10 changes: 7 additions & 3 deletions cypress/pageobject/Facility/FacilityManage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,23 @@ class FacilityManage {
cy.get("#middleware_address").click().clear().click().type(address);
}

typeHrfId(address) {
clearHfrId() {
cy.get("#hf_id").click().clear();
}

typeHfrId(address) {
cy.get("#hf_id").click().clear().click().type(address);
}

verifySuccessMessageVisibilityAndContent(text) {
cy.get(".pnotify-text").should("be.visible").and("contain", text);
cy.get(".pnotify-text").should("be.visible").contains(text);
}

verifyMiddlewareAddressValue(expectedValue) {
cy.get("#middleware_address").should("have.value", expectedValue);
}

verifyHrfIdValue(expectedValue) {
verifyHfrIdValue(expectedValue) {
cy.get("#hf_id").should("have.value", expectedValue);
}

Expand Down
49 changes: 16 additions & 33 deletions src/Components/ABDM/ConfigureHealthFacility.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,53 +75,31 @@ export const ConfigureHealthFacility = (props: any) => {

let response = null;
let responseData = null;
if (state.form.health_facility) {
if (state.form.hf_id === state.form.health_facility?.hf_id) {
const { res, data } = await request(
routes.abha.partialUpdateHealthFacility,
routes.abha.registerHealthFacilityAsService,
{
pathParams: {
facility_id: facilityId,
},
body: {
hf_id: state.form.hf_id,
},
}
);
response = res;
responseData = data;
} else if (state.form.hf_id === state.form.health_facility?.hf_id) {
} else if (state.form.health_facility) {
const { res, data } = await request(
routes.abha.registerHealthFacilityAsService,
routes.abha.partialUpdateHealthFacility,
{
pathParams: {
facility_id: facilityId,
},
body: {
hf_id: state.form.hf_id,
},
}
);
response = res;
responseData = data;

if (response?.status === 200 && responseData) {
if (responseData?.registered) {
dispatch({
type: "set_form",
form: {
...state.form,
health_facility: {
...state.form?.health_facility,
registered: responseData.registered,
},
},
});

return;
}
}

Notification.Error({
msg: "Service registration failed, please try again later",
});
return;
} else {
const { res, data } = await request(routes.abha.createHealthFacility, {
body: {
Expand All @@ -133,17 +111,22 @@ export const ConfigureHealthFacility = (props: any) => {
responseData = data;
}

setIsLoading(false);
if (response && responseData) {
if (response?.ok && responseData?.registered) {
Notification.Success({
msg: "Health Facility config updated successfully",
});
navigate(`/facility/${facilityId}`);
} else {
if (responseData)
if (responseData?.registered === false) {
Notification.Warn({
msg: responseData?.detail || "Health ID registration failed",
});
navigate(`/facility/${facilityId}`);
} else {
Notification.Error({
msg: "Something went wrong: " + (responseData.detail || ""),
msg: responseData?.detail || "Health Facility config update failed",
});
}
}
setIsLoading(false);
};
Expand Down

0 comments on commit 4fa0533

Please sign in to comment.