Counter mapping
This commit is contained in:
parent
587632ebe9
commit
6c92192628
|
|
@ -28,7 +28,7 @@ import {
|
|||
import { useAuth } from '../../AuthContext.jsx';
|
||||
import '../../Styles/CounterCategoryMappingForm/CounterCategoryMapping.scss';
|
||||
const subDirectory = import.meta.env.BASE_URL;
|
||||
import FolderExploreCompoent from "./FolderExploreCompoent.jsx"
|
||||
import FolderExploreCompoent from './FolderExploreCompoent.jsx';
|
||||
|
||||
const CounterCategoryMappingForm = () => {
|
||||
const { SadminuserAccess } = useAuth();
|
||||
|
|
@ -56,7 +56,7 @@ const CounterCategoryMappingForm = () => {
|
|||
const [openModel, setOpenModel] = useState(false);
|
||||
const [expandedRows, setExpandedRows] = useState([]);
|
||||
|
||||
console.log(CounterName, 'CounterName')
|
||||
console.log(CounterName, 'CounterName');
|
||||
const items = [
|
||||
{
|
||||
name: 'Home',
|
||||
|
|
@ -69,7 +69,6 @@ const CounterCategoryMappingForm = () => {
|
|||
},
|
||||
];
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(changeBreadCrumb({ items: items }));
|
||||
getCategorydetails();
|
||||
|
|
@ -83,7 +82,6 @@ const CounterCategoryMappingForm = () => {
|
|||
}
|
||||
}, [Editstate]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (UserType === 'Employee') {
|
||||
fetchApi();
|
||||
|
|
@ -112,22 +110,19 @@ const CounterCategoryMappingForm = () => {
|
|||
if (Category?.data?.statusCode === 1) {
|
||||
if (Category?.data?.data?.length > 0) {
|
||||
const categoryList = Category.data.data;
|
||||
const filteredCategories = categoryList?.map(e => ({
|
||||
const filteredCategories = categoryList?.map((e) => ({
|
||||
ProdCat: e.ProdCat,
|
||||
ProdCatName: e?.ProdCatName,
|
||||
isCatExpend: false,
|
||||
ProdSubCat: []
|
||||
ProdSubCat: [],
|
||||
}));
|
||||
|
||||
setExpandedRows(filteredCategories);
|
||||
}
|
||||
else {
|
||||
setExpandedRows([])
|
||||
|
||||
} else {
|
||||
setExpandedRows([]);
|
||||
}
|
||||
} else {
|
||||
setExpandedRows([])
|
||||
|
||||
setExpandedRows([]);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -137,95 +132,92 @@ const CounterCategoryMappingForm = () => {
|
|||
AppId: AppId,
|
||||
BranchId: BranchId,
|
||||
CompId: CompId,
|
||||
"CounterId": EditData?.CounterId,
|
||||
"CounterName": CounterName,
|
||||
"ActiveStatus": "A",
|
||||
CounterId: EditData?.CounterId,
|
||||
CounterName: CounterName,
|
||||
ActiveStatus: 'A',
|
||||
|
||||
CategoryDetails: (expandedRows || [])
|
||||
.filter(cat => cat?.isCatExpend || cat?.CounterCatId)
|
||||
.map(cat => {
|
||||
|
||||
.filter((cat) => cat?.isCatExpend || cat?.CounterCatId)
|
||||
.map((cat) => {
|
||||
const selectedSubs = (cat?.ProdSubCat || [])
|
||||
.filter(sub => sub?.isSubcatexpend || sub?.CounterSubCatId)
|
||||
.map(sub => ({
|
||||
.filter((sub) => sub?.isSubcatexpend || sub?.CounterSubCatId)
|
||||
.map((sub) => ({
|
||||
ProdSubCat: sub?.ProdSubCat,
|
||||
CounterCatId: sub?.CounterCatId || null,
|
||||
CounterSubCatId: sub?.CounterSubCatId || null,
|
||||
ActiveStatus: sub?.isSubcatexpend ? "A" : "D"
|
||||
ActiveStatus: sub?.isSubcatexpend ? 'A' : 'D',
|
||||
}));
|
||||
|
||||
return {
|
||||
CounterId: EditData?.CounterId || null,
|
||||
CounterCatId: cat?.CounterCatId,
|
||||
ProdCat: cat?.ProdCat,
|
||||
ActiveStatus: cat?.isCatExpend ? "A" : "D",
|
||||
SubCategoryDetails: selectedSubs
|
||||
ActiveStatus: cat?.isCatExpend ? 'A' : 'D',
|
||||
SubCategoryDetails: selectedSubs,
|
||||
};
|
||||
}),
|
||||
"UpdatedBy": UserId
|
||||
}
|
||||
UpdatedBy: UserId,
|
||||
};
|
||||
let PostCounterToken = await dispatch(
|
||||
putCounterCategoryMap(putData)
|
||||
).unwrap();
|
||||
if (PostCounterToken?.data?.statusCode === 1) {
|
||||
setEditData([])
|
||||
setEditState(false)
|
||||
setEditData([]);
|
||||
setEditState(false);
|
||||
setMessageType('success');
|
||||
setMessageData(PostCounterToken?.data?.response);
|
||||
setOpenModel(false)
|
||||
ClearDatas()
|
||||
setOpenModel(false);
|
||||
ClearDatas();
|
||||
formRef?.current?.resetFields();
|
||||
} else {
|
||||
setMessageType('error');
|
||||
setMessageData(PostCounterToken?.data?.response);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
let postdata = {
|
||||
AppId: AppId,
|
||||
BranchId: BranchId,
|
||||
CompId: CompId,
|
||||
CounterName: "values?.CounterName",
|
||||
CounterName: CounterName,
|
||||
ActiveStatus: 'A',
|
||||
CategoryDetails: (expandedRows || [])
|
||||
.filter(cat => cat?.isCatExpend)
|
||||
.map(cat => {
|
||||
|
||||
.filter((cat) => cat?.isCatExpend)
|
||||
.map((cat) => {
|
||||
const selectedSubs = (cat?.ProdSubCat || [])
|
||||
.filter(sub => sub?.isSubcatexpend)
|
||||
.map(sub => ({
|
||||
.filter((sub) => sub?.isSubcatexpend)
|
||||
.map((sub) => ({
|
||||
ProdSubCat: sub?.ProdSubCat,
|
||||
}));
|
||||
|
||||
return {
|
||||
ProdCat: cat?.ProdCat,
|
||||
SubCategoryDetails: selectedSubs
|
||||
SubCategoryDetails: selectedSubs,
|
||||
};
|
||||
})
|
||||
,
|
||||
}),
|
||||
CreatedBy: UserId,
|
||||
};
|
||||
let PostCounterToken = await dispatch(
|
||||
postCounterCategoryMap(postdata)
|
||||
).unwrap();
|
||||
|
||||
if (PostCounterToken?.data?.statusCode === 1) {
|
||||
setMessageType('success');
|
||||
setMessageData(PostCounterToken?.data?.response);
|
||||
setOpenModel(false)
|
||||
setOpenModel(false);
|
||||
ClearDatas();
|
||||
formRef?.current?.resetFields();
|
||||
} else {
|
||||
setMessageType('error');
|
||||
setMessageData(PostCounterToken?.data?.response);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
const getCounterTokenDatas = async () => {
|
||||
let data = {
|
||||
AppId: AppId,
|
||||
CompId: CompId,
|
||||
BranchId: BranchId,
|
||||
UserId: UserId
|
||||
UserId: UserId,
|
||||
};
|
||||
let Counterdatas = await dispatch(getCounterTokenData(data)).unwrap();
|
||||
if (Counterdatas?.data?.statusCode === 1) {
|
||||
|
|
@ -264,14 +256,12 @@ const CounterCategoryMappingForm = () => {
|
|||
(item) => item.ProdSubCat !== null
|
||||
);
|
||||
if (filterSubcategory?.length > 0) {
|
||||
return filterSubcategory
|
||||
|
||||
return filterSubcategory;
|
||||
} else {
|
||||
return []
|
||||
return [];
|
||||
}
|
||||
|
||||
} else {
|
||||
return []
|
||||
return [];
|
||||
}
|
||||
};
|
||||
const onComplete = useCallback(() => {
|
||||
|
|
@ -287,10 +277,9 @@ const CounterCategoryMappingForm = () => {
|
|||
setCategoryDataModal(false);
|
||||
};
|
||||
const editData = async (record, index) => {
|
||||
|
||||
setCounterName(record?.CounterName)
|
||||
setCounterName(record?.CounterName);
|
||||
setEditState(true);
|
||||
setOpenModel(true)
|
||||
setOpenModel(true);
|
||||
setEditData(record);
|
||||
|
||||
formRef?.current?.setFieldsValue({
|
||||
|
|
@ -298,7 +287,7 @@ const CounterCategoryMappingForm = () => {
|
|||
});
|
||||
|
||||
const results = await Promise.all(
|
||||
record?.CategoryDetails.map(cat =>
|
||||
record?.CategoryDetails.map((cat) =>
|
||||
getSubCategorydetailsFromChild(cat?.ProdCat)
|
||||
)
|
||||
);
|
||||
|
|
@ -306,18 +295,18 @@ const CounterCategoryMappingForm = () => {
|
|||
record?.CategoryDetails.forEach((cat, i) => {
|
||||
subCategoryMap[cat?.ProdCat] = results[i] || [];
|
||||
});
|
||||
console.log(subCategoryMap, "subCategoryMap");
|
||||
console.log(subCategoryMap, 'subCategoryMap');
|
||||
|
||||
setExpandedRows(prev =>
|
||||
prev.map(e => {
|
||||
setExpandedRows((prev) =>
|
||||
prev.map((e) => {
|
||||
const catDetail = record?.CategoryDetails?.find(
|
||||
x => x?.ProdCat === e.ProdCat
|
||||
(x) => x?.ProdCat === e.ProdCat
|
||||
);
|
||||
|
||||
if (!catDetail) return e;
|
||||
|
||||
const subDetailMap = {};
|
||||
catDetail?.SubCategoryDetails?.forEach(s => {
|
||||
catDetail?.SubCategoryDetails?.forEach((s) => {
|
||||
subDetailMap[s?.ProdSubCat] = s;
|
||||
});
|
||||
|
||||
|
|
@ -325,23 +314,22 @@ const CounterCategoryMappingForm = () => {
|
|||
...e,
|
||||
isCatExpend: true,
|
||||
CounterCatId: catDetail?.CounterCatId,
|
||||
ActiveStatus: "A",
|
||||
ActiveStatus: 'A',
|
||||
|
||||
// ✅ Attach subcategories
|
||||
ProdSubCat: (subCategoryMap[e?.ProdCat] || []).map(sub => {
|
||||
ProdSubCat: (subCategoryMap[e?.ProdCat] || []).map((sub) => {
|
||||
const subDetail = subDetailMap[sub?.ProdSubCat];
|
||||
|
||||
return {
|
||||
...sub,
|
||||
CounterCatId: subDetail?.CounterCatId,
|
||||
CounterSubCatId: subDetail?.CounterSubCatId,
|
||||
isSubcatexpend: !!subDetail // true if exists
|
||||
isSubcatexpend: !!subDetail, // true if exists
|
||||
};
|
||||
})
|
||||
}),
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
};
|
||||
const statusFormatter = async (record, index) => {
|
||||
let deletedata = {
|
||||
|
|
@ -367,8 +355,8 @@ const CounterCategoryMappingForm = () => {
|
|||
};
|
||||
|
||||
const ClearDatas = async () => {
|
||||
getCategorydetails();
|
||||
getCounterTokenDatas();
|
||||
await getCategorydetails();
|
||||
await getCounterTokenDatas();
|
||||
formRef?.current?.resetFields();
|
||||
setCounterName(null);
|
||||
setEditData([]);
|
||||
|
|
@ -419,9 +407,9 @@ const CounterCategoryMappingForm = () => {
|
|||
style={{ color: '#1292EE' }}
|
||||
onClick={() =>
|
||||
empData?.UpdateAccess === 'Y' ||
|
||||
SAAccessCommonMaster?.UpdateAccess === 'Y' ||
|
||||
UserType == 'Admin' ||
|
||||
UserType == 'Super Admin'
|
||||
SAAccessCommonMaster?.UpdateAccess === 'Y' ||
|
||||
UserType == 'Admin' ||
|
||||
UserType == 'Super Admin'
|
||||
? editData(record, index)
|
||||
: ''
|
||||
}
|
||||
|
|
@ -436,9 +424,9 @@ const CounterCategoryMappingForm = () => {
|
|||
}}
|
||||
onClick={() =>
|
||||
empData?.DeleteAccess === 'Y' ||
|
||||
SAAccessCommonMaster?.DeleteAccess === 'Y' ||
|
||||
UserType == 'Admin' ||
|
||||
UserType == 'Super Admin'
|
||||
SAAccessCommonMaster?.DeleteAccess === 'Y' ||
|
||||
UserType == 'Admin' ||
|
||||
UserType == 'Super Admin'
|
||||
? statusFormatter(record, index)
|
||||
: ''
|
||||
}
|
||||
|
|
@ -453,10 +441,10 @@ const CounterCategoryMappingForm = () => {
|
|||
}}
|
||||
onClick={() =>
|
||||
empData?.DeleteAccess === 'Y' ||
|
||||
empData?.DeleteAccess === undefined ||
|
||||
SAAccessCommonMaster?.DeleteAccess === 'Y' ||
|
||||
UserType == 'Admin' ||
|
||||
UserType == 'Super Admin'
|
||||
empData?.DeleteAccess === undefined ||
|
||||
SAAccessCommonMaster?.DeleteAccess === 'Y' ||
|
||||
UserType == 'Admin' ||
|
||||
UserType == 'Super Admin'
|
||||
? statusFormatter(record, index)
|
||||
: ''
|
||||
}
|
||||
|
|
@ -465,14 +453,12 @@ const CounterCategoryMappingForm = () => {
|
|||
},
|
||||
];
|
||||
const handleNewMapping = () => {
|
||||
setOpenModel(true)
|
||||
setEditState(false)
|
||||
}
|
||||
setOpenModel(true);
|
||||
setEditState(false);
|
||||
};
|
||||
|
||||
const handleChangeinput = async ({ type, value, Cat, subcat }) => {
|
||||
|
||||
if (type === "cat") {
|
||||
|
||||
if (type === 'cat') {
|
||||
if (value) {
|
||||
try {
|
||||
let data;
|
||||
|
|
@ -483,20 +469,20 @@ const CounterCategoryMappingForm = () => {
|
|||
memoizedData.current[Cat] = data;
|
||||
}
|
||||
|
||||
setExpandedRows(prev => {
|
||||
const alreadyExists = prev.find(e => e.ProdCat === Cat);
|
||||
setExpandedRows((prev) => {
|
||||
const alreadyExists = prev.find((e) => e.ProdCat === Cat);
|
||||
|
||||
if (alreadyExists) {
|
||||
return prev.map(e =>
|
||||
return prev.map((e) =>
|
||||
e.ProdCat === Cat
|
||||
? {
|
||||
...e,
|
||||
isCatExpend: true,
|
||||
ProdSubCat: data.map(sub => ({
|
||||
...sub,
|
||||
isSubcatexpend: true,
|
||||
})),
|
||||
}
|
||||
...e,
|
||||
isCatExpend: true,
|
||||
ProdSubCat: data.map((sub) => ({
|
||||
...sub,
|
||||
isSubcatexpend: true,
|
||||
})),
|
||||
}
|
||||
: e
|
||||
);
|
||||
}
|
||||
|
|
@ -506,51 +492,41 @@ const CounterCategoryMappingForm = () => {
|
|||
{
|
||||
ProdCat: Cat,
|
||||
isCatExpend: true,
|
||||
ProdSubCat: data.map(sub => ({
|
||||
ProdSubCat: data.map((sub) => ({
|
||||
...sub,
|
||||
isSubcatexpend: false,
|
||||
})),
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error("Subcategory fetch failed", error);
|
||||
console.error('Subcategory fetch failed', error);
|
||||
}
|
||||
|
||||
} else {
|
||||
setExpandedRows(prev =>
|
||||
prev.map(e =>
|
||||
e.ProdCat === Cat
|
||||
? { ...e, isCatExpend: false }
|
||||
: e
|
||||
setExpandedRows((prev) =>
|
||||
prev.map((e) =>
|
||||
e.ProdCat === Cat ? { ...e, isCatExpend: false } : e
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
else if (type === "subcat") {
|
||||
|
||||
setExpandedRows(prev =>
|
||||
prev.map(e => {
|
||||
|
||||
} else if (type === 'subcat') {
|
||||
setExpandedRows((prev) =>
|
||||
prev.map((e) => {
|
||||
if (e.ProdCat !== Cat) return e;
|
||||
|
||||
const updatedSubs = e.ProdSubCat.map(sub =>
|
||||
sub.ProdSubCat === subcat
|
||||
? { ...sub, isSubcatexpend: value }
|
||||
: sub
|
||||
const updatedSubs = e.ProdSubCat.map((sub) =>
|
||||
sub.ProdSubCat === subcat ? { ...sub, isSubcatexpend: value } : sub
|
||||
);
|
||||
|
||||
// 🔥 Check if ANY subcategory is still true
|
||||
const isAnySubSelected = updatedSubs.some(
|
||||
sub => sub.isSubcatexpend
|
||||
(sub) => sub.isSubcatexpend
|
||||
);
|
||||
|
||||
return {
|
||||
...e,
|
||||
isCatExpend: isAnySubSelected, // auto update category
|
||||
ProdSubCat: updatedSubs
|
||||
isCatExpend: isAnySubSelected, // auto update category
|
||||
ProdSubCat: updatedSubs,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
|
@ -560,7 +536,7 @@ const CounterCategoryMappingForm = () => {
|
|||
return (
|
||||
<div className="pageOverAll">
|
||||
<div className="userPage">
|
||||
<div className='countermapBTN'>
|
||||
<div className="countermapBTN">
|
||||
<FormHeader title={'Counter Category Mapping'} />
|
||||
<Buttons
|
||||
buttonText="Add New"
|
||||
|
|
@ -766,13 +742,12 @@ const CounterCategoryMappingForm = () => {
|
|||
</div>
|
||||
</Form> */}
|
||||
|
||||
|
||||
{CounterDetail?.length > 0 && (
|
||||
<div style={{ height: '400px', overflowY: 'scroll' }}>
|
||||
<Table
|
||||
dataSource={CounterDetail}
|
||||
columns={TableColumns}
|
||||
// pagination={handlePageChange}
|
||||
// pagination={handlePageChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
|
@ -831,21 +806,21 @@ const CounterCategoryMappingForm = () => {
|
|||
>
|
||||
{item?.SubCategoryDetails?.length > 0
|
||||
? item?.SubCategoryDetails?.map((subCategory) => (
|
||||
<div
|
||||
style={{
|
||||
padding: '3px',
|
||||
width: 'max-content',
|
||||
backgroundColor: '#dbe6f5',
|
||||
borderRadius: '5px',
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
columnGap: '5px',
|
||||
}}
|
||||
>
|
||||
{subCategory?.ProdSubCatName}
|
||||
{/* <CloseCircleOutlined className="close-icon" onClick={() => handleRemoveSubCategory(subCategory)} /> */}
|
||||
</div>
|
||||
))
|
||||
<div
|
||||
style={{
|
||||
padding: '3px',
|
||||
width: 'max-content',
|
||||
backgroundColor: '#dbe6f5',
|
||||
borderRadius: '5px',
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
columnGap: '5px',
|
||||
}}
|
||||
>
|
||||
{subCategory?.ProdSubCatName}
|
||||
{/* <CloseCircleOutlined className="close-icon" onClick={() => handleRemoveSubCategory(subCategory)} /> */}
|
||||
</div>
|
||||
))
|
||||
: '-'}
|
||||
</div>
|
||||
</td>
|
||||
|
|
@ -862,7 +837,10 @@ const CounterCategoryMappingForm = () => {
|
|||
<DefaultModal
|
||||
open={openModel}
|
||||
title="Category Mapping"
|
||||
handleCancel={() => { setOpenModel(false); ClearDatas() }}
|
||||
handleCancel={() => {
|
||||
setOpenModel(false);
|
||||
ClearDatas();
|
||||
}}
|
||||
handleSubmit={() => handleFinish()}
|
||||
width={600}
|
||||
footer={false}
|
||||
|
|
@ -897,13 +875,10 @@ const CounterCategoryMappingForm = () => {
|
|||
allowClear
|
||||
value={CounterName}
|
||||
onChange={(e) => setCounterName(e.target.value)}
|
||||
style={{ marginBottom: "16px" }}
|
||||
style={{ marginBottom: '16px' }}
|
||||
/>
|
||||
|
||||
</Form.Item>
|
||||
<div className='addCatAmping'>
|
||||
|
||||
|
||||
<div className="addCatAmping">
|
||||
{expandedRows?.map((item) => (
|
||||
<FolderExploreCompoent
|
||||
key={item.ProdCat}
|
||||
|
|
@ -912,22 +887,21 @@ const CounterCategoryMappingForm = () => {
|
|||
expandedRows={expandedRows}
|
||||
/>
|
||||
))}
|
||||
|
||||
</div>
|
||||
<div style={{
|
||||
display: "flex",
|
||||
flexDirection: "row-reverse"
|
||||
}}>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'row-reverse',
|
||||
}}
|
||||
>
|
||||
<Buttons
|
||||
buttonText="SUBMIT"
|
||||
color="901D77"
|
||||
icon={<ArrowRightOutlined />}
|
||||
|
||||
/>
|
||||
</div>
|
||||
</Form>
|
||||
</DefaultModal>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue