Skip to content

Commit 9a73ea1

Browse files
Merge pull request #4865 from OneCommunityGlobal/SaiKrishna_addEditDeleteInventoryType
Sai krishna add edit delete inventory type
2 parents 7f71674 + e84030f commit 9a73ea1

12 files changed

Lines changed: 1251 additions & 35 deletions

File tree

src/actions/bmdashboard/invTypeActions.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import GET_MATERIAL_TYPES, {
1414
GET_CONSUMABLE_TYPES,
1515
GET_REUSABLE_TYPES,
1616
GET_EQUIPMENT_TYPES,
17+
ADD_INVENTORY_TYPE_SUCCESS,
18+
ADD_INVENTORY_TYPE_ERROR,
19+
UPDATE_INVENTORY_TYPE_SUCCESS,
20+
UPDATE_INVENTORY_TYPE_ERROR,
21+
DELETE_INVENTORY_TYPE_SUCCESS,
22+
DELETE_INVENTORY_TYPE_ERROR,
1723
} from '../../constants/bmdashboard/inventoryTypeConstants';
1824
import {
1925
POST_TOOLS_LOG,
@@ -302,3 +308,69 @@ export const resetPostToolsLog = () => {
302308
type: RESET_POST_TOOLS_LOG,
303309
};
304310
};
311+
312+
// ============ Generic Inventory Type CRUD Actions ============
313+
314+
/**
315+
* Add a new inventory type
316+
* @param {Object} payload - { name, description, category }
317+
* @param {string} category - The category (Materials, Consumables, Equipments, Reusables, Tools)
318+
*/
319+
export const addInventoryType = (payload, category) => {
320+
return async dispatch => {
321+
try {
322+
const res = await axios.post(ENDPOINTS.BM_INVTYPE_ROOT, { ...payload, category });
323+
dispatch({ type: ADD_INVENTORY_TYPE_SUCCESS, payload: res.data });
324+
// Refresh the list for this category
325+
dispatch(fetchInvTypeByType(category));
326+
return { success: true, data: res.data };
327+
} catch (err) {
328+
const errorMsg = err.response?.data?.message || err.response?.data || 'Failed to add inventory type';
329+
dispatch({ type: ADD_INVENTORY_TYPE_ERROR, payload: errorMsg });
330+
return { success: false, error: errorMsg };
331+
}
332+
};
333+
};
334+
335+
/**
336+
* Update an existing inventory type
337+
* @param {string} typeId - The ID of the inventory type
338+
* @param {Object} payload - { name, description }
339+
* @param {string} category - The category to refresh after update
340+
*/
341+
export const updateInventoryType = (typeId, payload, category) => {
342+
return async dispatch => {
343+
try {
344+
const res = await axios.put(ENDPOINTS.BM_INVTYPE_BY_ID(typeId), payload);
345+
dispatch({ type: UPDATE_INVENTORY_TYPE_SUCCESS, payload: res.data });
346+
// Refresh the list for this category
347+
dispatch(fetchInvTypeByType(category));
348+
return { success: true, data: res.data };
349+
} catch (err) {
350+
const errorMsg = err.response?.data?.message || err.response?.data || 'Failed to update inventory type';
351+
dispatch({ type: UPDATE_INVENTORY_TYPE_ERROR, payload: errorMsg });
352+
return { success: false, error: errorMsg };
353+
}
354+
};
355+
};
356+
357+
/**
358+
* Delete an inventory type
359+
* @param {string} typeId - The ID of the inventory type
360+
* @param {string} category - The category to refresh after delete
361+
*/
362+
export const deleteInventoryType = (typeId, category) => {
363+
return async dispatch => {
364+
try {
365+
await axios.delete(ENDPOINTS.BM_INVTYPE_BY_ID(typeId));
366+
dispatch({ type: DELETE_INVENTORY_TYPE_SUCCESS, payload: typeId });
367+
// Refresh the list for this category
368+
dispatch(fetchInvTypeByType(category));
369+
return { success: true };
370+
} catch (err) {
371+
const errorMsg = err.response?.data?.message || err.response?.data || 'Failed to delete inventory type';
372+
dispatch({ type: DELETE_INVENTORY_TYPE_ERROR, payload: errorMsg });
373+
return { success: false, error: errorMsg };
374+
}
375+
};
376+
};

src/actions/bmdashboard/invUnitActions.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
FETCH_BUILDING_MATERIAL_INVENTORY_UNITS,
66
POST_BUILDING_MATERIAL_INVENTORY_UNIT,
77
RESET_POST_BUILDING_MATERIAL_INVENTORY_UNIT,
8+
DELETE_INVENTORY_UNIT_SUCCESS,
9+
DELETE_INVENTORY_UNIT_ERROR,
810
} from '../../constants/bmdashboard/inventoryTypeConstants';
911
import { GET_ERRORS } from '../../constants/errors';
1012

@@ -60,3 +62,43 @@ export const postBuildingInventoryUnit = payload => {
6062
});
6163
};
6264
};
65+
66+
/**
67+
* Add a new inventory unit
68+
* @param {Object} payload - { unit }
69+
*/
70+
export const addInventoryUnit = payload => {
71+
return async dispatch => {
72+
try {
73+
const res = await axios.post(ENDPOINTS.BM_INVENTORY_UNITS, payload);
74+
dispatch(setPostInvUnitResult(res.data));
75+
// Refresh the units list
76+
dispatch(fetchInvUnits());
77+
return { success: true, data: res.data };
78+
} catch (err) {
79+
const errorMsg = err.response?.data?.message || err.response?.data || 'Failed to add unit';
80+
dispatch(setErrors(err));
81+
return { success: false, error: errorMsg };
82+
}
83+
};
84+
};
85+
86+
/**
87+
* Delete an inventory unit
88+
* @param {string} unitId - The ID of the unit to delete
89+
*/
90+
export const deleteInventoryUnit = unitId => {
91+
return async dispatch => {
92+
try {
93+
await axios.delete(ENDPOINTS.BM_INVENTORY_UNIT_BY_ID(unitId));
94+
dispatch({ type: DELETE_INVENTORY_UNIT_SUCCESS, payload: unitId });
95+
// Refresh the units list
96+
dispatch(fetchInvUnits());
97+
return { success: true };
98+
} catch (err) {
99+
const errorMsg = err.response?.data?.message || err.response?.data || 'Failed to delete unit';
100+
dispatch({ type: DELETE_INVENTORY_UNIT_ERROR, payload: errorMsg });
101+
return { success: false, error: errorMsg };
102+
}
103+
};
104+
};

0 commit comments

Comments
 (0)