ESlint: application générale des règles
This commit is contained in:
parent
21fe79684d
commit
e5c5d9c8d2
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Controller;
|
|
||||||
|
|
||||||
use App\Http\DataResponse;
|
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
|
||||||
|
|
||||||
class RequestController
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Route("/api/v1/request", name="api_v1_list_requests")
|
|
||||||
*/
|
|
||||||
public function listRequests()
|
|
||||||
{
|
|
||||||
return new DataResponse([
|
|
||||||
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,31 +1,47 @@
|
|||||||
export const LOGIN_REQUEST = 'LOGIN_REQUEST'
|
export const LOGIN_REQUEST = 'LOGIN_REQUEST';
|
||||||
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
|
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
|
||||||
export const LOGIN_FAILURE = 'LOGIN_FAILURE';
|
export const LOGIN_FAILURE = 'LOGIN_FAILURE';
|
||||||
|
|
||||||
export function login(username, password) {
|
export function login(username, password) {
|
||||||
return { type: LOGIN_REQUEST, username, password }
|
return { type: LOGIN_REQUEST, username, password };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loginFailure(username, error) {
|
export function loginFailure(username, error) {
|
||||||
return { type: LOGIN_FAILURE, username, error }
|
return { type: LOGIN_FAILURE, username, error };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loginSuccess(username) {
|
export function loginSuccess(username) {
|
||||||
return { type: LOGIN_SUCCESS, username }
|
return { type: LOGIN_SUCCESS, username };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const LOGOUT_REQUEST = 'LOGOUT_REQUEST'
|
export const LOGOUT_REQUEST = 'LOGOUT_REQUEST';
|
||||||
export const LOGOUT_SUCCESS = 'LOGOUT_SUCCESS';
|
export const LOGOUT_SUCCESS = 'LOGOUT_SUCCESS';
|
||||||
export const LOGOUT_FAILURE = 'LOGOUT_FAILURE';
|
export const LOGOUT_FAILURE = 'LOGOUT_FAILURE';
|
||||||
|
|
||||||
export function logout() {
|
export function logout() {
|
||||||
return { type: LOGOUT_REQUEST }
|
return { type: LOGOUT_REQUEST };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function logoutFailure(error) {
|
export function logoutFailure(error) {
|
||||||
return { type: LOGOUT_FAILURE, error }
|
return { type: LOGOUT_FAILURE, error };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function logoutSuccess() {
|
export function logoutSuccess() {
|
||||||
return { type: LOGOUT_SUCCESS }
|
return { type: LOGOUT_SUCCESS };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const REFRESH_USER_SESSION_REQUEST = 'REFRESH_USER_SESSION_REQUEST';
|
||||||
|
export const REFRESH_USER_SESSION_SUCCESS = 'REFRESH_USER_SESSION_SUCCESS';
|
||||||
|
export const REFRESH_USER_SESSION_FAILURE = 'REFRESH_USER_SESSION_FAILURE';
|
||||||
|
|
||||||
|
export function refreshUserSession() {
|
||||||
|
return { type: REFRESH_USER_SESSION_REQUEST };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function refreshUserSessionSuccess(user) {
|
||||||
|
return { type: REFRESH_USER_SESSION_SUCCESS, user };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function refreshUserSessionFailure(error) {
|
||||||
|
return { type: REFRESH_USER_SESSION_FAILURE, error };
|
||||||
}
|
}
|
@ -1,11 +1,11 @@
|
|||||||
export const ADD_MESSAGE = 'ADD_MESSAGE'
|
export const ADD_MESSAGE = 'ADD_MESSAGE';
|
||||||
|
|
||||||
export function addMessage(type, text) {
|
export function addMessage(type, text) {
|
||||||
return { type: ADD_MESSAGE, text, messageType: type };
|
return { type: ADD_MESSAGE, text, messageType: type };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const REMOVE_OLDEST_MESSAGE = 'REMOVE_OLDEST_MESSAGE'
|
export const REMOVE_OLDEST_MESSAGE = 'REMOVE_OLDEST_MESSAGE';
|
||||||
|
|
||||||
export function removeOldestMessage() {
|
export function removeOldestMessage() {
|
||||||
return { type: REMOVE_OLDEST_MESSAGE }
|
return { type: REMOVE_OLDEST_MESSAGE };
|
||||||
}
|
}
|
@ -3,13 +3,13 @@ export const PROJECT_USER_LIST_SUCCESS = 'PROJECT_USER_LIST_SUCCESS';
|
|||||||
export const PROJECT_USER_LIST_FAILURE = 'PROJECT_USER_LIST_FAILURE';
|
export const PROJECT_USER_LIST_FAILURE = 'PROJECT_USER_LIST_FAILURE';
|
||||||
|
|
||||||
export function projectUserListRequest() {
|
export function projectUserListRequest() {
|
||||||
return { type: PROJECT_USER_LIST}
|
return { type: PROJECT_USER_LIST};
|
||||||
}
|
}
|
||||||
export function projectUserListSuccess(projects) {
|
export function projectUserListSuccess(projects) {
|
||||||
return { type: PROJECT_USER_LIST_SUCCESS, projects }
|
return { type: PROJECT_USER_LIST_SUCCESS, projects };
|
||||||
}
|
}
|
||||||
export function projectUserListFailure(error) {
|
export function projectUserListFailure(error) {
|
||||||
return { type: PROJECT_USER_LIST_FAILURE, error }
|
return { type: PROJECT_USER_LIST_FAILURE, error };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PROJECT_LIST = 'PROJECT_LIST';
|
export const PROJECT_LIST = 'PROJECT_LIST';
|
||||||
@ -17,11 +17,11 @@ export const PROJECT_LIST_SUCCESS = 'PROJECT_LIST_SUCCESS';
|
|||||||
export const PROJECT_LIST_FAILURE = 'PROJECT_LIST_FAILURE';
|
export const PROJECT_LIST_FAILURE = 'PROJECT_LIST_FAILURE';
|
||||||
|
|
||||||
export function projectList() {
|
export function projectList() {
|
||||||
return { type: PROJECT_LIST}
|
return { type: PROJECT_LIST};
|
||||||
}
|
}
|
||||||
export function projectListSuccess(projects) {
|
export function projectListSuccess(projects) {
|
||||||
return { type: PROJECT_LIST_SUCCESS, projects }
|
return { type: PROJECT_LIST_SUCCESS, projects };
|
||||||
}
|
}
|
||||||
export function projectListFailure(error) {
|
export function projectListFailure(error) {
|
||||||
return { type: PROJECT_LIST_FAILURE, error }
|
return { type: PROJECT_LIST_FAILURE, error };
|
||||||
}
|
}
|
@ -3,13 +3,13 @@ export const CREATE_USER_SUCCESS = 'CREATE_USER_SUCCESS';
|
|||||||
export const CREATE_USER_FAILURE = 'CREATE_USER_FAILURE';
|
export const CREATE_USER_FAILURE = 'CREATE_USER_FAILURE';
|
||||||
|
|
||||||
export function createUser(username, password) {
|
export function createUser(username, password) {
|
||||||
return { type: CREATE_USER_REQUEST, username, password}
|
return { type: CREATE_USER_REQUEST, username, password};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createUserSuccess(user) {
|
export function createUserSuccess(user) {
|
||||||
return { type: CREATE_USER_SUCCESS, user }
|
return { type: CREATE_USER_SUCCESS, user };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createUserFailure(error) {
|
export function createUserFailure(error) {
|
||||||
return { type: CREATE_USER_FAILURE, error }
|
return { type: CREATE_USER_FAILURE, error };
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
import { Component, Fragment } from 'react'
|
import { Component, Fragment } from 'react';
|
||||||
import { hot } from 'react-hot-loader'
|
import { hot } from 'react-hot-loader';
|
||||||
import { HashRouter } from 'react-router-dom' // ou BrowserRouter
|
import { HashRouter } from 'react-router-dom'; // ou BrowserRouter
|
||||||
import { Route, Switch, Redirect } from 'react-router'
|
import { Route, Switch, Redirect } from 'react-router';
|
||||||
import HomePage from './pages/home';
|
import { ConnectedHomePage as HomePage } from './pages/home';
|
||||||
import { ConnectedLoginPage as LoginPage } from './pages/login';
|
import { ConnectedLoginPage as LoginPage } from './pages/login';
|
||||||
import DashBoardClient from './pages/DashBoardClient';
|
import DashBoardClient from './pages/DashBoardClient';
|
||||||
import DashBoardDev from './pages/DashBoardDev';
|
import DashBoardDev from './pages/DashBoardDev';
|
||||||
@ -25,10 +25,9 @@ export class App extends Component {
|
|||||||
</Switch>
|
</Switch>
|
||||||
</HashRouter>
|
</HashRouter>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ConnectedApp = connect()(App);
|
export const ConnectedApp = connect()(App);
|
||||||
export const HotApp = hot(module)(ConnectedApp);
|
export const HotApp = hot(module)(ConnectedApp);
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react'
|
import React from 'react';
|
||||||
import ProjectTile from './ProjectTile'
|
import ProjectTile from './ProjectTile';
|
||||||
|
|
||||||
export default ({ projects, withRequest }) => (
|
export default ({ projects, withRequest }) => (
|
||||||
<div className="tile is-parent is-vertical">
|
<div className="tile is-parent is-vertical">
|
||||||
@ -9,4 +9,4 @@ export default ({ projects, withRequest }) => (
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react'
|
import React from 'react';
|
||||||
import RequestList from './RequestList'
|
import RequestList from './RequestList';
|
||||||
|
|
||||||
export default ({ project, withRequest }) => (
|
export default ({ project, withRequest }) => (
|
||||||
<article className="tile is-child notification is-primary">
|
<article className="tile is-child notification is-primary">
|
||||||
@ -8,4 +8,4 @@ export default ({ project, withRequest }) => (
|
|||||||
withRequest && <RequestList requests={project.requests || []} />
|
withRequest && <RequestList requests={project.requests || []} />
|
||||||
}
|
}
|
||||||
</article>
|
</article>
|
||||||
)
|
);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react'
|
import React from 'react';
|
||||||
import RequestTile from './RequestTile'
|
import RequestTile from './RequestTile';
|
||||||
|
|
||||||
export default ({ requests }) => (
|
export default ({ requests }) => (
|
||||||
<div className="tile is-parent is-vertical">
|
<div className="tile is-parent is-vertical">
|
||||||
@ -9,4 +9,4 @@ export default ({ requests }) => (
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React from 'react'
|
import React from 'react';
|
||||||
import styles from './RequestTile.css'
|
import styles from './RequestTile.css';
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
export default ({ request }) => (
|
export default ({ request }) => (
|
||||||
<Link to={`dashboard-client/detail-demande/${request.id}`}>
|
<Link to={`dashboard-client/detail-demande/${request.id}`}>
|
||||||
@ -11,4 +11,4 @@ export default ({ request }) => (
|
|||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
</Link>
|
</Link>
|
||||||
)
|
);
|
||||||
|
@ -55,20 +55,20 @@ export function UserForm({ form, onSubmit }) {
|
|||||||
<button type="submit" disabled={!form.valid} className="button">Envoyer</button>
|
<button type="submit" disabled={!form.valid} className="button">Envoyer</button>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
const validators = {
|
const validators = {
|
||||||
username: (value, formData) => {
|
username: (value, formData) => {
|
||||||
if (!value) return { hasError: true, message: 'Le nom d\'utilisateur ne peut être vide !' }
|
if (!value) return { hasError: true, message: 'Le nom d\'utilisateur ne peut être vide !' };
|
||||||
return { hasError: false, message: '' };
|
return { hasError: false, message: '' };
|
||||||
},
|
},
|
||||||
password: (value, formData) => {
|
password: (value, formData) => {
|
||||||
if (!value) return { hasError: true, message: 'Le mot de passe ne peut pas être vide !' }
|
if (!value) return { hasError: true, message: 'Le mot de passe ne peut pas être vide !' };
|
||||||
if (value !== formData.passwordVerification) return { hasError: true, message: 'Vos deux mots de passe sont différents !' }
|
if (value !== formData.passwordVerification) return { hasError: true, message: 'Vos deux mots de passe sont différents !' };
|
||||||
return { hasError: false, message: '' };
|
return { hasError: false, message: '' };
|
||||||
},
|
},
|
||||||
passwordVerification: (value, formData) => {
|
passwordVerification: (value, formData) => {
|
||||||
if (value !== formData.password) return { hasError: true, message: 'Vos deux mots de passe sont différents !' }
|
if (value !== formData.password) return { hasError: true, message: 'Vos deux mots de passe sont différents !' };
|
||||||
return { hasError: false, message: '' };
|
return { hasError: false, message: '' };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -23,7 +23,7 @@ describe('<UserForm />', () => {
|
|||||||
password: 'test',
|
password: 'test',
|
||||||
passwordVerification: 'test'
|
passwordVerification: 'test'
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('username validation', () => {
|
describe('username validation', () => {
|
||||||
|
@ -16,15 +16,15 @@ export function WithForm(validators) {
|
|||||||
setFormErrors(formErrors => {
|
setFormErrors(formErrors => {
|
||||||
return { ...formErrors, [name]: { hasError: false, message: '' } };
|
return { ...formErrors, [name]: { hasError: false, message: '' } };
|
||||||
});
|
});
|
||||||
return
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
const value = formData[name];
|
const value = formData[name];
|
||||||
const result = validators[name](value, formData);
|
const result = validators[name](value, formData);
|
||||||
setFormErrors(formErrors => {
|
setFormErrors(formErrors => {
|
||||||
return { ...formErrors, [name]: result };
|
return { ...formErrors, [name]: result };
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Object.keys(formData).forEach(validateField);
|
Object.keys(formData).forEach(validateField);
|
||||||
@ -78,7 +78,7 @@ export function WithForm(validators) {
|
|||||||
|
|
||||||
return <Component form={form} {...props} />;
|
return <Component form={form} {...props} />;
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect(mapStateToProps)(MyComponent)
|
// connect(mapStateToProps)(MyComponent)
|
@ -2,7 +2,7 @@ export function MessageList({ messages }) {
|
|||||||
if (!Array.isArray(messages)) return null;
|
if (!Array.isArray(messages)) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="columns" style={{marginTop:"1em"}}>
|
<div className="columns" style={{marginTop:'1em'}}>
|
||||||
<div className="column is-4 is-offset-4">
|
<div className="column is-4 is-offset-4">
|
||||||
<div className="messages">
|
<div className="messages">
|
||||||
{
|
{
|
||||||
@ -13,7 +13,7 @@ export function MessageList({ messages }) {
|
|||||||
{m.text}
|
{m.text}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export class UnauthorizedError extends Error {
|
export class UnauthorizedError extends Error {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("Unauthorized");
|
super('Unauthorized');
|
||||||
Error.captureStackTrace(this, UnauthorizedError);
|
Error.captureStackTrace(this, UnauthorizedError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import ReactDOM from 'react-dom'
|
import ReactDOM from 'react-dom';
|
||||||
import { HotApp as App } from './app'
|
import { HotApp as App } from './app';
|
||||||
import { configureStore } from './store/store'
|
import { configureStore } from './store/store';
|
||||||
import { Provider } from 'react-redux'
|
import { Provider } from 'react-redux';
|
||||||
import 'bulma/css/bulma.min.css';
|
import 'bulma/css/bulma.min.css';
|
||||||
|
|
||||||
const store = configureStore()
|
const store = configureStore();
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<App />
|
<App />
|
||||||
</Provider>,
|
</Provider>,
|
||||||
document.getElementById('app')
|
document.getElementById('app')
|
||||||
)
|
);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect } from 'react'
|
import React, { useEffect } from 'react';
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux';
|
||||||
import Page from './page';
|
import Page from './page';
|
||||||
import ProjectList from '../components/ProjectList';
|
import ProjectList from '../components/ProjectList';
|
||||||
import { projectUserListRequest } from '../actions/project';
|
import { projectUserListRequest } from '../actions/project';
|
||||||
@ -7,8 +7,8 @@ import { projectUserListRequest } from '../actions/project';
|
|||||||
const DashBoardClient = ({ projects = [], ...props }) => {
|
const DashBoardClient = ({ projects = [], ...props }) => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
props.dispatch(projectUserListRequest())
|
props.dispatch(projectUserListRequest());
|
||||||
}, [])
|
}, []);
|
||||||
projects = [
|
projects = [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
@ -78,7 +78,7 @@ const DashBoardClient = ({ projects = [], ...props }) => {
|
|||||||
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
]
|
];
|
||||||
return (
|
return (
|
||||||
<Page title="dashBoard client">
|
<Page title="dashBoard client">
|
||||||
<div className="notification">
|
<div className="notification">
|
||||||
@ -87,11 +87,11 @@ const DashBoardClient = ({ projects = [], ...props }) => {
|
|||||||
<ProjectList projects={projects} withRequest />
|
<ProjectList projects={projects} withRequest />
|
||||||
</Page>
|
</Page>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
const mapStateToProps = ({ project }) => ({
|
const mapStateToProps = ({ project }) => ({
|
||||||
projects: project.items,
|
projects: project.items,
|
||||||
})
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(DashBoardClient)
|
export default connect(mapStateToProps)(DashBoardClient);
|
@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect } from 'react'
|
import React, { useEffect } from 'react';
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux';
|
||||||
import Page from './page';
|
import Page from './page';
|
||||||
import ProjectList from '../components/ProjectList';
|
import ProjectList from '../components/ProjectList';
|
||||||
import { projectList } from '../actions/project';
|
import { projectList } from '../actions/project';
|
||||||
@ -7,8 +7,8 @@ import { projectList } from '../actions/project';
|
|||||||
const DashBoardDev = ({ projects = [], ...props }) => {
|
const DashBoardDev = ({ projects = [], ...props }) => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
props.dispatch(projectList())
|
props.dispatch(projectList());
|
||||||
}, [])
|
}, []);
|
||||||
projects = [
|
projects = [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
@ -78,7 +78,7 @@ const DashBoardDev = ({ projects = [], ...props }) => {
|
|||||||
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
]
|
];
|
||||||
return (
|
return (
|
||||||
<Page title="dashBoard dev">
|
<Page title="dashBoard dev">
|
||||||
<div className="notification">
|
<div className="notification">
|
||||||
@ -87,11 +87,11 @@ const DashBoardDev = ({ projects = [], ...props }) => {
|
|||||||
<ProjectList projects={projects} />
|
<ProjectList projects={projects} />
|
||||||
</Page>
|
</Page>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
const mapStateToProps = ({ project }) => ({
|
const mapStateToProps = ({ project }) => ({
|
||||||
projects: project.items,
|
projects: project.items,
|
||||||
})
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(DashBoardDev)
|
export default connect(mapStateToProps)(DashBoardDev);
|
@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import React from 'react';
|
||||||
import Page from './page';
|
import Page from './page';
|
||||||
import { ExtendedUserForm as UserForm } from '../components/UserForm';
|
import { ExtendedUserForm as UserForm } from '../components/UserForm';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
@ -33,9 +33,9 @@ function transformErrorCode(code) {
|
|||||||
return {
|
return {
|
||||||
username: {
|
username: {
|
||||||
hasError: true,
|
hasError: true,
|
||||||
message: "Le nom d'utilisateur ne peut pas être vide. (API)"
|
message: 'Le nom d\'utilisateur ne peut pas être vide. (API)'
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ function transformErrorCode(code) {
|
|||||||
function mapStateToProps({ users }) {
|
function mapStateToProps({ users }) {
|
||||||
return {
|
return {
|
||||||
createUserFormError: transformErrorCode(users.createUserForm.errorCode),
|
createUserFormError: transformErrorCode(users.createUserForm.errorCode),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ConnectedHomePage = connect(mapStateToProps)(HomePage)
|
export const ConnectedHomePage = connect(mapStateToProps)(HomePage);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react';
|
||||||
import { ConnectedPage as Page } from './page';
|
import { ConnectedPage as Page } from './page';
|
||||||
import { login } from '../actions/auth.actions';
|
import { login } from '../actions/auth.actions';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
@ -13,7 +13,7 @@ export function LoginPage({ dispatch, isLoggedIn, history }) {
|
|||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
const { username, password } = formData;
|
const { username, password } = formData;
|
||||||
dispatch(login(username, password));
|
dispatch(login(username, password));
|
||||||
}
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isLoggedIn) history.push('/home');
|
if (isLoggedIn) history.push('/home');
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect } from 'react'
|
import React, { useEffect } from 'react';
|
||||||
import { logout } from '../actions/auth.actions';
|
import { logout } from '../actions/auth.actions';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { ConnectedPage as Page } from './page';
|
import { ConnectedPage as Page } from './page';
|
||||||
@ -16,7 +16,7 @@ export function LogoutPage({ dispatch }) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Page>
|
</Page>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ConnectedLogoutPage = connect()(LogoutPage);
|
export const ConnectedLogoutPage = connect()(LogoutPage);
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect } from 'react'
|
import React, { useEffect } from 'react';
|
||||||
import { MessageList } from '../components/message-list';
|
import { MessageList } from '../components/message-list';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { removeOldestMessage } from '../actions/message.actions';
|
import { removeOldestMessage } from '../actions/message.actions';
|
||||||
@ -16,7 +16,7 @@ export default function Page({ title, messages, dispatch, children }) {
|
|||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
return () => clearTimeout(timeoutId);
|
return () => clearTimeout(timeoutId);
|
||||||
}, [messages])
|
}, [messages]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container">
|
<div className="container">
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ADD_MESSAGE, REMOVE_OLDEST_MESSAGE } from "../actions/message.actions";
|
import { ADD_MESSAGE, REMOVE_OLDEST_MESSAGE } from '../actions/message.actions';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
sortedByTimestamp: []
|
sortedByTimestamp: []
|
||||||
@ -10,7 +10,7 @@ export function messagesReducer(state = initialState, action) {
|
|||||||
return handleAddMessage(state, action);
|
return handleAddMessage(state, action);
|
||||||
case REMOVE_OLDEST_MESSAGE:
|
case REMOVE_OLDEST_MESSAGE:
|
||||||
return handleRemoveOldestMessage(state, action);
|
return handleRemoveOldestMessage(state, action);
|
||||||
};
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,12 +21,12 @@ function handleAddMessage(state, action) {
|
|||||||
{ ts: Date.now(), text: action.text, type: action.messageType },
|
{ ts: Date.now(), text: action.text, type: action.messageType },
|
||||||
...state.sortedByTimestamp
|
...state.sortedByTimestamp
|
||||||
]
|
]
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function handleRemoveOldestMessage(state, action) {
|
function handleRemoveOldestMessage(state, action) {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
sortedByTimestamp: state.sortedByTimestamp.slice(0, -1)
|
sortedByTimestamp: state.sortedByTimestamp.slice(0, -1)
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
}
|
@ -1,15 +1,15 @@
|
|||||||
import {
|
import {
|
||||||
PROJECT_USER_LIST_SUCCESS,
|
PROJECT_USER_LIST_SUCCESS,
|
||||||
PROJECT_USER_LIST_FAILURE
|
PROJECT_USER_LIST_FAILURE
|
||||||
} from '../actions/project'
|
} from '../actions/project';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
items: []
|
items: []
|
||||||
}
|
};
|
||||||
|
|
||||||
export default (state = initialState, action) => {
|
export default (state = initialState, action) => {
|
||||||
|
|
||||||
console.log(`Action: ${JSON.stringify(action)}`)
|
console.log(`Action: ${JSON.stringify(action)}`);
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
|
||||||
@ -17,15 +17,15 @@ export default (state = initialState, action) => {
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
items: action.projects
|
items: action.projects
|
||||||
}
|
};
|
||||||
case PROJECT_USER_LIST_FAILURE:
|
case PROJECT_USER_LIST_FAILURE:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
items: [],
|
items: [],
|
||||||
error: action.error
|
error: action.error
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
return state
|
return state;
|
||||||
|
|
||||||
}
|
};
|
@ -1,4 +1,4 @@
|
|||||||
import { LOGIN_SUCCESS, LOGOUT_SUCCESS } from "../actions/auth.actions";
|
import { LOGIN_SUCCESS, LOGOUT_SUCCESS } from '../actions/auth.actions';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
@ -11,7 +11,7 @@ export function sessionReducer(state = initialState, action) {
|
|||||||
return handleLoginSuccess(state, action);
|
return handleLoginSuccess(state, action);
|
||||||
case LOGOUT_SUCCESS:
|
case LOGOUT_SUCCESS:
|
||||||
return handleLogoutSuccess(state, action);
|
return handleLogoutSuccess(state, action);
|
||||||
};
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,13 +22,13 @@ function handleLoginSuccess(state, action) {
|
|||||||
user: {
|
user: {
|
||||||
username: action.username,
|
username: action.username,
|
||||||
},
|
},
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function handleLogoutSuccess(state, action) {
|
function handleLogoutSuccess(state, action) {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
user: null,
|
user: null,
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import { CREATE_USER_FAILURE } from "../actions/user.actions";
|
import { CREATE_USER_FAILURE } from '../actions/user.actions';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
byId: {},
|
byId: {},
|
||||||
@ -9,7 +9,7 @@ export function usersReducer(state = initialState, action) {
|
|||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case CREATE_USER_FAILURE:
|
case CREATE_USER_FAILURE:
|
||||||
return handleCreateUserFailure(state, action);
|
return handleCreateUserFailure(state, action);
|
||||||
};
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,20 +11,20 @@ export function* loginSaga(action) {
|
|||||||
result = yield call(client.login, action.username, action.password);
|
result = yield call(client.login, action.username, action.password);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
if (err instanceof UnauthorizedError) {
|
if (err instanceof UnauthorizedError) {
|
||||||
yield put(addMessage('warning', "Identifiants invalides."));
|
yield put(addMessage('warning', 'Identifiants invalides.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield put(loginFailure(action.username, err));
|
yield put(loginFailure(action.username, err));
|
||||||
yield put(addMessage('danger', "Une erreur inconnue bloque le fonctionnement normal de l'application. Veuillez réessayer plus tard."));
|
yield put(addMessage('danger', 'Une erreur inconnue bloque le fonctionnement normal de l\'application. Veuillez réessayer plus tard.'));
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('error' in result) {
|
if ('error' in result) {
|
||||||
yield put(loginFailure(action.username, result.error));
|
yield put(loginFailure(action.username, result.error));
|
||||||
const message = result.error.message ? result.error.message : result.error.toString();
|
const message = result.error.message ? result.error.message : result.error.toString();
|
||||||
yield put(addMessage('danger', message));
|
yield put(addMessage('danger', message));
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield put(loginSuccess(action.username));
|
yield put(loginSuccess(action.username));
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { history } from "../../util/history";
|
import { history } from '../../util/history';
|
||||||
import { addMessage } from '../../actions/message.actions';
|
import { addMessage } from '../../actions/message.actions';
|
||||||
import { put } from 'redux-saga/effects';
|
import { put } from 'redux-saga/effects';
|
||||||
|
|
||||||
export function* logoutRedirectSaga() {
|
export function* logoutRedirectSaga() {
|
||||||
yield put(addMessage("success", "Vous êtes déconnecté."));
|
yield put(addMessage('success', 'Vous êtes déconnecté.'));
|
||||||
history.push('/login');
|
history.push('/login');
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { APIClient } from "../../services/api-client.service";
|
import { APIClient } from '../../services/api-client.service';
|
||||||
import { logoutFailure, logoutSuccess } from "../../actions/auth.actions";
|
import { logoutFailure, logoutSuccess } from '../../actions/auth.actions';
|
||||||
import { addMessage } from "../../actions/message.actions";
|
import { addMessage } from '../../actions/message.actions';
|
||||||
import { call, put } from 'redux-saga/effects';
|
import { call, put } from 'redux-saga/effects';
|
||||||
|
|
||||||
export function* logoutSaga() {
|
export function* logoutSaga() {
|
||||||
@ -10,7 +10,7 @@ export function* logoutSaga() {
|
|||||||
result = yield call(client.logout);
|
result = yield call(client.logout);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
yield put(logoutFailure(err));
|
yield put(logoutFailure(err));
|
||||||
yield put(addMessage('danger', "Une erreur inconnue bloque le fonctionnement normal de l'application. Veuillez réessayer plus tard."));
|
yield put(addMessage('danger', 'Une erreur inconnue bloque le fonctionnement normal de l\'application. Veuillez réessayer plus tard.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ export function* logoutSaga() {
|
|||||||
yield put(logoutFailure(result.error));
|
yield put(logoutFailure(result.error));
|
||||||
const message = result.error.message ? result.error.message : result.error.toString();
|
const message = result.error.message ? result.error.message : result.error.toString();
|
||||||
yield put(addMessage('danger', message));
|
yield put(addMessage('danger', message));
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield put(logoutSuccess());
|
yield put(logoutSuccess());
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { LOGIN_REQUEST, LOGOUT_REQUEST, LOGOUT_SUCCESS } from "../../actions/auth.actions";
|
import { LOGIN_REQUEST, LOGOUT_REQUEST, LOGOUT_SUCCESS } from '../../actions/auth.actions';
|
||||||
import { loginSaga } from "./login.saga";
|
import { loginSaga } from './login.saga';
|
||||||
import { logoutSaga } from "./logout.saga";
|
import { logoutSaga } from './logout.saga';
|
||||||
import { logoutRedirectSaga } from "./logout-redirect.saga";
|
import { logoutRedirectSaga } from './logout-redirect.saga';
|
||||||
import { all, takeLatest } from 'redux-saga/effects';
|
import { all, takeLatest } from 'redux-saga/effects';
|
||||||
|
|
||||||
export function * rootSaga() {
|
export function * rootSaga() {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { failureActionSaga } from "./failure.saga";
|
import { failureActionSaga } from './failure.saga';
|
||||||
import { takeLatest, all } from "redux-saga/effects";
|
import { takeLatest, all } from 'redux-saga/effects';
|
||||||
|
|
||||||
export function * rootSaga(action) {
|
export function * rootSaga(action) {
|
||||||
yield all([
|
yield all([
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { all } from 'redux-saga/effects';
|
import { all } from 'redux-saga/effects';
|
||||||
import { checkSessionSaga } from './session.saga';
|
import { refreshSessionSaga } from './session.saga';
|
||||||
|
|
||||||
export function* rootSaga() {
|
export function* rootSaga() {
|
||||||
yield all([
|
yield all([
|
||||||
checkSessionSaga(),
|
refreshSessionSaga(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import { APIClient } from '../../services/api-client.service';
|
import { APIClient } from '../../services/api-client.service';
|
||||||
import { call } from 'redux-saga/effects';
|
import { call, put } from 'redux-saga/effects';
|
||||||
|
import { refreshUserSessionFailure, refreshUserSessionSuccess } from '../../actions/auth.actions';
|
||||||
|
|
||||||
export function* checkSessionSaga() {
|
export function* refreshSessionSaga() {
|
||||||
const client = new APIClient();
|
const client = new APIClient();
|
||||||
|
let user;
|
||||||
try {
|
try {
|
||||||
yield call(client.retrieveSessionUser);
|
user = yield call(client.retrieveSessionUser);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.error(err);
|
yield put(refreshUserSessionFailure(err));
|
||||||
}
|
}
|
||||||
|
yield put(refreshUserSessionSuccess(user));
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,17 @@ import { call, put } from 'redux-saga/effects';
|
|||||||
import { projectUserListFailure, projectUserListSuccess, projectListFailure, projectListSuccess } from '../actions/project';
|
import { projectUserListFailure, projectUserListSuccess, projectListFailure, projectListSuccess } from '../actions/project';
|
||||||
|
|
||||||
export function* projectUserListSaga() {
|
export function* projectUserListSaga() {
|
||||||
let result
|
let result;
|
||||||
try {
|
try {
|
||||||
result = yield call(projectUserList);
|
result = yield call(projectUserList);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
yield put(projectUserListFailure(err));
|
yield put(projectUserListFailure(err));
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('error' in result) {
|
if ('error' in result) {
|
||||||
yield put(projectUserListFailure(result.error));
|
yield put(projectUserListFailure(result.error));
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield put(projectUserListSuccess(result.data));
|
yield put(projectUserListSuccess(result.data));
|
||||||
@ -23,22 +23,22 @@ const projectUserList = () => {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
}).then(res => res.json())
|
}).then(res => res.json());
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
export function* projectListSaga() {
|
export function* projectListSaga() {
|
||||||
let result
|
let result;
|
||||||
try {
|
try {
|
||||||
result = yield call(projectList);
|
result = yield call(projectList);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
yield put(projectListFailure(err));
|
yield put(projectListFailure(err));
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('error' in result) {
|
if ('error' in result) {
|
||||||
yield put(projectListFailure(result.error));
|
yield put(projectListFailure(result.error));
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield put(projectListSuccess(result.data));
|
yield put(projectListSuccess(result.data));
|
||||||
@ -49,5 +49,5 @@ const projectList = () => {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
credentials: 'include'
|
credentials: 'include'
|
||||||
}).then(res => res.json())
|
}).then(res => res.json());
|
||||||
}
|
};
|
@ -10,7 +10,7 @@ export function* createUserSaga({username, password}) {
|
|||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
yield put(createUserFailure(err));
|
yield put(createUserFailure(err));
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield put(createUserSuccess(user));
|
yield put(createUserSuccess(user));
|
||||||
|
@ -20,7 +20,7 @@ export class APIClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logout() {
|
logout() {
|
||||||
return this._callAPI('/logout')
|
return this._callAPI('/logout');
|
||||||
}
|
}
|
||||||
|
|
||||||
retrieveSessionUser() {
|
retrieveSessionUser() {
|
||||||
@ -29,7 +29,7 @@ export class APIClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
listUsers() {
|
listUsers() {
|
||||||
return this._callAPI('/users')
|
return this._callAPI('/users');
|
||||||
}
|
}
|
||||||
|
|
||||||
listRequests() {
|
listRequests() {
|
||||||
@ -61,7 +61,7 @@ export class APIClient {
|
|||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
})
|
})
|
||||||
.then(this._withUnauthorizedErrorMiddleware())
|
.then(this._withUnauthorizedErrorMiddleware())
|
||||||
.then(res => res.json())
|
.then(res => res.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
_withUnauthorizedErrorMiddleware() {
|
_withUnauthorizedErrorMiddleware() {
|
||||||
@ -70,7 +70,7 @@ export class APIClient {
|
|||||||
throw new UnauthorizedError();
|
throw new UnauthorizedError();
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
_withAPIErrorMiddleware(endpoint) {
|
_withAPIErrorMiddleware(endpoint) {
|
||||||
@ -80,7 +80,7 @@ export class APIClient {
|
|||||||
throw new APIError(endpoint, code, message, data);
|
throw new APIError(endpoint, code, message, data);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { createStore, applyMiddleware, combineReducers, compose } from 'redux'
|
import { createStore, applyMiddleware, combineReducers, compose } from 'redux';
|
||||||
import createSagaMiddleware from 'redux-saga'
|
import createSagaMiddleware from 'redux-saga';
|
||||||
import rootSaga from '../sagas/root'
|
import rootSaga from '../sagas/root';
|
||||||
import { sessionReducer } from '../reducers/session.reducers';
|
import { sessionReducer } from '../reducers/session.reducers';
|
||||||
import { messagesReducer } from '../reducers/messages.reducers';
|
import { messagesReducer } from '../reducers/messages.reducers';
|
||||||
import project from '../reducers/project'
|
import project from '../reducers/project';
|
||||||
import { usersReducer } from '../reducers/users.reducers';
|
import { usersReducer } from '../reducers/users.reducers';
|
||||||
|
|
||||||
const sagaMiddleware = createSagaMiddleware()
|
const sagaMiddleware = createSagaMiddleware();
|
||||||
|
|
||||||
const rootReducer = combineReducers({
|
const rootReducer = combineReducers({
|
||||||
session: sessionReducer,
|
session: sessionReducer,
|
||||||
@ -24,7 +24,7 @@ export function configureStore(initialState = {}) {
|
|||||||
composeEnhancers(
|
composeEnhancers(
|
||||||
applyMiddleware(sagaMiddleware)
|
applyMiddleware(sagaMiddleware)
|
||||||
)
|
)
|
||||||
)
|
);
|
||||||
sagaMiddleware.run(rootSaga);
|
sagaMiddleware.run(rootSaga);
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user