Skip to content

Commit

Permalink
U4X-297 : Complete and Submit for review buttons don't work (#53)
Browse files Browse the repository at this point in the history
* U4X-297 : Complete and Submit for review buttons don't work

* fix : fix onComplete

* fix : onSubmit for review
  • Loading branch information
jabahum authored Jan 8, 2024
1 parent 1159387 commit 6f470d4
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 75 deletions.
3 changes: 3 additions & 0 deletions src/stock-items/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ import { StockOperationDTO } from "../core/api/types/stockOperation/StockOperati

export type SaveStockItem = (item: StockItemDTO) => Promise<void>;
export type SaveStockOperation = (item: StockOperationDTO) => Promise<void>;
export type SaveStockOperationAction = (
item: StockOperationDTO
) => Promise<void>;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { AddStockOperationProps } from "./types";
import { useInitializeStockOperations } from "./add-stock-operation.resource";
import { AccordionSkeleton } from "@carbon/react";
import { closeOverlay } from "../../core/components/overlay/hook";
import { addOrEditStockOperation } from "../stock-operation.utils";
import {
addOrEditStockOperation,
showActionDialogButton,
} from "../stock-operation.utils";
import StockOperationApprovalButton from "../stock-operations-dialog/stock-operations-approve-button.component";
import StockOperationRejectButton from "../stock-operations-dialog/stock-operations-reject-button.component";
import StockOperationReturnButton from "../stock-operations-dialog/stock-operations-return-button.component";
Expand All @@ -18,18 +21,6 @@ import StockOperationPrintButton from "../stock-operations-dialog/stock-operatio
import StockOperationApproveDispatchButton from "../stock-operations-dialog/stock-operations-approve-dispatch-button.component";
import StockOperationCompleteDispatchButton from "../stock-operations-dialog/stock-operations-completed-dispatch-button.component";
import StockOperationIssueStockButton from "../stock-operations-dialog/stock-operations-issue-stock-button.component";
import {
OperationType,
StockOperationType,
StockOperationTypeCanCapturePurchasePrice,
StockOperationTypeIsNegativeQtyAllowed,
StockOperationTypeIsQuantityOptional,
StockOperationTypeRequiresActualBatchInformation,
StockOperationTypeRequiresBatchUuid,
StockOperationTypeRequiresDispatchAcknowledgement,
StockOperationTypeRequiresStockAdjustmentReason,
operationFromString,
} from "../../core/api/types/stockOperation/StockOperationType";

