Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

VAR-209 | Show errors to staff members if editing of reservations fail #1033

Merged
merged 2 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Add `show_only` filter section to filter reservation list. This filter have `can_modify` as its default value.
- Anonymous users now see a log in button below the calendar on the resource page helping them understand that they need to log in to continue.
- Fix FullCalendar not auto-select minPeriod time slot when user select. Various fixes related to edit reservation calendar, drag and drop and select error handler.
- Errors from respa backend are not swallowed in our ApiClient anymore.

**HOTFIX**
- Fix resource information headlines and icon.
Expand All @@ -27,6 +28,7 @@
- [#1027](https://github.com/City-of-Helsinki/varaamo/pull/1027) Improve resource page usability for anonymous users.
- [#1028](https://github.com/City-of-Helsinki/varaamo/pull/1028) Always fetch reservations with start and end filters.
- [#1029](https://github.com/City-of-Helsinki/varaamo/pull/1029) Add option to configure time zone for resources.
- [#1033](https://github.com/City-of-Helsinki/varaamo/pull/1033) Show errors to staff members if editing of reservations fail.

# 0.4.2
**HOTFIX**
Expand Down
11 changes: 7 additions & 4 deletions src/common/api/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import { parseData } from '../data/utils';

let authToken;

// Response interceptor to be able to handle errors.
axios.interceptors.response.use((response) => {
return response;
}, (error) => {
return Promise.reject(error.response);
});

const getToken = () => {
const state = store.getState();
return get(state, 'auth.token');
Expand Down Expand Up @@ -58,10 +65,6 @@ export class ApiClient {
.then(response => ({
data: get(response, 'data'),
error: null,
}))
.catch(error => ({
data: null,
error: get(error, 'response'),
}));
};

Expand Down
30 changes: 20 additions & 10 deletions src/domain/reservation/manage/page/ManageReservationsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import { createStructuredSelector } from 'reselect';
import PageWrapper from '../../../../../app/pages/PageWrapper';
import injectT from '../../../../../app/i18n/injectT';
import client from '../../../../common/api/client';
import { createNotification } from '../../../../common/notification/utils';
import ManageReservationsFilters from '../filters/ManageReservationsFilters';
import ManageReservationsList from '../list/ManageReservationsList';
import { NOTIFICATION_TYPE } from '../../../../common/notification/constants';
import Pagination from '../../../../common/pagination/Pagination';
import * as searchUtils from '../../../search/utils';
import { selectReservationToEdit } from '../../../../../app/actions/uiActions';
Expand Down Expand Up @@ -137,20 +139,28 @@ class ManageReservationsPage extends React.Component {
}));
}

onEditReservation = (reservation, status) => {
if (status === RESERVATION_STATE.CANCELLED) {
reservationUtils.cancelReservation(reservation).then(() => this.loadReservations());
} else {
reservationUtils.putReservation(reservation, { state: status }).then(() => {
this.loadReservations();
});
onEditReservation = async (reservation, status) => {
try {
if (status === RESERVATION_STATE.CANCELLED) {
await reservationUtils.cancelReservation(reservation);
} else {
await reservationUtils.putReservation(reservation, { state: status });
}
this.loadReservations();
} catch (error) {
// We show the error message from respa to staff because it helps with support and debugging.
createNotification(NOTIFICATION_TYPE.ERROR, error.data.detail);
}
}

onSaveComment = (reservation, comments) => {
return reservationUtils.putReservation(reservation, { resource: reservation.resource.id, comments }).then(() => {
onSaveComment = async (reservation, comments) => {
try {
await reservationUtils.putReservation(reservation, { resource: reservation.resource.id, comments });
this.loadReservations();
});
} catch (error) {
// We show the error message from respa to staff because it helps with support and debugging.
createNotification(NOTIFICATION_TYPE.ERROR, error.data.detail);
}
};

/**
Expand Down