Skip to content

Commit

Permalink
edit product with prefilled value and count (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhavya-egov authored Jul 23, 2024
1 parent 8f67c31 commit b1a5e58
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ const AddDeliveryRule = ({ targetedData, deliveryRules, setDeliveryRules, index,
)}
</CardHeader>
{filteredDeliveryConfig?.customAttribute && filteredDeliveryConfig?.projectType !== "LLIN-mz" && (
<LabelFieldPair style={{ marginTop: "1.5rem", marginBottom: "1.5rem", alignItems: "flex-start" }} className="delivery-type-radio">
<LabelFieldPair style={{ marginTop: "1.5rem", marginBottom: "1.5rem"}} className="delivery-type-radio">
<div className="deliveryType-labelfield">
<span className="bold">{`${t("HCM_DELIVERY_TYPE")}`}</span>
</div>
Expand Down Expand Up @@ -733,6 +733,7 @@ const AddDeliveryRule = ({ targetedData, deliveryRules, setDeliveryRules, index,
confirmResources={confirmResources}
showToast={showToast}
closeToast={closeToast}
selectedProducts={delivery?.products}
/>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const DustbinIcon = () => (
/>
</svg>
);
function AddProducts({ stref, selectedDelivery, showToast, closeToast }) {
function AddProducts({ stref, selectedDelivery, showToast, closeToast, selectedProducts }) {
const { t } = useTranslation();
const oldSessionData = window.Digit.SessionStorage.get("HCM_CAMPAIGN_MANAGER_FORM_DATA");
const { campaignData, dispatchCampaignData } = useContext(CycleContext);
Expand All @@ -39,6 +39,25 @@ function AddProducts({ stref, selectedDelivery, showToast, closeToast }) {
},
]);
const data = Digit.Hooks.campaign.useProductList(tenantId);
useEffect(() => {
const updatedProducts = selectedProducts.map((selectedProduct, index) => {

const id = selectedProduct?.value;
return {
key: index + 1,
count: selectedProduct?.count || 1,
// value: selectedProduct.additionalData,
value: {
displayName: selectedProduct.name,
id: id,
},
name: selectedProduct.name,
};
});

setProducts(updatedProducts);
}, [selectedProducts]);


const filteredData = data?.filter((item) => !selectedDelivery?.products?.some((entry) => entry?.value === item?.id));
const temp = filteredData?.filter((item) => !products?.some((entry) => entry?.value?.id === item?.id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,11 @@ function DeliverySetup({ onSelect, config, formData, control, tabCount = 2, subT
case "UPDATE_ATTRIBUTE":
return action.payload;
case "ADD_PRODUCT":
const prodTemp = action.payload.productData.map((i) => ({ ...i, value: i?.value?.id, name: i?.value?.displayName }));
const prodTemp = action.payload.productData.map((i) => ({
...i,
value: i?.value?.id,
name: i?.value?.displayName,
}));
const updatedState = state.map((cycle) => {
if (cycle.active) {
const updatedDeliveries = cycle.deliveries.map((dd) => {
Expand All @@ -457,7 +461,7 @@ function DeliverySetup({ onSelect, config, formData, control, tabCount = 2, subT
if (rule.ruleKey === action.payload.delivery.ruleKey) {
return {
...rule,
products: [...rule.products, ...prodTemp],
products: [...prodTemp],
};
}
return rule;
Expand Down

0 comments on commit b1a5e58

Please sign in to comment.