import { memo, useState, useEffect } from "react"; import { DropDowns } from "../../../Components/Forms/DropDown"; import { Checkbox, Popover } from "antd"; import { Settings, X } from "lucide-react"; import { PlusCircleOutlined } from '@ant-design/icons'; import { Tooltip } from 'antd'; import { getActiveProdSubCatData } from "../../../Features/ProductPage/ProductPage"; import { useDispatch } from "react-redux"; import { getSession } from "../../../Services/Others"; const DefaultSettingPopover = memo(({ field, options, onSubmit, currentDefault, popOverHeading, checkBoxHeading = 'Apply to all existing rows', showField, Component = null, triggerModal = () => { }, needAllSubCategories = false }) => { const dispatch = useDispatch(); const [selectedValue, setSelectedValue] = useState(currentDefault); const [applyToAll, setApplyToAll] = useState(false); const [open, setOpen] = useState(false); const [fetchSubCategoriesData, setFetchSubCategoriesData] = useState(false); console.log(fetchSubCategoriesData, "fetchSubCategoriesData") useEffect(() => { if (open) { setSelectedValue(currentDefault); setApplyToAll(false); } }, [open, currentDefault]); useEffect(() => { const fetchAllSubCategories = async () => { await (dispatch(getActiveProdSubCatData({ AppId: getSession('AppId') })))?.unwrap(); setFetchSubCategoriesData(false); } if (fetchSubCategoriesData) { fetchAllSubCategories(); } }, [fetchSubCategoriesData]); const handleSubmit = () => { onSubmit(field, selectedValue, applyToAll); setOpen(false); setApplyToAll(false); setSelectedValue(""); }; const getFieldTitle = (field) => { switch (field) { case "uom": return "UOM"; case "category": return "Category"; case "subCategory": return "Sub-Category"; case "tax": return "Tax"; default: return field; } }; const content = (
{popOverHeading} setOpen(false)} />
{showField &&
{showField}
}
{Component && ( { triggerModal(true); if (needAllSubCategories) { setFetchSubCategoriesData(true); } }} /> )}
{Component}
setApplyToAll(e.target.checked)} > {checkBoxHeading}
); return ( <> ); }); export default DefaultSettingPopover;