2018-01-30 09:54:45 -05:00
|
|
|
var keyMirror = require('keymirror');
|
|
|
|
var api = require('../lib/api');
|
2016-05-19 11:34:59 -04:00
|
|
|
|
2018-01-30 09:54:45 -05:00
|
|
|
var Types = keyMirror({
|
2016-05-19 11:34:59 -04:00
|
|
|
SET_DETAILS: null,
|
|
|
|
SET_DETAILS_FETCHING: null,
|
|
|
|
SET_DETAILS_ERROR: null
|
|
|
|
});
|
|
|
|
|
2018-01-30 09:54:45 -05:00
|
|
|
module.exports.detailsReducer = function (state, action) {
|
2016-05-19 11:34:59 -04:00
|
|
|
if (typeof state === 'undefined') {
|
|
|
|
state = {};
|
|
|
|
}
|
|
|
|
switch (action.type) {
|
|
|
|
case Types.SET_DETAILS:
|
|
|
|
return action.details;
|
|
|
|
case Types.SET_DETAILS_FETCHING:
|
|
|
|
return {fetching: action.fetching};
|
|
|
|
case Types.SET_DETAILS_ERROR:
|
|
|
|
return {error: action.error};
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-30 09:54:45 -05:00
|
|
|
module.exports.setDetailsError = function (error) {
|
|
|
|
return {
|
|
|
|
type: Types.SET_DETAILS_ERROR,
|
|
|
|
error: error
|
|
|
|
};
|
|
|
|
};
|
2016-05-19 11:34:59 -04:00
|
|
|
|
2018-01-30 09:54:45 -05:00
|
|
|
module.exports.setDetails = function (details) {
|
|
|
|
return {
|
|
|
|
type: Types.SET_DETAILS,
|
|
|
|
details: details
|
|
|
|
};
|
|
|
|
};
|
2016-05-19 11:34:59 -04:00
|
|
|
|
2018-01-30 09:54:45 -05:00
|
|
|
module.exports.setDetailsFetching = function () {
|
|
|
|
return {
|
|
|
|
type: Types.SET_DETAILS_FETCHING,
|
|
|
|
fetching: true
|
|
|
|
};
|
|
|
|
};
|
2016-05-19 11:34:59 -04:00
|
|
|
|
2018-01-30 09:54:45 -05:00
|
|
|
module.exports.startGetDetails = function (id) {
|
|
|
|
return function (dispatch) {
|
|
|
|
dispatch(module.exports.setDetailsFetching());
|
|
|
|
dispatch(module.exports.getDetails(id));
|
|
|
|
};
|
|
|
|
};
|
2016-05-19 11:34:59 -04:00
|
|
|
|
2018-01-30 09:54:45 -05:00
|
|
|
module.exports.getDetails = function (id) {
|
|
|
|
return function (dispatch) {
|
|
|
|
api({
|
|
|
|
uri: '/conference/' + id + '/details'
|
|
|
|
}, function (err, body) {
|
|
|
|
if (err) {
|
|
|
|
dispatch(module.exports.setDetailsError(err));
|
|
|
|
return;
|
2016-05-19 11:34:59 -04:00
|
|
|
}
|
2018-01-19 14:06:26 -05:00
|
|
|
|
2018-01-30 09:54:45 -05:00
|
|
|
if (typeof body !== 'undefined') {
|
|
|
|
var columns = body.columns;
|
|
|
|
if (body.rows) {
|
|
|
|
var details = body.rows[0];
|
|
|
|
var detailsObject = details.reduce(function (prev, cur, index) {
|
|
|
|
prev[columns[index]] = cur;
|
|
|
|
return prev;
|
|
|
|
}, {});
|
|
|
|
dispatch(module.exports.setDetails(detailsObject));
|
|
|
|
} else {
|
|
|
|
dispatch(module.exports.setDetailsError('Not Found'));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
dispatch(module.exports.setDetailsError('An unexpected error occurred'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|