Skip to content

Commit fdc0956

Browse files
committed
fix: handle errors from backend properly
1 parent 99e1ebb commit fdc0956

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

src/shared/containers/timeline-wall/index.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function TimelineWallContainer(props) {
3737
userAvatars,
3838
pendingApprovals,
3939
uploading,
40+
uploadResult,
4041
} = props;
4142

4243
const role = 'Admin User';
@@ -199,6 +200,7 @@ function TimelineWallContainer(props) {
199200
getAvatar={getAvatar}
200201
userAvatars={userAvatars}
201202
uploading={uploading}
203+
uploadResult={uploadResult}
202204
deleteEvent={deleteEvent}
203205
/>
204206
<React.Fragment>
@@ -231,6 +233,7 @@ TimelineWallContainer.defaultProps = {
231233
isAdmin: false,
232234
loading: false,
233235
uploading: false,
236+
uploadResult: '',
234237
events: [],
235238
userAvatars: {},
236239
pendingApprovals: [],
@@ -244,6 +247,7 @@ TimelineWallContainer.propTypes = {
244247
isAdmin: PT.bool,
245248
loading: PT.bool,
246249
uploading: PT.bool,
250+
uploadResult: PT.string,
247251
events: PT.arrayOf(PT.shape()),
248252
loadUserDetails: PT.func.isRequired,
249253
createNewEvent: PT.func.isRequired,
@@ -261,6 +265,7 @@ const mapStateToProps = state => ({
261265
isAdmin: state.timelineWall.isAdmin,
262266
loading: state.timelineWall.loading,
263267
uploading: state.timelineWall.uploading,
268+
uploadResult: state.timelineWall.uploadResult,
264269
events: state.timelineWall.events,
265270
userAvatars: state.timelineWall.userAvatars,
266271
pendingApprovals: state.timelineWall.pendingApprovals,

src/shared/containers/timeline-wall/modal-event-add/index.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import LoadingIndicator from 'components/LoadingIndicator';
66

77
import style from './styles.scss';
88

9-
function ModalEventAdd({ onClose, isAdmin, uploading }) {
9+
function ModalEventAdd({
10+
onClose, isAdmin, uploading, uploadResult,
11+
}) {
12+
const successMessage = !isAdmin ? 'Thank you! Your event was submitted for review. You’ll receive an email once the review is completed'
13+
: 'Thank you! Your event was added to the Timeline Wall.';
1014
return (
1115
<Modal
1216
theme={{ container: style.container, overlay: style.overlay }}
@@ -22,8 +26,7 @@ function ModalEventAdd({ onClose, isAdmin, uploading }) {
2226
) : (
2327
<span styleName="text-description">
2428
{
25-
!isAdmin ? 'Thank you! Your event was submitted for review. You’ll receive an email once the review is completed'
26-
: 'Thank you! Your event was added to the Timeline Wall.'
29+
uploadResult || successMessage
2730
}
2831
</span>
2932
)
@@ -56,6 +59,7 @@ ModalEventAdd.defaultProps = {
5659
onClose: () => { },
5760
isAdmin: false,
5861
uploading: false,
62+
uploadResult: '',
5963
};
6064

6165
/**
@@ -65,6 +69,7 @@ ModalEventAdd.propTypes = {
6569
onClose: PT.func,
6670
isAdmin: PT.bool,
6771
uploading: PT.bool,
72+
uploadResult: PT.string,
6873
};
6974

7075
export default ModalEventAdd;

src/shared/containers/timeline-wall/timeline-events/add-event/index.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import ModalEventAdd from '../../modal-event-add';
1818
import style from './styles.scss';
1919

2020
function AddEvents({
21-
className, isAuthenticated, createNewEvent, isAdmin, onDoneAddEvent, uploading,
21+
className, isAuthenticated, createNewEvent, isAdmin, onDoneAddEvent, uploading, uploadResult,
2222
}) {
2323
const [formData, setFormData] = useState({
2424
eventName: '',
@@ -197,6 +197,7 @@ function AddEvents({
197197
}}
198198
isAdmin={isAdmin}
199199
uploading={uploading}
200+
uploadResult={uploadResult}
200201
/>
201202
) : null
202203
}
@@ -212,6 +213,7 @@ AddEvents.defaultProps = {
212213
isAuthenticated: false,
213214
isAdmin: false,
214215
uploading: false,
216+
uploadResult: '',
215217
};
216218

217219
/**
@@ -224,6 +226,7 @@ AddEvents.propTypes = {
224226
isAdmin: PT.bool,
225227
onDoneAddEvent: PT.func.isRequired,
226228
uploading: PT.bool,
229+
uploadResult: PT.string,
227230
};
228231

229232
export default AddEvents;

src/shared/containers/timeline-wall/timeline-events/index.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function TimelineEvents({
2222
userAvatars,
2323
onDoneAddEvent,
2424
uploading,
25+
uploadResult,
2526
deleteEvent,
2627
}) {
2728
return (
@@ -34,6 +35,7 @@ function TimelineEvents({
3435
isAdmin={isAdmin}
3536
onDoneAddEvent={onDoneAddEvent}
3637
uploading={uploading}
38+
uploadResult={uploadResult}
3739
/>
3840
{events.length ? (
3941
<Events
@@ -94,6 +96,7 @@ TimelineEvents.defaultProps = {
9496
isAdmin: false,
9597
userAvatars: {},
9698
uploading: false,
99+
uploadResult: '',
97100
};
98101

99102
/**
@@ -114,6 +117,7 @@ TimelineEvents.propTypes = {
114117
onDoneAddEvent: PT.func.isRequired,
115118
userAvatars: PT.shape(),
116119
uploading: PT.bool,
120+
uploadResult: PT.string,
117121
deleteEvent: PT.func.isRequired,
118122
};
119123

src/shared/reducers/timelineWall.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ function onPendingApprovalDone(state, { payload }) {
8787
function onCreateNewEventInit(state) {
8888
return {
8989
...state,
90+
uploadResult: '',
9091
uploading: true,
9192
};
9293
}
@@ -96,9 +97,10 @@ function onCreateNewEventInit(state) {
9697
* @param {Object} state Previous state.
9798
* @param {Object} payload The payload.
9899
*/
99-
function onCreateNewEventDone(state) {
100+
function onCreateNewEventDone(state, { payload }) {
100101
return {
101102
...state,
103+
uploadResult: payload,
102104
uploading: false,
103105
};
104106
}

src/shared/services/timelineWall.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ export const createEvent = async (tokenV3, formData) => {
8585
},
8686
body: form,
8787
});
88+
if (res.status >= 300) {
89+
const result = await res.json();
90+
return result.message || 'There was an error during add event.';
91+
}
8892

89-
return res.json();
93+
return '';
9094
} catch (error) {
91-
return [];
95+
return 'There was an error during add event.';
9296
}
9397
};
9498

0 commit comments

Comments
 (0)