Skip to content

Commit 82939c5

Browse files
Merge pull request #4857 from OneCommunityGlobal/SaiKrishna_EditableAndSelectableFieldsInEquipmentFrontEnd
SaiKrishna - Editable And Selectable Fields In Equipment
2 parents 1558887 + 131992c commit 82939c5

6 files changed

Lines changed: 485 additions & 87 deletions

File tree

src/actions/bmdashboard/equipmentActions.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import axios from 'axios';
22
import { toast } from 'react-toastify';
3-
import { GET_EQUIPMENT_BY_ID, SET_EQUIPMENTS } from '../../constants/bmdashboard/equipmentConstants';
3+
import {
4+
GET_EQUIPMENT_BY_ID,
5+
SET_EQUIPMENTS,
6+
UPDATE_EQUIPMENT_START,
7+
UPDATE_EQUIPMENT_SUCCESS,
8+
UPDATE_EQUIPMENT_ERROR,
9+
} from '../../constants/bmdashboard/equipmentConstants';
410
import { GET_ERRORS } from '../../constants/errors';
511
import { ENDPOINTS } from '~/utils/URL';
612

@@ -91,3 +97,20 @@ export const updateMultipleEquipmentLogs = (projectId, bulkArr) => dispatch => {
9197
throw err;
9298
});
9399
}
100+
101+
export const updateEquipmentById = (equipmentId, updatedFields) => async dispatch => {
102+
dispatch({ type: UPDATE_EQUIPMENT_START });
103+
try {
104+
const url = ENDPOINTS.BM_EQUIPMENT_BY_ID(equipmentId);
105+
const res = await axios.put(url, updatedFields);
106+
dispatch({ type: UPDATE_EQUIPMENT_SUCCESS, payload: res.data });
107+
dispatch(setEquipment(res.data));
108+
toast.success('Equipment updated successfully!');
109+
return res.data;
110+
} catch (err) {
111+
const errorMsg = err.response?.data?.message || 'Failed to update equipment.';
112+
dispatch({ type: UPDATE_EQUIPMENT_ERROR, payload: errorMsg });
113+
toast.error(errorMsg);
114+
throw err;
115+
}
116+
};

0 commit comments

Comments
 (0)