2020-07-01 13:08:18 -07:00
|
|
|
import api from '../api';
|
2020-03-31 15:45:12 -07:00
|
|
|
|
2020-07-04 12:14:36 -07:00
|
|
|
export const PATRON_INSTANCE_FETCH_REQUEST = 'PATRON_INSTANCE_FETCH_REQUEST';
|
|
|
|
export const PATRON_INSTANCE_FETCH_SUCCESS = 'PATRON_INSTANCE_FETCH_SUCCESS';
|
2020-07-04 19:25:43 -07:00
|
|
|
export const PATRON_INSTANCE_FETCH_FAIL = 'PATRON_INSTANCE_FETCH_FAIL';
|
|
|
|
|
|
|
|
export const PATRON_ACCOUNT_FETCH_REQUEST = 'PATRON_ACCOUNT_FETCH_REQUEST';
|
|
|
|
export const PATRON_ACCOUNT_FETCH_SUCCESS = 'PATRON_ACCOUNT_FETCH_SUCCESS';
|
|
|
|
export const PATRON_ACCOUNT_FETCH_FAIL = 'PATRON_ACCOUNT_FETCH_FAIL';
|
2020-03-31 15:45:12 -07:00
|
|
|
|
2020-07-04 12:14:36 -07:00
|
|
|
export function fetchPatronInstance() {
|
2020-03-31 15:45:12 -07:00
|
|
|
return (dispatch, getState) => {
|
2020-07-04 12:14:36 -07:00
|
|
|
dispatch({ type: PATRON_INSTANCE_FETCH_REQUEST });
|
2020-07-01 13:08:18 -07:00
|
|
|
api(getState).get('/api/patron/v1/instance').then(response => {
|
2020-07-04 19:25:43 -07:00
|
|
|
dispatch(importFetchedInstance(response.data));
|
2020-03-31 15:45:12 -07:00
|
|
|
}).catch(error => {
|
2020-07-04 19:25:43 -07:00
|
|
|
dispatch(fetchInstanceFail(error));
|
2020-03-31 15:45:12 -07:00
|
|
|
});
|
|
|
|
};
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|
2020-03-31 15:45:12 -07:00
|
|
|
|
2020-07-04 19:25:43 -07:00
|
|
|
export function fetchPatronAccount(apId) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
apId = encodeURIComponent(apId);
|
|
|
|
dispatch({ type: PATRON_ACCOUNT_FETCH_REQUEST });
|
|
|
|
api(getState).get(`/api/patron/v1/accounts/${apId}`).then(response => {
|
|
|
|
dispatch(importFetchedAccount(response.data));
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch(fetchAccountFail(error));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function importFetchedInstance(instance) {
|
2020-03-31 15:45:12 -07:00
|
|
|
return {
|
2020-07-04 12:14:36 -07:00
|
|
|
type: PATRON_INSTANCE_FETCH_SUCCESS,
|
|
|
|
instance,
|
2020-03-31 15:45:12 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-07-04 19:25:43 -07:00
|
|
|
function fetchInstanceFail(error) {
|
2020-03-31 15:45:12 -07:00
|
|
|
return {
|
2020-07-04 12:14:36 -07:00
|
|
|
type: PATRON_INSTANCE_FETCH_FAIL,
|
2020-03-31 15:45:12 -07:00
|
|
|
error,
|
|
|
|
skipAlert: true,
|
|
|
|
};
|
2021-08-03 12:22:51 -07:00
|
|
|
}
|
2020-07-04 19:25:43 -07:00
|
|
|
|
|
|
|
function importFetchedAccount(account) {
|
|
|
|
return {
|
|
|
|
type: PATRON_ACCOUNT_FETCH_SUCCESS,
|
|
|
|
account,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetchAccountFail(error) {
|
|
|
|
return {
|
|
|
|
type: PATRON_ACCOUNT_FETCH_FAIL,
|
|
|
|
error,
|
|
|
|
skipAlert: true,
|
|
|
|
};
|
|
|
|
}
|