add action for sending update data to backend
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
|||||||
BOOKING_SHORTENED
|
BOOKING_SHORTENED
|
||||||
} from '../../../constants/enums';
|
} from '../../../constants/enums';
|
||||||
import { doorLockRelatedWithReservationIncidentHeaders, standaloneDoorLockIncidentHeaders, bookingChangeIncidentHeaders } from '../../../constants/constants';
|
import { doorLockRelatedWithReservationIncidentHeaders, standaloneDoorLockIncidentHeaders, bookingChangeIncidentHeaders } from '../../../constants/constants';
|
||||||
import { deleteIncidents } from "../../../store/actions";
|
import { deleteIncidents, updateIncidentFees } from "../../../store/actions";
|
||||||
|
|
||||||
class SingleIncidentsTable extends Component {
|
class SingleIncidentsTable extends Component {
|
||||||
state = {
|
state = {
|
||||||
@@ -88,6 +88,24 @@ class SingleIncidentsTable extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
updateChangedFees = () => {
|
||||||
|
const { dateRange, updateIncidentsById, memberId } = this.props;
|
||||||
|
const { changedUnlockedIncidentIds, changedUnscheduledIncidentIds, changedBookingChangeIncidentIds } = this.state;
|
||||||
|
|
||||||
|
const incidentFeesToUpdate = {
|
||||||
|
unlockedIncidentFees: changedUnlockedIncidentIds,
|
||||||
|
unscheduledIncidentFees: changedUnscheduledIncidentIds,
|
||||||
|
bookingChangeIncidentFees: changedBookingChangeIncidentIds
|
||||||
|
};
|
||||||
|
|
||||||
|
updateIncidentsById(dateRange, incidentFeesToUpdate, memberId);
|
||||||
|
this.setState({
|
||||||
|
changedUnlockedIncidentIds: {},
|
||||||
|
changedUnscheduledIncidentIds: {},
|
||||||
|
changedBookingChangeIncidentIds: {}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
const {
|
const {
|
||||||
loading,
|
loading,
|
||||||
@@ -327,7 +345,7 @@ class SingleIncidentsTable extends Component {
|
|||||||
<Button disabled={loading || totalSelected === 0} onClick={this.deleteSelectedFees}>{`Delete selected ${numberOfSelectedText}`}</Button>
|
<Button disabled={loading || totalSelected === 0} onClick={this.deleteSelectedFees}>{`Delete selected ${numberOfSelectedText}`}</Button>
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
<Button disabled={loading || totalChanged === 0}>{`Save changed ${numberOfChangedText}`}</Button>
|
<Button disabled={loading || totalChanged === 0} onClick={this.updateChangedFees}>{`Save changed ${numberOfChangedText}`}</Button>
|
||||||
}
|
}
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
{
|
{
|
||||||
@@ -346,7 +364,8 @@ class SingleIncidentsTable extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
deleteIncidentsById: (dateRange, incidentsToDelete, memberId) => deleteIncidents(dispatch, {dateRange, incidentsToDelete, memberId})
|
deleteIncidentsById: (dateRange, incidentsToDelete, memberId) => deleteIncidents(dispatch, {dateRange, incidentsToDelete, memberId}),
|
||||||
|
updateIncidentsById: (dateRange, updatedIncidentsData, memberId) => updateIncidentFees(dispatch, {dateRange, updatedIncidentsData, memberId})
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(null, mapDispatchToProps)(SingleIncidentsTable);
|
export default connect(null, mapDispatchToProps)(SingleIncidentsTable);
|
||||||
|
|||||||
@@ -103,6 +103,21 @@ export const deleteIncidents = (dispatch, deleteData) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updateIncidentFees = (dispatch, updateData) => {
|
||||||
|
const pendingAction = updateData.memberId ? FETCH_MEMBER_INCIDENTS_PENDING : FETCH_INCIDENTS_PENDING;
|
||||||
|
const successAction = updateData.memberId ? FETCH_MEMBER_INCIDENTS_SUCCESS : FETCH_INCIDENTS_SUCCESS;
|
||||||
|
const failedAction = updateData.memberId ? FETCH_MEMBER_INCIDENTS_FAILED : FETCH_INCIDENTS_FAILED;
|
||||||
|
|
||||||
|
dispatch({type: pendingAction});
|
||||||
|
API.patch(`/integration/fees`, updateData)
|
||||||
|
.then(response => {
|
||||||
|
dispatch({type: successAction, payload: response.data});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
dispatch({type: failedAction, payload: error.response});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const fetchMembersList = (dispatch) => {
|
export const fetchMembersList = (dispatch) => {
|
||||||
dispatch({type: FETCH_MEMBERS_PENDING});
|
dispatch({type: FETCH_MEMBERS_PENDING});
|
||||||
API.get('officeRnD/membersList')
|
API.get('officeRnD/membersList')
|
||||||
|
|||||||
Reference in New Issue
Block a user