diff --git a/src/stock-sources/add-stock-sources/add-stock-sources.component.tsx b/src/stock-sources/add-stock-sources/add-stock-sources.component.tsx index 733b5d87..f991a747 100644 --- a/src/stock-sources/add-stock-sources/add-stock-sources.component.tsx +++ b/src/stock-sources/add-stock-sources/add-stock-sources.component.tsx @@ -28,7 +28,7 @@ const StockSourcesAddOrUpdate: React.FC = ({ model }) => { // get stock sources const { items } = useConceptById(STOCK_SOURCE_TYPE_CODED_CONCEPT_ID); - const [formModel, setFormModel] = useState(); + const [formModel, setFormModel] = useState({ ...model }); const onNameChanged = (evt: React.ChangeEvent): void => { model ? (model.name = evt.target.value) : ""; @@ -78,7 +78,7 @@ const StockSourcesAddOrUpdate: React.FC = ({ model }) => { ) .catch(); }, - [formModel, t] + [formModel, model, t] ); return (
diff --git a/src/stock-sources/edit-stock-source/edit-stock-source.component.tsx b/src/stock-sources/edit-stock-source/edit-stock-source.component.tsx index f3537e7b..d12784e6 100644 --- a/src/stock-sources/edit-stock-source/edit-stock-source.component.tsx +++ b/src/stock-sources/edit-stock-source/edit-stock-source.component.tsx @@ -1,32 +1,35 @@ -import { Button, Tooltip } from "@carbon/react"; +import React, { useCallback } from "react"; +import { Button } from "@carbon/react"; import { Edit } from "@carbon/react/icons"; -import { interpolateUrl, navigate } from "@openmrs/esm-framework"; -import React, { AnchorHTMLAttributes } from "react"; import { useTranslation } from "react-i18next"; +import { launchOverlay } from "../../core/components/overlay/hook"; +import StockSourcesAddOrUpdate from "../add-stock-sources/add-stock-sources.component"; +import { StockSource } from "../../core/api/types/stockOperation/StockSource"; -interface NameLinkProps extends AnchorHTMLAttributes { - to: string; - from: string; +interface EditStockSourcesActionMenuProps { + data?: StockSource; } -const EditSourceActionsMenu: React.FC = ({ from, to }) => { +const EditStockSourceActionsMenu: React.FC = ({ + data, +}) => { const { t } = useTranslation(); - const handleNameClick = (event: MouseEvent, to: string) => { - event.preventDefault(); - navigate({ to }); - localStorage.setItem("fromPage", from); - }; + const handleClick = useCallback(() => { + launchOverlay( + "Edit Stock Source", + + ); + }, [data]); + return ( - - - + - - - -
+interface StockSourcesDeleteActionMenuProps { + uuid: string; +} + +const StockSourcesDeleteActionMenu: React.FC< + StockSourcesDeleteActionMenuProps +> = ({ uuid }) => { + const { t } = useTranslation(); + + const [deletingSource, setDeletingSource] = useState(false); + + const handleClick = (e) => { + e.preventDefault(); + setDeletingSource(true); + const ids = []; + ids.push(uuid); + deleteStockSource(ids) + .then( + () => { + setDeletingSource(false); + showToast({ + critical: true, + title: t("deletingSource", "Delete Source"), + kind: "success", + description: t( + "stocksourcedeletedsuccessfully", + "Stock Source Deleted Successfully" + ), + }); + }, + (error) => { + setDeletingSource(false); + showNotification({ + title: t(`errorDeletingSource', 'error deleting a source`), + kind: "error", + critical: true, + description: error?.message, + }); + } + ) + .catch(); + }; + + const deleteButton = ( + - - ); - }); - } - const tableRows = useMemo(() => { - return items?.map((entry) => { + return items?.map((entry, index) => { return { ...entry, id: entry?.uuid, @@ -82,6 +56,12 @@ function StockSourcesItems() { name: entry?.name, acronym: entry?.acronym, sourceType: entry?.sourceType?.display, + actions: ( + <> + + + + ), }; }); }, [items]);