Skip to content

Commit

Permalink
reverted back quantity dispense component
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKiprotich350 committed Jul 18, 2024
1 parent 4b6c4f9 commit b5b5eff
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
12 changes: 1 addition & 11 deletions src/forms/dispense-form.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ const DispenseForm: React.FC<DispenseFormProps> = ({
// to prevent duplicate submits
const [isSubmitting, setIsSubmitting] = useState(false);

//track quantity to dispense
const [currentQuantity, setCurrentQuantity] = useState(
quantityRemaining ? quantityRemaining : medicationDispense?.quantity?.value,
);

// Submit medication dispense form
const handleSubmit = () => {
if (!isSubmitting) {
Expand Down Expand Up @@ -170,10 +165,6 @@ const DispenseForm: React.FC<DispenseFormProps> = ({
}
};

const setAvailableQuantity = (batch) => {
setCurrentQuantity(Number(batch.quantity));
};

// initialize the internal dispense payload with the dispenses passed in as props
useEffect(() => setMedicationDispensePayload(medicationDispense), [medicationDispense]);

Expand Down Expand Up @@ -218,14 +209,13 @@ const DispenseForm: React.FC<DispenseFormProps> = ({
<MedicationDispenseReview
medicationDispense={medicationDispensePayload}
updateMedicationDispense={setMedicationDispensePayload}
quantityRemaining={currentQuantity}
quantityRemaining={quantityRemaining}
/>
{config.enableStockDispense && (
<StockDispense
inventoryItem={inventoryItem}
medicationDispense={medicationDispense}
updateInventoryItem={setInventoryItem}
updateAvailableQuantityToMedicationDispenseQuantity={setAvailableQuantity}
/>
)}
</div>
Expand Down
6 changes: 1 addition & 5 deletions src/forms/medication-dispense-review.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,7 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
}
min={0}
max={config.dispenseBehavior.restrictTotalQuantityDispensed ? quantityRemaining : undefined}
value={
quantityRemaining <= medicationDispense.quantity.value
? quantityRemaining
: medicationDispense.quantity.value
}
value={medicationDispense.quantity.value}
onChange={(e) => {
updateMedicationDispense({
...medicationDispense,
Expand Down
8 changes: 1 addition & 7 deletions src/forms/stock-dispense/stock-dispense.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ type StockDispenseProps = {
medicationDispense: MedicationDispense;
updateInventoryItem: (inventoryItem: InventoryItem) => void;
inventoryItem: InventoryItem;
updateAvailableQuantityToMedicationDispenseQuantity: (inventoryItem: InventoryItem) => void;
};

const StockDispense: React.FC<StockDispenseProps> = ({
medicationDispense,
updateInventoryItem,
updateAvailableQuantityToMedicationDispenseQuantity,
}) => {
const StockDispense: React.FC<StockDispenseProps> = ({ medicationDispense, updateInventoryItem }) => {
const { t } = useTranslation();
const drugUuid = medicationDispense?.medicationReference?.reference?.split('/')[1];
const { inventoryItems, error, isLoading } = useDispenseStock(drugUuid);
Expand Down Expand Up @@ -111,7 +106,6 @@ const StockDispense: React.FC<StockDispenseProps> = ({
items={validInventoryItems}
onChange={({ selectedItem }) => {
updateInventoryItem(selectedItem);
updateAvailableQuantityToMedicationDispenseQuantity(selectedItem);
}}
itemToString={(item) => (item ? toStockDispense(item) : '')}
titleText={t('stockDispense', 'Stock Dispense')}
Expand Down

0 comments on commit b5b5eff

Please sign in to comment.