const AddStockOperation: React.FC<AddStockOperationProps> = (props) => {
const { t } = useTranslation();
Expand All @@ -44,21 +35,8 @@ const AddStockOperation: React.FC<AddStockOperationProps> = (props) => {
);
const [selectedIndex, setSelectedIndex] = useState(0);

const [stockOperationType, setStockOperationType] = useState<
StockOperationType | null | undefined
>(null);
const [isNegativeQtyAllowed, setIsNegativeQtyAllowed] = useState(false);
const [requiresBatchUuid, setRequiresBatchUuid] = useState(false);
const [requiresActualBatchInformation, setRequiresActualBatchInformation] =
useState(false);
const [isQuantityOptional, setIsQuantityOptional] = useState(false);
const [canCapturePurchasePrice, setCanCapturePurchasePrice] = useState(false);
const [requireStockAdjustmentReason, setRequireStockAdjustmentReason] =
useState(false);
const [requiresDispatchAcknowledgement, setRequiresDispatchAcknowledgement] =
useState(false);
const [allowExpiredBatchNumbers, setAllowExpiredBatchNumbers] =
useState(false);

if (isLoading) return <AccordionSkeleton />;
if (isError) {
Expand Down Expand Up @@ -130,14 +108,18 @@ const AddStockOperation: React.FC<AddStockOperationProps> = (props) => {
onGoBack: () => {
setSelectedIndex(1);
},
onComplete: () => {
// TODO: Update
onComplete: async () => {
await showActionDialogButton("Complete", false, props?.model);
},
onSubmit: () => {
// TODO: Update
onSubmit: async () => {
await showActionDialogButton("Submit", false, props?.model);
},
onDispatch: () => {
// TODO: Update
onDispatch: async () => {
await showActionDialogButton(
"Dispatch Approval",
false,
props?.model
);
},
}}
/>
Expand All @@ -146,39 +128,6 @@ const AddStockOperation: React.FC<AddStockOperationProps> = (props) => {
},
];

// const currentStockOperationType = props.operations?.find(
// (p) => p.uuid === props.operation?.uuid
// );

// console.info("data operations-->", props);

// console.info("data-->", currentStockOperationType);
// const operationType: OperationType = operationFromString(
// currentStockOperationType?.operationType ?? ""
// );

// setStockOperationType(currentStockOperationType);
// setIsNegativeQtyAllowed(
// StockOperationTypeIsNegativeQtyAllowed(operationType)
// );
// setRequiresBatchUuid(StockOperationTypeRequiresBatchUuid(operationType));
// setRequiresActualBatchInformation(
// StockOperationTypeRequiresActualBatchInformation(operationType)
// );
// setIsQuantityOptional(StockOperationTypeIsQuantityOptional(operationType));
// setCanCapturePurchasePrice(
// StockOperationTypeCanCapturePurchasePrice(operationType)
// );
// setRequireStockAdjustmentReason(
// StockOperationTypeRequiresStockAdjustmentReason(operationType)
// );
// setRequiresDispatchAcknowledgement(
// StockOperationTypeRequiresDispatchAcknowledgement(operationType)
// );
// setAllowExpiredBatchNumbers(
// currentStockOperationType?.allowExpiredBatchNumbers ?? false
// );

return (
<>
<div
Expand Down Expand Up @@ -295,8 +244,11 @@ const AddStockOperation: React.FC<AddStockOperationProps> = (props) => {
<StockOperationIssueStockButton operation={props.model} />
</div>
)}

{canPrint && (
{(props.model?.permission?.isRequisitionAndCanIssueStock ||
props.model?.operationType === "stockissue" ||
props.model?.operationType === "requisition" ||
props.model?.operationType === "receipt" ||
props.model?.operationType === "transferout") && (
<div style={{ margin: "2px" }}>
<StockOperationPrintButton operation={props.model} />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { StockOperationDTO } from "../../core/api/types/stockOperation/StockOperationDTO";
import { SaveStockOperation } from "../../stock-items/types";
import {
SaveStockOperation,
SaveStockOperationAction,
} from "../../stock-items/types";
import { StockOperationType } from "../../core/api/types/stockOperation/StockOperationType";
import { InitializeResult } from "./types";
import {
Expand Down Expand Up @@ -31,9 +34,9 @@ interface StockOperationSubmissionProps {
actions: {
onGoBack: () => void;
onSave?: SaveStockOperation;
onComplete: () => void;
onSubmit: () => void;
onDispatch: () => void;
onComplete: SaveStockOperationAction;
onSubmit: SaveStockOperationAction;
onDispatch: SaveStockOperationAction;
};
}

Expand Down Expand Up @@ -98,6 +101,7 @@ const StockOperationSubmission: React.FC<StockOperationSubmissionProps> = ({
<Button
name="complete"
type="button"
style={{ margin: "4px" }}
className="submitButton"
kind="primary"
onClick={actions.onComplete}
Expand All @@ -110,6 +114,7 @@ const StockOperationSubmission: React.FC<StockOperationSubmissionProps> = ({
<Button
name="dispatch"
type="button"
style={{ margin: "4px" }}
className="submitButton"
kind="primary"
onClick={actions.onDispatch}
Expand All @@ -122,12 +127,13 @@ const StockOperationSubmission: React.FC<StockOperationSubmissionProps> = ({
<Button
name="submit"
type="button"
style={{ margin: "4px" }}
className="submitButton"
kind="primary"
onClick={actions.onSubmit}
renderIcon={SendFilled}
>
{t("submit", "Submit")}
{t("submit", "Submit For Review")}
</Button>
)}
</>
Expand All @@ -136,6 +142,7 @@ const StockOperationSubmission: React.FC<StockOperationSubmissionProps> = ({
name="save"
type="button"
className="submitButton"
style={{ margin: "4px" }}
disabled={isSaving}
onClick={async () => {
setIsSaving(true);
Expand All @@ -150,6 +157,7 @@ const StockOperationSubmission: React.FC<StockOperationSubmissionProps> = ({
{!isSaving && (
<Button
type="button"
style={{ margin: "4px" }}
className="cancelButton"
kind="tertiary"
onClick={actions.onGoBack}
Expand Down
14 changes: 14 additions & 0 deletions src/stock-operations/stock-operation.utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { closeOverlay, launchOverlay } from "../core/components/overlay/hook";
import React from "react";
import {
FetchResponse,
showModal,
showNotification,
showToast,
} from "@openmrs/esm-framework";
Expand Down Expand Up @@ -90,3 +91,16 @@ export function getStockOperationUniqueId() {
.toString(36)
.substring(2, 16)}`;
}

export const showActionDialogButton = async (
title: string,
requireReason: boolean,
operation: StockOperationDTO
) => {
const dispose = showModal("stock-operation-dialog", {
title: title,
operation: operation,
requireReason: requireReason,
closeModal: () => dispose(),
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const StockOperationApprovalButton: React.FC<
const dispose = showModal("stock-operation-dialog", {
title: "Approve",
operation: operation,
requireReason: false,
closeModal: () => dispose(),
});
}, [operation]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const StockOperationApproveDispatchButton: React.FC<
const dispose = showModal("stock-operation-dialog", {
title: "Approve Dispatch",
operation: operation,
requireReason: true,
closeModal: () => dispose(),
});
}, [operation]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const StockOperationCancelButton: React.FC<StockOperationCancelButtonProps> = ({
const dispose = showModal("stock-operation-dialog", {
title: "Cancel",
operation: operation,
requireReason: true,
closeModal: () => dispose(),
});
}, [operation]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const StockOperationCompleteButton: React.FC<
const dispose = showModal("stock-operation-dialog", {
title: "Complete",
operation: operation,
requireReason: true,
closeModal: () => dispose(),
});
}, [operation]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const StockOperationCompleteDispatchButton: React.FC<
const dispose = showModal("stock-operation-dialog", {
title: "Complete Dispatch",
operation: operation,
requireReason: false,
closeModal: () => dispose(),
});
}, [operation]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ import { closeOverlay } from "../../core/components/overlay/hook";

interface StockOperationDialogProps {
title: string;
requireReason: boolean;
operation: StockOperationDTO;
closeModal: () => void;
}

const StockOperationDialog: React.FC<StockOperationDialogProps> = ({
title,
requireReason,
operation,
closeModal,
}) => {
const confirmType = title.toLocaleLowerCase();
const confirmType = title.toLocaleLowerCase().trim();

const { t } = useTranslation();

Expand All @@ -45,6 +47,18 @@ const StockOperationDialog: React.FC<StockOperationDialogProps> = ({
let actionName: StopOperationActionType | null = null;

switch (confirmType) {
case "submit":
actionName = "SUBMIT";
break;
case "dispatch":
actionName = "DISPATCH";
break;
case "complete":
actionName = "COMPLETE";
break;
case "completedispatch":
actionName = "COMPLETE";
break;
case "cancel":
actionName = "CANCEL";
break;
Expand All @@ -68,7 +82,7 @@ const StockOperationDialog: React.FC<StockOperationDialogProps> = ({

const payload: StopOperationAction = {
name: actionName,
uuid: operation.uuid,
uuid: operation?.uuid,
reason: notes,
};

Expand Down Expand Up @@ -117,7 +131,7 @@ const StockOperationDialog: React.FC<StockOperationDialogProps> = ({
</h5>
</section>
<br />
{title !== "Approve" && (
{requireReason && (
<section className={styles.section}>
<TextArea
labelText={t("notes", "Please explain the reason:")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const StockOperationIssueStockButton: React.FC<
const dispose = showModal("stock-operation-dialog", {
title: "Issue Stock",
operation: operation,
requireReason: true,
closeModal: () => dispose(),
});
}, [operation]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const StockOperationRejectButton: React.FC<StockOperationRejectButtonProps> = ({
const dispose = showModal("stock-operation-dialog", {
title: "Reject",
operation: operation,
requireReason: true,
closeModal: () => dispose(),
});
}, [operation]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const StockOperationReturnButton: React.FC<StockOperationReturnButtonProps> = ({
const dispose = showModal("stock-operation-dialog", {
title: "Return",
operation: operation,
requireReason: true,
closeModal: () => dispose(),
});
}, [operation]);
Expand Down

0 comments on commit 6f470d4

Please sign in to comment.