From 16ba4a138ccdc8286371dacc680741134a4d6db1 Mon Sep 17 00:00:00 2001 From: Makombe Kennedy Date: Thu, 18 Jan 2024 10:12:24 +0300 Subject: [PATCH] Revert "fix radio button bug" --- ...ontrolled-radio-button-group.component.tsx | 37 ++++++++----------- .../stock-item-details.component.tsx | 27 ++++++++++---- .../stock-item-details.resource.tsx | 14 ------- .../add-stock-operation.component.tsx | 13 +++---- ...ions-approve-dispatch-button.component.tsx | 4 +- 5 files changed, 41 insertions(+), 54 deletions(-) diff --git a/src/core/components/carbon/controlled-radio-button-group/controlled-radio-button-group.component.tsx b/src/core/components/carbon/controlled-radio-button-group/controlled-radio-button-group.component.tsx index 308afd9e..bc8589cc 100644 --- a/src/core/components/carbon/controlled-radio-button-group/controlled-radio-button-group.component.tsx +++ b/src/core/components/carbon/controlled-radio-button-group/controlled-radio-button-group.component.tsx @@ -1,18 +1,12 @@ import React from "react"; import { RadioButtonGroupProps } from "@carbon/react/lib/components/RadioButtonGroup/RadioButtonGroup"; import { Control, Controller, FieldValues } from "react-hook-form"; -import { RadioButtonGroup, RadioButton } from "@carbon/react"; -import { - RadioOption, - radioOptions, -} from "../../../../stock-items/add-stock-item/stock-item-details/stock-item-details.resource"; +import { RadioButtonGroup } from "@carbon/react"; interface ControlledRadioButtonGroupProps extends RadioButtonGroupProps { controllerName: string; name: string; control: Control; - defaultValue?: string; - radioOptions: RadioOption[]; } const ControlledRadioButtonGroup = ( @@ -22,22 +16,21 @@ const ControlledRadioButtonGroup = ( ( - - {radioOptions.map((option: RadioOption, index) => ( - onChange(option.value)} - ref={ref} - /> - ))} - + { + onChange(selection, name, event); + + // Fire prop change + if (props.onChange) { + props.onChange(selection, name, event); + } + }} + id={props.name} + ref={ref} + value={value} + /> )} /> ); diff --git a/src/stock-items/add-stock-item/stock-item-details/stock-item-details.component.tsx b/src/stock-items/add-stock-item/stock-item-details/stock-item-details.component.tsx index 90624844..b881a546 100644 --- a/src/stock-items/add-stock-item/stock-item-details/stock-item-details.component.tsx +++ b/src/stock-items/add-stock-item/stock-item-details/stock-item-details.component.tsx @@ -22,7 +22,6 @@ import { SaveStockItem } from "../../types"; import ConceptsSelector from "../concepts-selector/concepts-selector.component"; import rootStyles from "../../../root.scss"; import { closeOverlay } from "../../../core/components/overlay/hook"; -import { expirationOptions, radioOptions } from "./stock-item-details.resource"; interface StockItemDetailsProps { model: StockItemDTO; @@ -57,12 +56,12 @@ const StockItemDetails = forwardRef( }; const [isSaving, setIsSaving] = useState(false); - const [isDrug, setIsDrug] = useState(false); + const [isDrug, setIsDrug] = useState(); const [hasExpiration, setHasExpiration] = useState(); useEffect(() => { - setIsDrug(model.isDrug ?? false); - setHasExpiration(model.hasExpiration ?? false); + setIsDrug(model.isDrug); + setHasExpiration(model.hasExpiration); }, [model.hasExpiration, model.isDrug]); return ( @@ -84,8 +83,10 @@ const StockItemDetails = forwardRef( setIsDrug(selection); }} name="isDrug" - radioOptions={radioOptions} - /> + > + + + {isDrug && ( ( onChange={(selection: boolean) => { setHasExpiration(selection); }} - radioOptions={expirationOptions} - /> + > + + + {hasExpiration && ( diff --git a/src/stock-items/add-stock-item/stock-item-details/stock-item-details.resource.tsx b/src/stock-items/add-stock-item/stock-item-details/stock-item-details.resource.tsx index ad5529cd..e69de29b 100644 --- a/src/stock-items/add-stock-item/stock-item-details/stock-item-details.resource.tsx +++ b/src/stock-items/add-stock-item/stock-item-details/stock-item-details.resource.tsx @@ -1,14 +0,0 @@ -export interface RadioOption { - label: string; - value: boolean | string; -} - -export const radioOptions: RadioOption[] = [ - { label: "Drug", value: true }, - { label: "Other", value: false }, -]; - -export const expirationOptions: RadioOption[] = [ - { label: "Yes", value: "yes" }, - { label: "No", value: "no" }, -]; diff --git a/src/stock-operations/add-stock-operation/add-stock-operation.component.tsx b/src/stock-operations/add-stock-operation/add-stock-operation.component.tsx index 0e45563b..cd172a55 100644 --- a/src/stock-operations/add-stock-operation/add-stock-operation.component.tsx +++ b/src/stock-operations/add-stock-operation/add-stock-operation.component.tsx @@ -36,6 +36,9 @@ const AddStockOperation: React.FC = (props) => { ); const [selectedIndex, setSelectedIndex] = useState(0); + const [requiresDispatchAcknowledgement, setRequiresDispatchAcknowledgement] = + useState(false); + if (isLoading) return ; if (isError) { closeOverlay(); @@ -193,18 +196,12 @@ const AddStockOperation: React.FC = (props) => { {!props.model?.permission?.canEdit && props.model?.permission?.canApprove && ( <> - {!(props.model - ? props.model?.operationTypeName === "return" || - props.model?.operationTypeName === "stockissue" - : false) && ( + {!requiresDispatchAcknowledgement && (
)} - {(props.model - ? props.model?.operationTypeName === "return" || - props.model?.operationTypeName === "stockissue" - : false) && ( + {requiresDispatchAcknowledgement && (
{ const dispose = showModal("stock-operation-dialog", { - title: "Dispatch", + title: "Approve Dispatch", operation: operation, requireReason: true, closeModal: () => dispose(), @@ -28,7 +28,7 @@ const StockOperationApproveDispatchButton: React.FC< onClick={launchApproveDispatchModal} renderIcon={(props) => } > - {t("approve", "Dispatch")} + {t("approve", "Approve Dispatch ")} ); };