2020-08-11 09:42:31 +00:00
|
|
|
|
|
|
|
import axios from "axios";
|
|
|
|
import I18n from 'react-native-i18n';
|
2020-08-19 06:25:24 +00:00
|
|
|
import { fetchCreateGroupError, fetchCreateGroupPending, fetchCreateGroupReset, fetchCreateGroupSuccess, fetchTreatDemandsGroupPending, fetchTreatDemandsGroupSuccess, fetchTreatDemandsGroupError, fetchTreatDemandsGroupReset, fetchJoinGroupPending, fetchJoinGroupSuccess, fetchJoinGroupError, fetchJoinGroupReset } from "../redux/actions/NanoCreditAction";
|
2020-08-11 09:42:31 +00:00
|
|
|
import { store } from "../redux/store";
|
2020-08-19 06:25:24 +00:00
|
|
|
import { groupUrl, treatDemandUrl, joinGroupUrl } from "./IlinkConstants";
|
2020-08-11 09:42:31 +00:00
|
|
|
|
|
|
|
export const createGroupAction = (data) => {
|
|
|
|
|
|
|
|
const auth = store.getState().authKeyReducer;
|
|
|
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
|
|
|
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchCreateGroupPending());
|
|
|
|
|
|
|
|
axios({
|
|
|
|
url: `${groupUrl}`,
|
|
|
|
method: 'POST',
|
|
|
|
data,
|
|
|
|
headers: {
|
|
|
|
'Authorization': authKey,
|
|
|
|
'X-Localization': I18n.currentLocale()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
console.log(response);
|
|
|
|
dispatch(fetchCreateGroupSuccess(response));
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if (error.response)
|
|
|
|
dispatch(fetchCreateGroupError(error.response));
|
|
|
|
else if (error.request)
|
|
|
|
dispatch(fetchCreateGroupError(error.request))
|
|
|
|
else
|
|
|
|
dispatch(fetchCreateGroupError(error.message))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const createGroupReset = () => {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchCreateGroupReset());
|
|
|
|
}
|
|
|
|
}
|
2020-08-17 05:25:16 +00:00
|
|
|
|
|
|
|
export const treatDemandGroupAction = (data) => {
|
|
|
|
|
|
|
|
const auth = store.getState().authKeyReducer;
|
|
|
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
|
|
|
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchTreatDemandsGroupPending());
|
|
|
|
|
|
|
|
axios({
|
|
|
|
url: `${treatDemandUrl}`,
|
|
|
|
method: 'POST',
|
|
|
|
data,
|
|
|
|
headers: {
|
|
|
|
'Authorization': authKey,
|
|
|
|
'X-Localization': I18n.currentLocale()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
console.log(response);
|
|
|
|
dispatch(fetchTreatDemandsGroupSuccess(response));
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if (error.response)
|
|
|
|
dispatch(fetchTreatDemandsGroupError(error.response));
|
|
|
|
else if (error.request)
|
|
|
|
dispatch(fetchTreatDemandsGroupError(error.request))
|
|
|
|
else
|
|
|
|
dispatch(fetchTreatDemandsGroupError(error.message))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const treatDemandGroupReset = () => {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchTreatDemandsGroupReset());
|
|
|
|
}
|
2020-08-19 06:25:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const joinGroupAction = (data) => {
|
|
|
|
|
|
|
|
const auth = store.getState().authKeyReducer;
|
|
|
|
const authKey = auth !== null ? `${auth.authKey.token_type} ${auth.authKey.access_token}` : '';
|
|
|
|
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchJoinGroupPending());
|
|
|
|
|
|
|
|
axios({
|
|
|
|
url: `${joinGroupUrl}`,
|
|
|
|
method: 'POST',
|
|
|
|
data,
|
|
|
|
headers: {
|
|
|
|
'Authorization': authKey,
|
|
|
|
'X-Localization': I18n.currentLocale()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
console.log(response);
|
|
|
|
dispatch(fetchJoinGroupSuccess(response));
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if (error.response)
|
|
|
|
dispatch(fetchJoinGroupError(error.response));
|
|
|
|
else if (error.request)
|
|
|
|
dispatch(fetchJoinGroupError(error.request))
|
|
|
|
else
|
|
|
|
dispatch(fetchJoinGroupError(error.message))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const joinGroupReset = () => {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(fetchJoinGroupReset());
|
|
|
|
}
|
2020-08-17 05:25:16 +00:00
|
|
|
}
|