@@ -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' ;
1824import {
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+ } ;
0 commit comments