Fix envvar problem
This commit is contained in:
parent
0a2c180d6a
commit
e858200a7a
377
js/api.js
377
js/api.js
|
|
@ -8,9 +8,12 @@ import thunkMiddleware from 'redux-thunk';
|
||||||
|
|
||||||
import { errorMessages } from './constants';
|
import { errorMessages } from './constants';
|
||||||
|
|
||||||
const axios = require('axios');
|
import getConfig from 'next/config';
|
||||||
|
const { publicRuntimeConfig } = getConfig();
|
||||||
|
|
||||||
const api_url = process.env.REACT_APP_TURNIERE_API_URL;
|
const api_url = publicRuntimeConfig.api_url;
|
||||||
|
|
||||||
|
const axios = require('axios');
|
||||||
|
|
||||||
const actiontypes_userinfo = {
|
const actiontypes_userinfo = {
|
||||||
'REGISTER' : 'REGISTER',
|
'REGISTER' : 'REGISTER',
|
||||||
|
|
@ -147,215 +150,215 @@ function checkForAuthenticationHeaders(response) {
|
||||||
|
|
||||||
const reducer_userinfo = (state = defaultstate_userinfo, action) => {
|
const reducer_userinfo = (state = defaultstate_userinfo, action) => {
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case actiontypes_userinfo.REGISTER:
|
case actiontypes_userinfo.REGISTER:
|
||||||
postRequest(action.state, '/users', {
|
postRequest(action.state, '/users', {
|
||||||
'username' : action.parameters.username,
|
'username' : action.parameters.username,
|
||||||
'email' : action.parameters.email,
|
'email' : action.parameters.email,
|
||||||
'password' : action.parameters.password
|
'password' : action.parameters.password
|
||||||
}).then((resp) => {
|
}).then((resp) => {
|
||||||
__store.dispatch({
|
|
||||||
type : actiontypes_userinfo.REGISTER_RESULT_SUCCESS
|
|
||||||
});
|
|
||||||
storeOptionalToken(resp);
|
|
||||||
}).catch((error) => {
|
|
||||||
if (error.response) {
|
|
||||||
__store.dispatch({
|
__store.dispatch({
|
||||||
'type' : actiontypes_userinfo.REGISTER_RESULT_ERROR,
|
type : actiontypes_userinfo.REGISTER_RESULT_SUCCESS
|
||||||
'parameters' : {
|
|
||||||
'errorMessages' : error.response.data.errors.full_messages
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
storeOptionalToken(error.response);
|
storeOptionalToken(resp);
|
||||||
} else {
|
}).catch((error) => {
|
||||||
__store.dispatch({
|
if (error.response) {
|
||||||
'type' : actiontypes_userinfo.REGISTER_RESULT_ERROR,
|
__store.dispatch({
|
||||||
'parameters' : {
|
'type' : actiontypes_userinfo.REGISTER_RESULT_ERROR,
|
||||||
'errorMessages' : [
|
'parameters' : {
|
||||||
errorMessages['registration_errorunknown']['en']
|
'errorMessages' : error.response.data.errors.full_messages
|
||||||
]
|
}
|
||||||
}
|
});
|
||||||
});
|
storeOptionalToken(error.response);
|
||||||
}
|
} else {
|
||||||
});
|
__store.dispatch({
|
||||||
return Object.assign({}, state, {});
|
'type' : actiontypes_userinfo.REGISTER_RESULT_ERROR,
|
||||||
case actiontypes_userinfo.REGISTER_RESULT_SUCCESS:
|
'parameters' : {
|
||||||
return Object.assign({}, state, {
|
'errorMessages' : [
|
||||||
error : false,
|
errorMessages['registration_errorunknown']['en']
|
||||||
errorMessages : []
|
]
|
||||||
});
|
}
|
||||||
case actiontypes_userinfo.REGISTER_RESULT_ERROR:
|
});
|
||||||
return Object.assign({}, state, {
|
|
||||||
error : true,
|
|
||||||
errorMessages : action.parameters.errorMessages
|
|
||||||
});
|
|
||||||
case actiontypes_userinfo.LOGIN:
|
|
||||||
postRequest(action.state, '/users/sign_in', {
|
|
||||||
email : action.parameters.email,
|
|
||||||
password : action.parameters.password
|
|
||||||
}).then((resp) => {
|
|
||||||
__store.dispatch({
|
|
||||||
type : actiontypes_userinfo.LOGIN_RESULT_SUCCESS,
|
|
||||||
parameters : {
|
|
||||||
username : resp.data.username,
|
|
||||||
successCallback: action.parameters.successCallback
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
storeOptionalToken(resp);
|
return Object.assign({}, state, {});
|
||||||
}).catch((error) => {
|
case actiontypes_userinfo.REGISTER_RESULT_SUCCESS:
|
||||||
if(error.response) {
|
return Object.assign({}, state, {
|
||||||
|
error : false,
|
||||||
|
errorMessages : []
|
||||||
|
});
|
||||||
|
case actiontypes_userinfo.REGISTER_RESULT_ERROR:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
error : true,
|
||||||
|
errorMessages : action.parameters.errorMessages
|
||||||
|
});
|
||||||
|
case actiontypes_userinfo.LOGIN:
|
||||||
|
postRequest(action.state, '/users/sign_in', {
|
||||||
|
email : action.parameters.email,
|
||||||
|
password : action.parameters.password
|
||||||
|
}).then((resp) => {
|
||||||
__store.dispatch({
|
__store.dispatch({
|
||||||
'type' : actiontypes_userinfo.LOGIN_RESULT_ERROR,
|
type : actiontypes_userinfo.LOGIN_RESULT_SUCCESS,
|
||||||
'parameters' : {
|
parameters : {
|
||||||
'errorMessages' : error.response.data.errors
|
username : resp.data.username,
|
||||||
|
successCallback: action.parameters.successCallback
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
storeOptionalToken(error.response);
|
storeOptionalToken(resp);
|
||||||
} else {
|
}).catch((error) => {
|
||||||
__store.dispatch({
|
if(error.response) {
|
||||||
'type' : actiontypes_userinfo.LOGIN_RESULT_ERROR,
|
__store.dispatch({
|
||||||
'parameters' : {
|
'type' : actiontypes_userinfo.LOGIN_RESULT_ERROR,
|
||||||
'errorMessages' : [ errorMessages['login_errorunknown']['en'] ]
|
'parameters' : {
|
||||||
}
|
'errorMessages' : error.response.data.errors
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
});
|
storeOptionalToken(error.response);
|
||||||
return Object.assign({}, state, {});
|
} else {
|
||||||
case actiontypes_userinfo.LOGIN_RESULT_SUCCESS:
|
__store.dispatch({
|
||||||
action.parameters.successCallback(action.parameters.username);
|
'type' : actiontypes_userinfo.LOGIN_RESULT_ERROR,
|
||||||
return Object.assign({}, state, {
|
'parameters' : {
|
||||||
isSignedIn : true,
|
'errorMessages' : [ errorMessages['login_errorunknown']['en'] ]
|
||||||
error : false,
|
}
|
||||||
errorMessages : [],
|
});
|
||||||
username : action.parameters.username,
|
}
|
||||||
});
|
});
|
||||||
case actiontypes_userinfo.LOGIN_RESULT_ERROR:
|
return Object.assign({}, state, {});
|
||||||
return Object.assign({}, state, {
|
case actiontypes_userinfo.LOGIN_RESULT_SUCCESS:
|
||||||
error : true,
|
action.parameters.successCallback(action.parameters.username);
|
||||||
errorMessages : action.parameters.errorMessages
|
return Object.assign({}, state, {
|
||||||
});
|
isSignedIn : true,
|
||||||
case actiontypes_userinfo.LOGOUT:
|
error : false,
|
||||||
deleteRequest(action.state, '/users/sign_out').then(() => {
|
errorMessages : [],
|
||||||
action.parameters.successCallback();
|
username : action.parameters.username,
|
||||||
__store.dispatch({ type : actiontypes_userinfo.CLEAR });
|
});
|
||||||
}).catch(() => {
|
case actiontypes_userinfo.LOGIN_RESULT_ERROR:
|
||||||
__store.dispatch({ type : actiontypes_userinfo.CLEAR });
|
return Object.assign({}, state, {
|
||||||
});
|
error : true,
|
||||||
return Object.assign({}, state, {});
|
errorMessages : action.parameters.errorMessages
|
||||||
case actiontypes_userinfo.STORE_AUTH_HEADERS:
|
});
|
||||||
return Object.assign({}, state, {
|
case actiontypes_userinfo.LOGOUT:
|
||||||
accesstoken : action.parameters.accesstoken,
|
deleteRequest(action.state, '/users/sign_out').then(() => {
|
||||||
client : action.parameters.client,
|
action.parameters.successCallback();
|
||||||
expiry : action.parameters.expiry,
|
__store.dispatch({ type : actiontypes_userinfo.CLEAR });
|
||||||
uid : action.parameters.uid
|
}).catch(() => {
|
||||||
});
|
__store.dispatch({ type : actiontypes_userinfo.CLEAR });
|
||||||
case actiontypes_userinfo.VERIFY_CREDENTIALS:
|
});
|
||||||
getRequest(action.state, '/users/validate_token').then((resp) => {
|
return Object.assign({}, state, {});
|
||||||
storeOptionalToken(resp);
|
case actiontypes_userinfo.STORE_AUTH_HEADERS:
|
||||||
}).catch(() => {
|
return Object.assign({}, state, {
|
||||||
__store.dispatch({ type: actiontypes_userinfo.CLEAR });
|
accesstoken : action.parameters.accesstoken,
|
||||||
});
|
client : action.parameters.client,
|
||||||
return Object.assign({}, state, {});
|
expiry : action.parameters.expiry,
|
||||||
case actiontypes_userinfo.REHYDRATE:
|
uid : action.parameters.uid
|
||||||
return Object.assign({}, state, action.parameters, { error: false, errorMessages: [] });
|
});
|
||||||
case actiontypes_userinfo.CLEAR:
|
case actiontypes_userinfo.VERIFY_CREDENTIALS:
|
||||||
return Object.assign({}, state, {
|
getRequest(action.state, '/users/validate_token').then((resp) => {
|
||||||
isSignedIn : false,
|
storeOptionalToken(resp);
|
||||||
username : null,
|
}).catch(() => {
|
||||||
error : false,
|
__store.dispatch({ type: actiontypes_userinfo.CLEAR });
|
||||||
errorMessages : [],
|
});
|
||||||
|
return Object.assign({}, state, {});
|
||||||
|
case actiontypes_userinfo.REHYDRATE:
|
||||||
|
return Object.assign({}, state, action.parameters, { error: false, errorMessages: [] });
|
||||||
|
case actiontypes_userinfo.CLEAR:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
isSignedIn : false,
|
||||||
|
username : null,
|
||||||
|
error : false,
|
||||||
|
errorMessages : [],
|
||||||
|
|
||||||
accesstoken : null,
|
accesstoken : null,
|
||||||
client : null,
|
client : null,
|
||||||
expiry : null,
|
expiry : null,
|
||||||
uid : null
|
uid : null
|
||||||
});
|
});
|
||||||
default: return state;
|
default: return state;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const reducer_tournamentinfo = (state = defaultstate_tournamentinfo, action) => {
|
const reducer_tournamentinfo = (state = defaultstate_tournamentinfo, action) => {
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case actiontypes_tournamentinfo.CREATE_TOURNAMENT:
|
case actiontypes_tournamentinfo.CREATE_TOURNAMENT:
|
||||||
postRequest(action.state, '/tournaments', action.parameters.tournament).then((resp) => {
|
postRequest(action.state, '/tournaments', action.parameters.tournament).then((resp) => {
|
||||||
storeOptionalToken(resp);
|
storeOptionalToken(resp);
|
||||||
action.parameters.successCallback();
|
action.parameters.successCallback();
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
action.parameters.errorCallback();
|
action.parameters.errorCallback();
|
||||||
});
|
|
||||||
return Object.assign({}, state, {});
|
|
||||||
case actiontypes_tournamentinfo.REQUEST_TOURNAMENT:
|
|
||||||
getRequest(action.state, '/tournaments/' + action.parameters.code).then((resp) => {
|
|
||||||
__store.dispatch({
|
|
||||||
type: actiontypes_tournamentinfo.REQUEST_TOURNAMENT_SUCCESS,
|
|
||||||
parameters: resp.data
|
|
||||||
});
|
});
|
||||||
storeOptionalToken(resp);
|
return Object.assign({}, state, {});
|
||||||
action.parameters.successCallback();
|
case actiontypes_tournamentinfo.REQUEST_TOURNAMENT:
|
||||||
}).catch(() => {
|
getRequest(action.state, '/tournaments/' + action.parameters.code).then((resp) => {
|
||||||
action.parameters.errorCallback();
|
__store.dispatch({
|
||||||
});
|
type: actiontypes_tournamentinfo.REQUEST_TOURNAMENT_SUCCESS,
|
||||||
return Object.assign({}, state, {});
|
parameters: resp.data
|
||||||
case actiontypes_tournamentinfo.REQUEST_TOURNAMENT_SUCCESS:
|
});
|
||||||
return Object.assign({}, state, {
|
storeOptionalToken(resp);
|
||||||
code : action.parameters.code,
|
action.parameters.successCallback();
|
||||||
description : action.parameters.description,
|
}).catch(() => {
|
||||||
id : action.parameters.id,
|
action.parameters.errorCallback();
|
||||||
name : action.parameters.name,
|
});
|
||||||
ownerUsername : action.parameters.owner_username,
|
return Object.assign({}, state, {});
|
||||||
isPublic : action.parameters.public,
|
case actiontypes_tournamentinfo.REQUEST_TOURNAMENT_SUCCESS:
|
||||||
stages: action.parameters.stages,
|
return Object.assign({}, state, {
|
||||||
teams : action.parameters.teams
|
code : action.parameters.code,
|
||||||
});
|
description : action.parameters.description,
|
||||||
case actiontypes_tournamentinfo.MODIFY_TOURNAMENT:
|
id : action.parameters.id,
|
||||||
patchRequest(action.state, '/teams/' + action.parameters.teamid, {
|
name : action.parameters.name,
|
||||||
name: action.parameters.name
|
ownerUsername : action.parameters.owner_username,
|
||||||
}).then((resp) => {
|
isPublic : action.parameters.public,
|
||||||
storeOptionalToken(resp);
|
stages: action.parameters.stages,
|
||||||
action.parameters.onSuccess();
|
teams : action.parameters.teams
|
||||||
}).catch((error) => {
|
});
|
||||||
if(error.response) {
|
case actiontypes_tournamentinfo.MODIFY_TOURNAMENT:
|
||||||
storeOptionalToken(error.response);
|
patchRequest(action.state, '/teams/' + action.parameters.teamid, {
|
||||||
}
|
name: action.parameters.name
|
||||||
action.parameters.onError();
|
}).then((resp) => {
|
||||||
});
|
storeOptionalToken(resp);
|
||||||
return Object.assign({}, state, {});
|
action.parameters.onSuccess();
|
||||||
case actiontypes_tournamentinfo.MODIFY_TOURNAMENT_SUCCESS:
|
}).catch((error) => {
|
||||||
|
if(error.response) {
|
||||||
|
storeOptionalToken(error.response);
|
||||||
|
}
|
||||||
|
action.parameters.onError();
|
||||||
|
});
|
||||||
|
return Object.assign({}, state, {});
|
||||||
|
case actiontypes_tournamentinfo.MODIFY_TOURNAMENT_SUCCESS:
|
||||||
|
|
||||||
return Object.assign({}, state, {});
|
return Object.assign({}, state, {});
|
||||||
case actiontypes_tournamentinfo.MODIFY_TOURNAMENT_ERROR:
|
case actiontypes_tournamentinfo.MODIFY_TOURNAMENT_ERROR:
|
||||||
|
|
||||||
return Object.assign({}, state, {});
|
return Object.assign({}, state, {});
|
||||||
case actiontypes_tournamentinfo.REHYDRATE:
|
case actiontypes_tournamentinfo.REHYDRATE:
|
||||||
|
|
||||||
return Object.assign({}, state, {});
|
return Object.assign({}, state, {});
|
||||||
case actiontypes_tournamentinfo.CLEAR:
|
case actiontypes_tournamentinfo.CLEAR:
|
||||||
|
|
||||||
return Object.assign({}, state, {});
|
return Object.assign({}, state, {});
|
||||||
default: return state;
|
default: return state;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const reducer_tournamentlist = (state = defaultstate_tournamentlist, action) => {
|
const reducer_tournamentlist = (state = defaultstate_tournamentlist, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case actiontypes_tournamentlist.FETCH:
|
case actiontypes_tournamentlist.FETCH:
|
||||||
getRequest(action.state, '/tournaments?type=' + action.parameters.type).then((resp) => {
|
getRequest(action.state, '/tournaments?type=' + action.parameters.type).then((resp) => {
|
||||||
__store.dispatch({
|
__store.dispatch({
|
||||||
type: actiontypes_tournamentlist.FETCH_SUCCESS,
|
type: actiontypes_tournamentlist.FETCH_SUCCESS,
|
||||||
parameters: resp.data
|
parameters: resp.data
|
||||||
|
});
|
||||||
|
storeOptionalToken(resp);
|
||||||
|
action.parameters.successCallback(resp.data);
|
||||||
|
}).catch((error) => {
|
||||||
|
if(error.response) {
|
||||||
|
storeOptionalToken(error.response);
|
||||||
|
}
|
||||||
|
action.parameters.errorCallback();
|
||||||
});
|
});
|
||||||
storeOptionalToken(resp);
|
return state;
|
||||||
action.parameters.successCallback(resp.data);
|
case actiontypes_tournamentlist.FETCH_SUCCESS:
|
||||||
}).catch((error) => {
|
return Object.assign({}, state, {tournaments: action.parameters});
|
||||||
if(error.response) {
|
default:
|
||||||
storeOptionalToken(error.response);
|
return state;
|
||||||
}
|
|
||||||
action.parameters.errorCallback();
|
|
||||||
});
|
|
||||||
return state;
|
|
||||||
case actiontypes_tournamentlist.FETCH_SUCCESS:
|
|
||||||
return Object.assign({}, state, {tournaments: action.parameters});
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
|
||||||
const withCSS = require('@zeit/next-css');
|
const withCSS = require('@zeit/next-css');
|
||||||
module.exports = withCSS();
|
module.exports = withCSS();
|
||||||
|
module.exports.publicRuntimeConfig = {
|
||||||
|
api_url: process.env.API_URL
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue