From 0912ea5efc3708cc53a3d015811cbd81f36e073d Mon Sep 17 00:00:00 2001 From: Aman Ibrahim Date: Thu, 26 Sep 2019 09:32:27 -0400 Subject: [PATCH 1/4] Moved files to appropriate placements --- app/{redux => }/actions/login.js | 0 app/{redux => }/actions/posts.js | 0 app/actions/shifts.js | 78 ++++++++++++++++++ app/{redux => }/actions/team.js | 0 app/{redux => }/actions/user.js | 0 app/{redux => }/actions/utils/crud.js | 0 .../components/HomeTabs}/Availabilty/index.js | 0 .../components/HomeTabs}/Calendar/Group.js | 0 .../components/HomeTabs}/Calendar/Personal.js | 0 .../components/HomeTabs}/Settings/index.js | 0 .../components/HomeTabs}/index.js | 0 {Login => app/components/Login}/LoginForm.js | 0 {UI => app/components/general}/Button.js | 0 {UI => app/components/general}/EditText.js | 0 {UI => app/components/general}/index.js | 0 App.js => app/containers/App.js | 2 +- Login/index.js => app/containers/Login.js | 0 {assets => app}/images/logo.png | Bin Home.js => app/index.js | 6 +- app/{redux => }/reducers/index.js | 0 app/{redux => }/reducers/login.js | 0 app/{redux => }/reducers/posts.js | 0 app/{redux => }/reducers/shifts.js | 0 app/{redux => }/reducers/team.js | 0 app/{redux => }/reducers/user.js | 0 app/redux/actions/shifts.js | 73 ---------------- index.js | 8 +- 27 files changed, 85 insertions(+), 82 deletions(-) rename app/{redux => }/actions/login.js (100%) rename app/{redux => }/actions/posts.js (100%) create mode 100644 app/actions/shifts.js rename app/{redux => }/actions/team.js (100%) rename app/{redux => }/actions/user.js (100%) rename app/{redux => }/actions/utils/crud.js (100%) rename {HomeTabs => app/components/HomeTabs}/Availabilty/index.js (100%) rename {HomeTabs => app/components/HomeTabs}/Calendar/Group.js (100%) rename {HomeTabs => app/components/HomeTabs}/Calendar/Personal.js (100%) rename {HomeTabs => app/components/HomeTabs}/Settings/index.js (100%) rename {HomeTabs => app/components/HomeTabs}/index.js (100%) rename {Login => app/components/Login}/LoginForm.js (100%) rename {UI => app/components/general}/Button.js (100%) rename {UI => app/components/general}/EditText.js (100%) rename {UI => app/components/general}/index.js (100%) rename App.js => app/containers/App.js (80%) rename Login/index.js => app/containers/Login.js (100%) rename {assets => app}/images/logo.png (100%) rename Home.js => app/index.js (73%) rename app/{redux => }/reducers/index.js (100%) rename app/{redux => }/reducers/login.js (100%) rename app/{redux => }/reducers/posts.js (100%) rename app/{redux => }/reducers/shifts.js (100%) rename app/{redux => }/reducers/team.js (100%) rename app/{redux => }/reducers/user.js (100%) delete mode 100644 app/redux/actions/shifts.js diff --git a/app/redux/actions/login.js b/app/actions/login.js similarity index 100% rename from app/redux/actions/login.js rename to app/actions/login.js diff --git a/app/redux/actions/posts.js b/app/actions/posts.js similarity index 100% rename from app/redux/actions/posts.js rename to app/actions/posts.js diff --git a/app/actions/shifts.js b/app/actions/shifts.js new file mode 100644 index 00000000..8a4b2c4a --- /dev/null +++ b/app/actions/shifts.js @@ -0,0 +1,78 @@ +// @flow + +import crud from './utils/crud'; + +const getAllShifts = () => + crud({ + dispatch: { + begin: 'BEGIN_GET_SHIFTS', + end: 'END_GET_SHIFTS', + fail: 'FAILED_GET_SHIFTS', + }, + method: 'GET', + url: '/api/v1/shifts', + }); + +const updateShift = (id, data) => + crud({ + dispatch: { + begin: 'BEGIN_PUT_SHIFT', + end: 'END_PUT_SHIFT', + fail: 'FAILED_PUT_SHIFT', + }, + method: 'PUT', + url: `/api/v1/shifts/${id}`, + data, + }); + +const createShift = data => + crud({ + dispatch: { + begin: 'BEGIN_POST_SHIFT', + end: 'END_POST_SHIFT', + fail: 'FAILED_POST_SHIFT', + }, + method: 'POST', + url: '/api/v1/shifts', + data, + }); + +const deleteShift = id => + crud({ + dispatch: { + begin: 'BEGIN_DELETE_SHIFT', + end: 'END_DELETE_SHIFT', + fail: 'FAILED_DELETE_SHIFT', + }, + method: 'DELETE', + url: `/api/v1/shifts/${id}`, + }); + +const addUserToShift = (userID, shiftID) => + crud({ + dispatch: { + begin: 'BEGIN_POST_SHIFT', + end: 'END_POST_SHIFT', + fail: 'FAILED_POST_SHIFT', + }, + method: 'POST', + url: '/api/v1/user/shifts', + data: { + user_id: userID, + shift_id: shiftID, + }, + }); + +const dragDropUpdate = (oldShifts, newShift) => { + // NOTE: There is both a oldShift and oldShifts variable and the same for newShift and newShifts + const oldShift = oldShifts.find(shift => shift.id === newShift.id); + const index = oldShifts.indexOf(oldShift); + const newShifts = [...oldShifts]; + newShifts.splice(index, 1, newShift); + return { + type: 'DRAG_DROP', + payload: newShifts, + }; +}; + +export { getAllShifts, updateShift, createShift, deleteShift, addUserToShift, dragDropUpdate }; diff --git a/app/redux/actions/team.js b/app/actions/team.js similarity index 100% rename from app/redux/actions/team.js rename to app/actions/team.js diff --git a/app/redux/actions/user.js b/app/actions/user.js similarity index 100% rename from app/redux/actions/user.js rename to app/actions/user.js diff --git a/app/redux/actions/utils/crud.js b/app/actions/utils/crud.js similarity index 100% rename from app/redux/actions/utils/crud.js rename to app/actions/utils/crud.js diff --git a/HomeTabs/Availabilty/index.js b/app/components/HomeTabs/Availabilty/index.js similarity index 100% rename from HomeTabs/Availabilty/index.js rename to app/components/HomeTabs/Availabilty/index.js diff --git a/HomeTabs/Calendar/Group.js b/app/components/HomeTabs/Calendar/Group.js similarity index 100% rename from HomeTabs/Calendar/Group.js rename to app/components/HomeTabs/Calendar/Group.js diff --git a/HomeTabs/Calendar/Personal.js b/app/components/HomeTabs/Calendar/Personal.js similarity index 100% rename from HomeTabs/Calendar/Personal.js rename to app/components/HomeTabs/Calendar/Personal.js diff --git a/HomeTabs/Settings/index.js b/app/components/HomeTabs/Settings/index.js similarity index 100% rename from HomeTabs/Settings/index.js rename to app/components/HomeTabs/Settings/index.js diff --git a/HomeTabs/index.js b/app/components/HomeTabs/index.js similarity index 100% rename from HomeTabs/index.js rename to app/components/HomeTabs/index.js diff --git a/Login/LoginForm.js b/app/components/Login/LoginForm.js similarity index 100% rename from Login/LoginForm.js rename to app/components/Login/LoginForm.js diff --git a/UI/Button.js b/app/components/general/Button.js similarity index 100% rename from UI/Button.js rename to app/components/general/Button.js diff --git a/UI/EditText.js b/app/components/general/EditText.js similarity index 100% rename from UI/EditText.js rename to app/components/general/EditText.js diff --git a/UI/index.js b/app/components/general/index.js similarity index 100% rename from UI/index.js rename to app/components/general/index.js diff --git a/App.js b/app/containers/App.js similarity index 80% rename from App.js rename to app/containers/App.js index 5d4d0924..0edae72f 100644 --- a/App.js +++ b/app/containers/App.js @@ -5,7 +5,7 @@ import React, { Component } from 'react'; import { createBottomTabNavigator } from 'react-navigation'; // ui -import { Personal, Group, Settings, Availability } from './HomeTabs'; +import { Personal, Group, Settings, Availability } from './components/HomeTabs'; import Login from './Login'; const Home = createBottomTabNavigator({ diff --git a/Login/index.js b/app/containers/Login.js similarity index 100% rename from Login/index.js rename to app/containers/Login.js diff --git a/assets/images/logo.png b/app/images/logo.png similarity index 100% rename from assets/images/logo.png rename to app/images/logo.png diff --git a/Home.js b/app/index.js similarity index 73% rename from Home.js rename to app/index.js index 000f9b2f..1811810a 100644 --- a/Home.js +++ b/app/index.js @@ -7,14 +7,14 @@ import { Provider } from 'react-redux'; import { createStore, combineReducers } from 'redux'; // reducers -import * as allReducers from './app/redux/reducers'; +import * as allReducers from './reducers'; // ui -import App from './App'; +import App from './containers/App'; const store = createStore(combineReducers(allReducers)); -export default class Home extends Component { +export default class GTHC extends Component { render() { return ( diff --git a/app/redux/reducers/index.js b/app/reducers/index.js similarity index 100% rename from app/redux/reducers/index.js rename to app/reducers/index.js diff --git a/app/redux/reducers/login.js b/app/reducers/login.js similarity index 100% rename from app/redux/reducers/login.js rename to app/reducers/login.js diff --git a/app/redux/reducers/posts.js b/app/reducers/posts.js similarity index 100% rename from app/redux/reducers/posts.js rename to app/reducers/posts.js diff --git a/app/redux/reducers/shifts.js b/app/reducers/shifts.js similarity index 100% rename from app/redux/reducers/shifts.js rename to app/reducers/shifts.js diff --git a/app/redux/reducers/team.js b/app/reducers/team.js similarity index 100% rename from app/redux/reducers/team.js rename to app/reducers/team.js diff --git a/app/redux/reducers/user.js b/app/reducers/user.js similarity index 100% rename from app/redux/reducers/user.js rename to app/reducers/user.js diff --git a/app/redux/actions/shifts.js b/app/redux/actions/shifts.js deleted file mode 100644 index 258e0542..00000000 --- a/app/redux/actions/shifts.js +++ /dev/null @@ -1,73 +0,0 @@ -// @flow - -import crud from './utils/crud'; - -const getAllShifts = () => crud({ - dispatch: { - begin: 'BEGIN_GET_SHIFTS', - end: 'END_GET_SHIFTS', - fail: 'FAILED_GET_SHIFTS', - }, - method: 'GET', - url: '/api/v1/shifts', -}); - -const updateShift = (id, data) => crud({ - dispatch: { - begin: 'BEGIN_PUT_SHIFT', - end: 'END_PUT_SHIFT', - fail: 'FAILED_PUT_SHIFT', - }, - method: 'PUT', - url: `/api/v1/shifts/${id}`, - data, -}); - -const createShift = data => crud({ - dispatch: { - begin: 'BEGIN_POST_SHIFT', - end: 'END_POST_SHIFT', - fail: 'FAILED_POST_SHIFT', - }, - method: 'POST', - url: '/api/v1/shifts', - data, -}); - -const deleteShift = id => crud({ - dispatch: { - begin: 'BEGIN_DELETE_SHIFT', - end: 'END_DELETE_SHIFT', - fail: 'FAILED_DELETE_SHIFT', - }, - method: 'DELETE', - url: `/api/v1/shifts/${id}`, -}); - -const addUserToShift = (userID, shiftID) => crud({ - dispatch: { - begin: 'BEGIN_POST_SHIFT', - end: 'END_POST_SHIFT', - fail: 'FAILED_POST_SHIFT', - }, - method: 'POST', - url: '/api/v1/user/shifts', - data: { - user_id: userID, - shift_id: shiftID, - }, -}); - -const dragDropUpdate = (oldShifts, newShift) => { - // NOTE: There is both a oldShift and oldShifts variable and the same for newShift and newShifts - const oldShift = oldShifts.find(shift => shift.id === newShift.id); - const index = oldShifts.indexOf(oldShift); - const newShifts = [...oldShifts]; - newShifts.splice(index, 1, newShift); - return { - type: 'DRAG_DROP', - payload: newShifts, - }; -}; - -export { getAllShifts, updateShift, createShift, deleteShift, addUserToShift, dragDropUpdate }; diff --git a/index.js b/index.js index e06bb94a..ac58196d 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,6 @@ /** @format */ - import { AppRegistry } from 'react-native'; -import Home from './Home'; -import Login from './Login'; -AppRegistry.registerComponent('GTHC', () => Home); -AppRegistry.registerComponent('Login', () => Login); +import GTHC from './app'; + +AppRegistry.registerComponent('GTHC', () => GTHC); From 8a57b1118c5ee6e8182581f0efad95925760f756 Mon Sep 17 00:00:00 2001 From: Aman Ibrahim Date: Thu, 26 Sep 2019 09:46:04 -0400 Subject: [PATCH 2/4] Fixed linter issues --- .eslintrc | 1 + app/components/Login/LoginForm.js | 2 +- app/containers/App.js | 16 ++++++++-------- app/containers/Login.js | 32 +++++++++++++++++-------------- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/.eslintrc b/.eslintrc index 8551c203..20f1ff77 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,6 +8,7 @@ "import" ], "rules": { + "arrow-parens": "off", "import/prefer-default-export": "off", "react/require-default-props": "off", "object-curly-newline": "off", diff --git a/app/components/Login/LoginForm.js b/app/components/Login/LoginForm.js index 615a3d7b..7668444c 100644 --- a/app/components/Login/LoginForm.js +++ b/app/components/Login/LoginForm.js @@ -3,7 +3,7 @@ import React, { Component } from 'react'; import { View, StyleSheet } from 'react-native'; -import { EditText, Button } from '../UI'; +import { EditText, Button } from '../general'; export default class LoginForm extends Component { render() { diff --git a/app/containers/App.js b/app/containers/App.js index 0edae72f..3b6442b5 100644 --- a/app/containers/App.js +++ b/app/containers/App.js @@ -2,18 +2,18 @@ import React, { Component } from 'react'; -import { createBottomTabNavigator } from 'react-navigation'; +// import { createBottomTabNavigator } from 'react-navigation'; // ui -import { Personal, Group, Settings, Availability } from './components/HomeTabs'; +// import { Personal, Group, Settings, Availability } from '../components/HomeTabs'; import Login from './Login'; -const Home = createBottomTabNavigator({ - Personal, - Group, - Settings, - Availability, -}); +// const Home = createBottomTabNavigator({ +// Personal, +// Group, +// Settings, +// Availability, +// }); export default class App extends Component { render() { diff --git a/app/containers/Login.js b/app/containers/Login.js index 38e923d2..7c19e001 100644 --- a/app/containers/Login.js +++ b/app/containers/Login.js @@ -3,20 +3,24 @@ import React, { Component } from 'react'; import { KeyboardAvoidingView, View, StyleSheet, Image } from 'react-native'; -// ui -import LoginForm from './LoginForm'; - -type Props = { - // TODO(anesu): Add more accurate types - login: any, - user: any, - loginUser: any, - clearError: any, -}; - -export default class Login extends Component { +// components +import LoginForm from '../components/Login/LoginForm'; + +// images +import * as logo from '../images/logo.png'; + +// type Props = { +// // TODO(anesu): Add more accurate types +// login: any, +// user: any, +// loginUser: any, +// clearError: any, +// }; + +export default class Login extends Component /* */ { render() { - const { login, user, loginUser, clearError } = this.props; + // TODO: Use variables below + // const { login, user, loginUser, clearError } = this.props; return ( @@ -25,7 +29,7 @@ export default class Login extends Component { resizeMode="contain" style={styles.logo} // eslint-disable-next-line global-require - source={require('../assets/images/logo.png')} + source={logo} /> From e9e4b55ce9d557e914faaa0b717181c8a5dea7c4 Mon Sep 17 00:00:00 2001 From: Aman Ibrahim Date: Thu, 26 Sep 2019 10:46:40 -0400 Subject: [PATCH 3/4] Updated flow configurations for actions and reducers --- .eslintrc | 1 + .flowconfig | 3 +++ app/reducers/index.js | 2 -- app/reducers/login.js | 2 -- app/reducers/posts.js | 2 -- app/reducers/shifts.js | 2 -- app/reducers/team.js | 2 -- app/reducers/user.js | 2 -- 8 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.eslintrc b/.eslintrc index 20f1ff77..6bb5c1e0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,6 +9,7 @@ ], "rules": { "arrow-parens": "off", + "implicit-arrow-linebreak": "off", "import/prefer-default-export": "off", "react/require-default-props": "off", "object-curly-newline": "off", diff --git a/.flowconfig b/.flowconfig index 1043c82d..644866b7 100644 --- a/.flowconfig +++ b/.flowconfig @@ -19,6 +19,9 @@ ; Ignore metro .*/node_modules/metro/.* +; Ignore redux +.*/app/actions/* + [include] [libs] diff --git a/app/reducers/index.js b/app/reducers/index.js index 4b34ea11..3108692d 100644 --- a/app/reducers/index.js +++ b/app/reducers/index.js @@ -1,5 +1,3 @@ -// @flow - export { default as user } from './user'; export { default as login } from './login'; export { default as shifts } from './shifts'; diff --git a/app/reducers/login.js b/app/reducers/login.js index 863efd04..43e98edd 100644 --- a/app/reducers/login.js +++ b/app/reducers/login.js @@ -1,5 +1,3 @@ -// @flow - const initialState = { type: 'login', // login or signup signUpData: { diff --git a/app/reducers/posts.js b/app/reducers/posts.js index 9a641b06..2f7b171e 100644 --- a/app/reducers/posts.js +++ b/app/reducers/posts.js @@ -1,5 +1,3 @@ -// @flow - const initialState = { data: [], isLoading: false, diff --git a/app/reducers/shifts.js b/app/reducers/shifts.js index 230db6f9..3b78bf06 100644 --- a/app/reducers/shifts.js +++ b/app/reducers/shifts.js @@ -1,5 +1,3 @@ -// @flow - const initialState = { team_shifts: [], user_shifts: [], diff --git a/app/reducers/team.js b/app/reducers/team.js index c115831d..0d0a5031 100644 --- a/app/reducers/team.js +++ b/app/reducers/team.js @@ -1,5 +1,3 @@ -// @flow - const initialState = { data: {}, isLoading: false, diff --git a/app/reducers/user.js b/app/reducers/user.js index 66511a7e..375a621c 100644 --- a/app/reducers/user.js +++ b/app/reducers/user.js @@ -1,5 +1,3 @@ -// @flow - const initialState = { data: {}, isLoggedIn: false, From 6efb5ba073a8cb520674617f7aa231cf16b83b97 Mon Sep 17 00:00:00 2001 From: Aman Ibrahim Date: Thu, 26 Sep 2019 11:05:43 -0400 Subject: [PATCH 4/4] Fix flow errors --- .eslintrc | 1 + app/components/Login/LoginForm.js | 4 +++- app/components/general/EditText.js | 5 ++--- app/containers/App.js | 4 +++- app/containers/Login.js | 20 ++++++++++---------- app/index.js | 4 +++- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/.eslintrc b/.eslintrc index 6bb5c1e0..b0f06a7b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -10,6 +10,7 @@ "rules": { "arrow-parens": "off", "implicit-arrow-linebreak": "off", + "react/no-unused-prop-types": "off", "import/prefer-default-export": "off", "react/require-default-props": "off", "object-curly-newline": "off", diff --git a/app/components/Login/LoginForm.js b/app/components/Login/LoginForm.js index 7668444c..ebe3ef86 100644 --- a/app/components/Login/LoginForm.js +++ b/app/components/Login/LoginForm.js @@ -5,7 +5,9 @@ import { View, StyleSheet } from 'react-native'; import { EditText, Button } from '../general'; -export default class LoginForm extends Component { +type Props = {}; // TODO: Add props + +export default class LoginForm extends Component { render() { return ( diff --git a/app/components/general/EditText.js b/app/components/general/EditText.js index 36aecf03..8c13a267 100644 --- a/app/components/general/EditText.js +++ b/app/components/general/EditText.js @@ -3,9 +3,8 @@ import React, { Component } from 'react'; import { TextInput, StyleSheet } from 'react-native'; -type Props = { +type Props = TextInput.propTypes & { placeholder: string, - keyboardType?: boolean, secureTextEntry?: boolean, }; @@ -16,7 +15,7 @@ export default class EditText extends Component { this.passwordInput.focus()} + // onSubmitEditing={() => this.passwordInput.focus()} autoCorrect={false} keyboardType={keyboardType || 'default'} returnKeyType="next" diff --git a/app/containers/App.js b/app/containers/App.js index 3b6442b5..aabf6e0a 100644 --- a/app/containers/App.js +++ b/app/containers/App.js @@ -15,7 +15,9 @@ import Login from './Login'; // Availability, // }); -export default class App extends Component { +type Props = {}; // TODO: Add props + +export default class App extends Component { render() { return ; } diff --git a/app/containers/Login.js b/app/containers/Login.js index 7c19e001..33cc0e8e 100644 --- a/app/containers/Login.js +++ b/app/containers/Login.js @@ -9,15 +9,15 @@ import LoginForm from '../components/Login/LoginForm'; // images import * as logo from '../images/logo.png'; -// type Props = { -// // TODO(anesu): Add more accurate types -// login: any, -// user: any, -// loginUser: any, -// clearError: any, -// }; - -export default class Login extends Component /* */ { +type Props = { + // TODO(anesu): Add more accurate types + login?: any, + user?: any, + loginUser?: any, + clearError?: any, +}; + +export default class Login extends Component { render() { // TODO: Use variables below // const { login, user, loginUser, clearError } = this.props; @@ -33,7 +33,7 @@ export default class Login extends Component /* */ { /> - + diff --git a/app/index.js b/app/index.js index 1811810a..e3f1e4fe 100644 --- a/app/index.js +++ b/app/index.js @@ -14,7 +14,9 @@ import App from './containers/App'; const store = createStore(combineReducers(allReducers)); -export default class GTHC extends Component { +type Props = {}; // TODO: Add props + +export default class GTHC extends Component { render() { return (