forked from openmrs/openmrs-esm-stock-management
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat):refresh feature with mutate in stock tables (openmrs#75)
* code cleanup * Added delete User role feature * refresh feature with mutate in stock Sources * refresh feature with mutate in user role scope
- Loading branch information
Showing
15 changed files
with
184 additions
and
23 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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { mutate } from "swr"; | ||
|
||
export const handleMutate = (url: string) => { | ||
mutate((key) => typeof key === "string" && key.startsWith(url), undefined, { | ||
revalidate: true, | ||
}); | ||
}; |
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
47 changes: 47 additions & 0 deletions
47
src/stock-user-role-scopes/delete-stock-user-scope-modal.component.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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { Button, ModalHeader, ModalBody, ModalFooter } from "@carbon/react"; | ||
import styles from "../root.scss"; | ||
|
||
interface DeleteConfirmationProps { | ||
uuid?: string; | ||
close: () => void; | ||
onConfirmation: () => void; | ||
} | ||
|
||
const DeleteConfirmation: React.FC<DeleteConfirmationProps> = ({ | ||
close, | ||
onConfirmation, | ||
uuid, | ||
}) => { | ||
const { t } = useTranslation(); | ||
const handleCancel = () => close(); | ||
const handleDelete = () => onConfirmation?.(); | ||
|
||
return ( | ||
<> | ||
<ModalHeader closeModal={close} className={styles.productiveHeading03}> | ||
{t("deleteStockUserScope", "Delete Stock User Scope")}? | ||
</ModalHeader> | ||
<ModalBody> | ||
<p className={styles.bodyLong01}> | ||
{t( | ||
"deleteConfirmationText", | ||
`Are you sure you want to delete this User Scope? This action can't be undone.`, | ||
{ encounter: uuid } | ||
)} | ||
</p> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button size="lg" kind="secondary" onClick={handleCancel}> | ||
{t("cancel", "Cancel")} | ||
</Button> | ||
<Button autoFocus kind="danger" onClick={handleDelete} size="lg"> | ||
{t("delete", "Delete")} | ||
</Button> | ||
</ModalFooter> | ||
</> | ||
); | ||
}; | ||
|
||
export default DeleteConfirmation; |
73 changes: 73 additions & 0 deletions
73
src/stock-user-role-scopes/delete-stock-user-scope/delete-stock-user-scope.component.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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { useState } from "react"; | ||
import { Button, InlineLoading } from "@carbon/react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { TrashCan } from "@carbon/react/icons"; | ||
import { deleteUserRoleScopes } from "../stock-user-role-scopes.resource"; | ||
import { showModal, showNotification, showToast } from "@openmrs/esm-framework"; | ||
import { handleMutate } from "../swr-revalidation"; | ||
|
||
interface StockUserScopDeleteActionMenuProps { | ||
uuid: string; | ||
} | ||
|
||
const StockUserScopeDeleteActionMenu: React.FC< | ||
StockUserScopDeleteActionMenuProps | ||
> = ({ uuid }) => { | ||
const { t } = useTranslation(); | ||
|
||
const [deletingUserScope, setDeletingUserScope] = useState(false); | ||
|
||
const handleDeleteStockUserScope = React.useCallback(() => { | ||
const close = showModal("delete-stock-user-scope-modal", { | ||
close: () => close(), | ||
uuid: uuid, | ||
onConfirmation: () => { | ||
const ids = []; | ||
ids.push(uuid); | ||
deleteUserRoleScopes(ids) | ||
.then( | ||
() => { | ||
handleMutate("ws/rest/v1/stockmanagement/userrolescope"); | ||
setDeletingUserScope(false); | ||
showToast({ | ||
critical: true, | ||
title: t("deletingstockUserScope", "Delete Stock User Scope"), | ||
kind: "success", | ||
description: t( | ||
"stockuserscopedeletedsuccessfully", | ||
"Stock User Scope Deleted Successfully" | ||
), | ||
}); | ||
}, | ||
(error) => { | ||
setDeletingUserScope(false); | ||
showNotification({ | ||
title: t( | ||
`errorDeletingUserScope', 'error deleting a user scope` | ||
), | ||
kind: "error", | ||
critical: true, | ||
description: error?.message, | ||
}); | ||
} | ||
) | ||
.catch(); | ||
close(); | ||
}, | ||
}); | ||
}, [t, uuid]); | ||
|
||
const deleteButton = ( | ||
<Button | ||
kind="ghost" | ||
size="md" | ||
onClick={handleDeleteStockUserScope} | ||
iconDescription={t("deleteUserScope", "Delete Stock User Scope")} | ||
renderIcon={(props) => <TrashCan size={16} {...props} />} | ||
/> | ||
); | ||
|
||
return deletingUserScope ? <InlineLoading /> : deleteButton; | ||
}; | ||
|
||
export default StockUserScopeDeleteActionMenu; |
Empty file.
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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { mutate } from "swr"; | ||
|
||
export const handleMutate = (url: string) => { | ||
mutate((key) => typeof key === "string" && key.startsWith(url), undefined, { | ||
revalidate: true, | ||
}); | ||
}; |