Skip to content

Commit

Permalink
(fix):O3-4252-Stock issue operation bugs out while saving/completing …
Browse files Browse the repository at this point in the history
…the operation && minor fixes
  • Loading branch information
makombe committed Dec 5, 2024
1 parent c613cb7 commit 2e17cb8
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ const AddStockOperation: React.FC<AddStockOperationProps> = (props) => {

const [requiresDispatchAcknowledgement, setRequiresDispatchAcknowledgement] = useState(false);

const currentStockOperationType = types?.results?.find((p) => p.operationType === props.model?.operationType);
const currentStockOperationType = types?.results?.find((p) => p.operationType === props?.model?.operationType);

useEffect(() => {
if (
currentStockOperationType?.operationType === OperationType.REQUISITION_OPERATION_TYPE ||
props.model?.operationType === OperationType.REQUISITION_OPERATION_TYPE
props?.model?.operationType === OperationType.REQUISITION_OPERATION_TYPE
) {
setRequisition(props.model?.uuid);
setRequisition(props?.model?.uuid);
}
}, [currentStockOperationType, props.model?.operationType, props.model?.uuid]);
}, [currentStockOperationType, props?.model?.operationType, props?.model?.uuid]);

useEffect(() => {
if (
Expand Down Expand Up @@ -110,8 +110,8 @@ const AddStockOperation: React.FC<AddStockOperationProps> = (props) => {
{...props}
isEditing={props?.operation?.name === 'Stock Issue' ? !isEditing : isEditing}
setup={result}
canEdit={props?.operation?.name === 'Stock Issue' ? !canEdit : canEdit}
model={isEditing ? props?.model : props?.operation?.name === 'Stock Issue' ? props?.model : result?.dto} // check if type is stockIssue and pass requisition data
canEdit={canEdit}
model={isEditing ? props?.model : props?.operation?.name === 'Stock Issue' ? props?.model : result?.dto}
onSave={async () => {
setManageStockItems(true);
setSelectedIndex(1);
Expand Down Expand Up @@ -291,7 +291,7 @@ const AddStockOperation: React.FC<AddStockOperationProps> = (props) => {
<h6 style={{ color: '#24a148' }}>Related Transactions:</h6>
{operationLinks.map(
(item) =>
(props.model?.uuid === item?.parentUuid || currentStockOperationType.uuid === item?.parentUuid) && (
(props?.model?.uuid === item?.parentUuid || currentStockOperationType?.uuid === item?.parentUuid) && (
<>
<span>{item?.childOperationTypeName}</span>
<span className={item?.childVoided ? 'voided' : ''}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ const BaseOperationDetails: React.FC<BaseOperationDetailsProps> = ({
setIsSaving(false);
}
};

const isCompleteStatus = model?.status === 'COMPLETED';
const sourceTags =
operation?.stockOperationTypeLocationScopes
?.filter((p) => operation?.hasSource && p.isSource)
Expand Down Expand Up @@ -125,7 +123,7 @@ const BaseOperationDetails: React.FC<BaseOperationDetailsProps> = ({
return (
<div style={{ margin: '10px' }}>
<form className={`${styles.formContainer} ${styles.verticalForm}`}>
{isCompleteStatus ? (
{!canEdit || operationType === 'stockissue' ? (
<>
{model?.operationDate && (
<TextInput
Expand All @@ -146,15 +144,17 @@ const BaseOperationDetails: React.FC<BaseOperationDetailsProps> = ({
{model?.atLocationName && (
<TextInput
id="sourceLbl"
value={model.atLocationName}
value={operationType === 'stockissue' ? issueStockOperation.sourceName : model?.sourceName ?? ''}
readOnly={true}
labelText={t('source', 'Source')}
/>
)}
{model?.destinationName && (
<TextInput
id="destinationLbl"
value={model.destinationName}
value={
operationType === 'stockissue' ? issueStockOperation.destinationName : model?.destinationName ?? ''
}
readOnly={true}
labelText={t('destination', 'Destination')}
/>
Expand All @@ -173,6 +173,20 @@ const BaseOperationDetails: React.FC<BaseOperationDetailsProps> = ({
{model?.remarks && (
<TextInput id="remarksLbl" value={model.remarks} readOnly={true} labelText={t('remarks', 'Remarks')} />
)}
{operationType === 'stockissue' && (
<div style={{ display: 'flex', flexDirection: 'row-reverse' }}>
<Button
name="save"
type="button"
className="submitButton"
onClick={handleSubmit(handleSave)}
kind="primary"
renderIcon={ArrowRight}
>
{isSaving ? <InlineLoading /> : t('next', 'Next')}
</Button>
</div>
)}
</>
) : (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ const StockOperationReference = (props: StockOperationReferenceProps) => {
const { types } = useStockOperationTypes();

let model: StockOperationDTO;

getStockOperation(props?.operationUuid).then((resp) => {
model = resp.data;
});
if (props?.operationUuid) {
getStockOperation(props?.operationUuid).then((resp) => {
model = resp?.data;
});
}

const handleEdit = () => {
const operation = types.results?.find((op) => op?.uuid === model?.operationTypeUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const StockOperationSubmission: React.FC<StockOperationSubmissionProps> = ({
name="rbgApprovelRequired"
legendText={t('doesThisTransactionRequireApproval', 'Does the transaction require approval ?')}
onChange={handleRadioButtonChange}
defaultSelected={model?.approvalRequired === null ? false : approvalRequired}
>
<RadioButton value={true} id="rbgApprovelRequired-true" labelText={t('yes', 'Yes')} />
<RadioButton value={false} id="rbgApprovelRequired-false" labelText={t('no', 'No')} />
Expand Down Expand Up @@ -115,7 +114,6 @@ const StockOperationSubmission: React.FC<StockOperationSubmissionProps> = ({
}}
renderIcon={Departure}
>
{t('dispatch', 'Dispatch')}
{isSaving ? (
<InlineLoading description={t('dispatching', 'Dispatching')} />
) : (
Expand Down
1 change: 1 addition & 0 deletions src/stock-operations/stock-operation.utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const addOrEditStockOperation = async (
delete payload.operationTypeUuid;
delete payload.permission;
delete payload.locked;

payload['operationTypeUuid'] = stockIssueOpsTypeUuid;
}
const response: FetchResponse<StockOperationDTO> = await (isEditing ? updateStockOperation : createStockOperation)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const StockOperationDialog: React.FC<StockOperationDialogProps> = ({ title, requ
case 'complete':
actionName = 'COMPLETE';
break;
case 'completedispatch':
case 'complete dispatch':
actionName = 'COMPLETE';
break;
case 'cancel':
Expand Down
1 change: 0 additions & 1 deletion src/stock-operations/stock-operations-table.resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export function useStockOperationPages(filter: StockOperationFilter) {

const pageSizes = [10, 20, 30, 40, 50];
const [currentPageSize, setPageSize] = useState(10);
console.log(items.results);

const { goTo, results: paginatedItems, currentPage } = usePagination(items.results, currentPageSize);

Expand Down
17 changes: 11 additions & 6 deletions src/stock-operations/stock-operations.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,23 @@ export function getStockOperationLinks(filter: string) {
}

// getStockOperation
export function useStockOperation(id: string) {
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperation/${id}`;
const { data, error, isLoading } = useSWR<{ data: StockOperationDTO }, Error>(apiUrl, openmrsFetch);

export function useStockOperation(id: string | null) {
const apiUrl = id ? `${restBaseUrl}/stockmanagement/stockoperation/${id}` : null;
const { data, error, isLoading } = useSWR<{ data: StockOperationDTO }, Error>(apiUrl, apiUrl ? openmrsFetch : null);
return {
items: data.data ? data.data : {},
items: data?.data || {},
isLoading,
error,
};
} // getStockOperation
}

// getStockOperation
export function getStockOperation(id: string): Promise<FetchResponse<StockOperationDTO>> {
if (!id) {
return;
}
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperation/${id}?v=full`;

return openmrsFetch(apiUrl);
}

Expand Down

0 comments on commit 2e17cb8

Please sign in to comment.