-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
2,804 additions
and
2,750 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,47 @@ | ||
// Action type | ||
const AUTHENTICATED = 'loggedin_user'; | ||
const AUTHENTICATION_FAILED = 'login_failed'; | ||
const AUTHENTICATION_IN_PROGRESS = 'login-progess'; | ||
const LOGGED_OUT = 'logout'; | ||
const LOGOUT_FAILED = 'logout_failed'; | ||
|
||
// Action creator | ||
const Login = response => ({ | ||
type: AUTHENTICATED, | ||
payload: response.data, | ||
loading: false, | ||
}); | ||
|
||
const LoginFailed = errorMessage => ({ | ||
type: AUTHENTICATION_FAILED, | ||
payload: { errorMessage }, | ||
loading: false, | ||
}); | ||
|
||
export { AUTHENTICATED, AUTHENTICATION_FAILED, Login, LoginFailed }; | ||
const LoginStarted = () => ({ | ||
type: AUTHENTICATION_IN_PROGRESS, | ||
loading: true, | ||
}); | ||
|
||
const Logout = () => ({ | ||
type: LOGGED_OUT, | ||
payload: {}, | ||
}); | ||
|
||
const LogoutFailed = errorMessage => ({ | ||
type: LOGOUT_FAILED, | ||
payload: { errorMessage }, | ||
}); | ||
|
||
export { | ||
AUTHENTICATED, | ||
AUTHENTICATION_FAILED, | ||
AUTHENTICATION_IN_PROGRESS, | ||
LOGGED_OUT, | ||
LOGOUT_FAILED, | ||
Login, | ||
LoginFailed, | ||
LoginStarted, | ||
Logout, | ||
LogoutFailed, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,38 @@ | ||
import axios from "axios"; | ||
import { Login, LoginFailed } from "../ActionCreators/AuthActionCreators"; | ||
import axios from 'axios'; | ||
import { | ||
Login, | ||
LoginFailed, | ||
LoginStarted, | ||
Logout, | ||
} from '../ActionCreators/AuthActionCreators'; | ||
|
||
const BASE_URL = "https://api.openconceptlab.org/"; | ||
const BASE_URL = 'https://api.openconceptlab.org/'; | ||
|
||
// login action | ||
const LoginAction = ({ username, token }) => { | ||
return async dispatch => { | ||
try { | ||
const url = `${BASE_URL}/users/${username}/`, | ||
headers = { Authorization: `Token ${token}` }; | ||
// dispatch login sent | ||
const response = await axios.post(url, null, { headers }); | ||
dispatch(Login(response)); | ||
localStorage.setItem("token", `Token ${token}`); | ||
localStorage.setItem("username", `${username}`); | ||
} catch (error) { | ||
if (error.response) { | ||
dispatch(LoginFailed(error.response.data.detail)); | ||
} else if (error.request) { | ||
dispatch(LoginFailed("Request can't be made")); | ||
} | ||
const LoginAction = ({ username, token }) => async (dispatch) => { | ||
try { | ||
const url = `${BASE_URL}/users/${username}/`; | ||
const headers = { Authorization: `Token ${token}` }; | ||
// dispatch request sent | ||
dispatch(LoginStarted()); | ||
const response = await axios.post(url, null, { headers }); | ||
dispatch(Login(response)); | ||
localStorage.setItem('token', `Token ${token}`); | ||
localStorage.setItem('username', `${username}`); | ||
} catch (error) { | ||
if (error.response) { | ||
dispatch(LoginFailed(error.response.data.detail)); | ||
} else if (error.request) { | ||
dispatch(LoginFailed("Request can't be made")); | ||
} | ||
}; | ||
} | ||
}; | ||
|
||
export { LoginAction }; | ||
// logout action | ||
const LogoutAction = () => (dispatch) => { | ||
dispatch(LoginStarted()); | ||
dispatch(Logout()); | ||
localStorage.clear(); | ||
}; | ||
|
||
export { LoginAction, LogoutAction }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import Loader from '../components/Loader'; | ||
|
||
const wrapper = mount(<Loader />); | ||
|
||
describe('Loader Component', () => { | ||
it('should render without crashing', () => { | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react'; | ||
|
||
const Loader = () => ( | ||
<div className="loader" /> | ||
); | ||
|
||
export default Loader; |
Oops, something went wrong.