Compare commits
No commits in common. "db967006933c60346261b49e669c89608453b8ab" and "dc3a49ee6cd85efb10393f04ea700db2d34a101e" have entirely different histories.
db96700693
...
dc3a49ee6c
10 changed files with 207 additions and 529 deletions
|
|
@ -65,64 +65,84 @@ test('recoverLogin success saved', () => {
|
|||
|
||||
test('isRequestResponseValid', () => {
|
||||
let json = {
|
||||
error: 0,
|
||||
state: true,
|
||||
data: {}
|
||||
};
|
||||
expect(c.isResponseValid(json)).toBeTrue();
|
||||
expect(c.isRequestResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
error: 1,
|
||||
state: false,
|
||||
data: {}
|
||||
};
|
||||
expect(c.isResponseValid(json)).toBeTrue();
|
||||
expect(c.isRequestResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
error: 50,
|
||||
data: {}
|
||||
};
|
||||
expect(c.isResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
error: 50,
|
||||
state: false,
|
||||
message: 'coucou',
|
||||
data: {truc: 'machin'}
|
||||
};
|
||||
expect(c.isResponseValid(json)).toBeTrue();
|
||||
expect(c.isRequestResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
message: 'coucou'
|
||||
};
|
||||
expect(c.isResponseValid(json)).toBeFalse();
|
||||
expect(c.isRequestResponseValid(json)).toBeFalse();
|
||||
json = {
|
||||
error: 'coucou',
|
||||
data: {truc: 'machin'}
|
||||
state: 'coucou'
|
||||
};
|
||||
expect(c.isResponseValid(json)).toBeFalse();
|
||||
expect(c.isRequestResponseValid(json)).toBeFalse();
|
||||
json = {
|
||||
error: 0,
|
||||
data: 'coucou'
|
||||
state: true,
|
||||
};
|
||||
expect(c.isResponseValid(json)).toBeFalse();
|
||||
json = {
|
||||
error: 0,
|
||||
};
|
||||
expect(c.isResponseValid(json)).toBeFalse();
|
||||
expect(c.isRequestResponseValid(json)).toBeFalse();
|
||||
});
|
||||
|
||||
test("isConnectionResponseValid", () => {
|
||||
let json = {
|
||||
error: 0,
|
||||
data: {token: 'token'}
|
||||
state: true,
|
||||
message: 'Connexion confirmée',
|
||||
token: 'token'
|
||||
};
|
||||
expect(c.isConnectionResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
error: 2,
|
||||
data: {}
|
||||
state: true,
|
||||
token: 'token'
|
||||
};
|
||||
expect(c.isConnectionResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
error: 0,
|
||||
data: {token: ''}
|
||||
state: false,
|
||||
};
|
||||
expect(c.isConnectionResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
state: false,
|
||||
message: 'Adresse mail ou mot de passe incorrect',
|
||||
token: ''
|
||||
};
|
||||
expect(c.isConnectionResponseValid(json)).toBeTrue();
|
||||
json = {
|
||||
state: true,
|
||||
message: 'Connexion confirmée',
|
||||
token: ''
|
||||
};
|
||||
expect(c.isConnectionResponseValid(json)).toBeFalse();
|
||||
json = {
|
||||
error: 'prout',
|
||||
data: {token: ''}
|
||||
state: true,
|
||||
message: 'Connexion confirmée',
|
||||
};
|
||||
expect(c.isConnectionResponseValid(json)).toBeFalse();
|
||||
json = {
|
||||
state: 'coucou',
|
||||
message: 'Connexion confirmée',
|
||||
token: 'token'
|
||||
};
|
||||
expect(c.isConnectionResponseValid(json)).toBeFalse();
|
||||
json = {
|
||||
state: true,
|
||||
message: 'Connexion confirmée',
|
||||
token: 2
|
||||
};
|
||||
expect(c.isConnectionResponseValid(json)).toBeFalse();
|
||||
json = {
|
||||
coucou: 'coucou',
|
||||
message: 'Connexion confirmée',
|
||||
token: 'token'
|
||||
};
|
||||
expect(c.isConnectionResponseValid(json)).toBeFalse();
|
||||
});
|
||||
|
|
@ -132,9 +152,10 @@ test("connect bad credentials", () => {
|
|||
return Promise.resolve({
|
||||
json: () => {
|
||||
return {
|
||||
error: ERROR_TYPE.BAD_CREDENTIALS,
|
||||
data: {}
|
||||
};
|
||||
state: false,
|
||||
message: 'Adresse mail ou mot de passe incorrect',
|
||||
token: ''
|
||||
}
|
||||
},
|
||||
})
|
||||
});
|
||||
|
|
@ -147,9 +168,10 @@ test("connect good credentials", () => {
|
|||
return Promise.resolve({
|
||||
json: () => {
|
||||
return {
|
||||
error: ERROR_TYPE.SUCCESS,
|
||||
data: {token: 'token'}
|
||||
};
|
||||
state: true,
|
||||
message: 'Connexion confirmée',
|
||||
token: 'token'
|
||||
}
|
||||
},
|
||||
})
|
||||
});
|
||||
|
|
@ -164,9 +186,13 @@ test("connect good credentials no consent", () => {
|
|||
return Promise.resolve({
|
||||
json: () => {
|
||||
return {
|
||||
error: ERROR_TYPE.NO_CONSENT,
|
||||
data: {}
|
||||
};
|
||||
state: false,
|
||||
message: 'pas de consent',
|
||||
token: '',
|
||||
data: {
|
||||
consent: false,
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
});
|
||||
|
|
@ -179,16 +205,17 @@ test("connect good credentials, fail save token", () => {
|
|||
return Promise.resolve({
|
||||
json: () => {
|
||||
return {
|
||||
error: ERROR_TYPE.SUCCESS,
|
||||
data: {token: 'token'}
|
||||
};
|
||||
state: true,
|
||||
message: 'Connexion confirmée',
|
||||
token: 'token'
|
||||
}
|
||||
},
|
||||
})
|
||||
});
|
||||
jest.spyOn(ConnectionManager.prototype, 'saveLogin').mockImplementationOnce(() => {
|
||||
return Promise.reject(false);
|
||||
});
|
||||
return expect(c.connect('email', 'password')).rejects.toBe(ERROR_TYPE.UNKNOWN);
|
||||
return expect(c.connect('email', 'password')).rejects.toBe(ERROR_TYPE.SAVE_TOKEN);
|
||||
});
|
||||
|
||||
test("connect connection error", () => {
|
||||
|
|
@ -222,10 +249,7 @@ test("authenticatedRequest success", () => {
|
|||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
return Promise.resolve({
|
||||
json: () => {
|
||||
return {
|
||||
error: ERROR_TYPE.SUCCESS,
|
||||
data: {coucou: 'toi'}
|
||||
};
|
||||
return {state: true, message: 'Connexion vérifiée', data: {coucou: 'toi'}}
|
||||
},
|
||||
})
|
||||
});
|
||||
|
|
@ -240,15 +264,12 @@ test("authenticatedRequest error wrong token", () => {
|
|||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
return Promise.resolve({
|
||||
json: () => {
|
||||
return {
|
||||
error: ERROR_TYPE.BAD_TOKEN,
|
||||
data: {}
|
||||
};
|
||||
return {state: false, message: 'Le champ token sélectionné est invalide.'}
|
||||
},
|
||||
})
|
||||
});
|
||||
return expect(c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'))
|
||||
.rejects.toBe(ERROR_TYPE.BAD_TOKEN);
|
||||
.rejects.toBe(ERROR_TYPE.BAD_CREDENTIALS);
|
||||
});
|
||||
|
||||
test("authenticatedRequest error bogus response", () => {
|
||||
|
|
@ -258,9 +279,7 @@ test("authenticatedRequest error bogus response", () => {
|
|||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
return Promise.resolve({
|
||||
json: () => {
|
||||
return {
|
||||
error: ERROR_TYPE.SUCCESS,
|
||||
};
|
||||
return {state: true, message: 'Connexion vérifiée'}
|
||||
},
|
||||
})
|
||||
});
|
||||
|
|
@ -283,6 +302,13 @@ test("authenticatedRequest error no token", () => {
|
|||
jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
||||
return null;
|
||||
});
|
||||
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
||||
return Promise.resolve({
|
||||
json: () => {
|
||||
return {state: false, message: 'Le champ token sélectionné est invalide.'}
|
||||
},
|
||||
})
|
||||
});
|
||||
return expect(c.authenticatedRequest('https://www.amicale-insat.fr/api/token/check'))
|
||||
.rejects.toBe(ERROR_TYPE.UNKNOWN);
|
||||
.rejects.toBe(ERROR_TYPE.NO_TOKEN);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,20 +1 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "Removing node_modules..."
|
||||
rm -rf node_modules/
|
||||
echo -e "Done\n"
|
||||
|
||||
echo "Removing locks..."
|
||||
rm -f package-lock.json && rm -f yarn.lock
|
||||
echo -e "Done\n"
|
||||
|
||||
#echo "Verifying npm cache..."
|
||||
#npm cache verify
|
||||
#echo -e "Done\n"
|
||||
|
||||
echo "Installing dependencies..."
|
||||
npm install
|
||||
echo -e "Done\n"
|
||||
|
||||
echo "Starting expo with clear cache..."
|
||||
expo r -c
|
||||
rm -rf node_modules/ && rm -f package-lock.json && rm -f yarn.lock && npm cache verify && npm install && expo r -c
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import BasicLoadingScreen from "../Custom/BasicLoadingScreen";
|
|||
type Props = {
|
||||
navigation: Object,
|
||||
theme: Object,
|
||||
links: Array<{link: string, mandatory: boolean}>,
|
||||
link: string,
|
||||
renderFunction: Function,
|
||||
}
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ class AuthenticatedScreen extends React.Component<Props, State> {
|
|||
currentUserToken: string | null;
|
||||
connectionManager: ConnectionManager;
|
||||
errorCode: number;
|
||||
data: Array<Object>;
|
||||
data: Object;
|
||||
colors: Object;
|
||||
|
||||
constructor(props) {
|
||||
|
|
@ -35,7 +35,6 @@ class AuthenticatedScreen extends React.Component<Props, State> {
|
|||
this.colors = props.theme.colors;
|
||||
this.connectionManager = ConnectionManager.getInstance();
|
||||
this.props.navigation.addListener('focus', this.onScreenFocus.bind(this));
|
||||
this.data = new Array(this.props.links.length);
|
||||
}
|
||||
|
||||
onScreenFocus() {
|
||||
|
|
@ -47,53 +46,25 @@ class AuthenticatedScreen extends React.Component<Props, State> {
|
|||
if (!this.state.loading)
|
||||
this.setState({loading: true});
|
||||
if (this.connectionManager.isLoggedIn()) {
|
||||
for (let i = 0; i < this.props.links.length; i++) {
|
||||
this.connectionManager.authenticatedRequest(this.props.links[i].link)
|
||||
.then((data) => {
|
||||
this.onFinishedLoading(data, i, -1);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.onFinishedLoading(null, i, error);
|
||||
});
|
||||
}
|
||||
|
||||
this.connectionManager.authenticatedRequest(this.props.link)
|
||||
.then((data) => {
|
||||
this.onFinishedLoading(data, -1);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.onFinishedLoading(undefined, error);
|
||||
});
|
||||
} else {
|
||||
this.onFinishedLoading(null, -1, ERROR_TYPE.BAD_CREDENTIALS);
|
||||
this.onFinishedLoading(undefined, ERROR_TYPE.BAD_CREDENTIALS);
|
||||
}
|
||||
};
|
||||
|
||||
onFinishedLoading(data: Object, index: number, error: number) {
|
||||
if (index >= 0 && index < this.props.links.length)
|
||||
this.data[index] = data;
|
||||
onFinishedLoading(data: Object, error: number) {
|
||||
this.data = data;
|
||||
this.currentUserToken = data !== undefined
|
||||
? this.connectionManager.getToken()
|
||||
: null;
|
||||
this.errorCode = error;
|
||||
|
||||
if (this.allRequestsFinished())
|
||||
this.setState({loading: false});
|
||||
}
|
||||
|
||||
allRequestsFinished() {
|
||||
let finished = true;
|
||||
for (let i = 0; i < this.data.length; i++) {
|
||||
if (this.data[i] === undefined) {
|
||||
finished = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return finished;
|
||||
}
|
||||
|
||||
allRequestsValid() {
|
||||
let valid = true;
|
||||
for (let i = 0; i < this.data.length; i++) {
|
||||
if (this.data[i] === null && this.props.links[i].mandatory) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
this.setState({loading: false});
|
||||
}
|
||||
|
||||
getErrorRender() {
|
||||
|
|
@ -104,10 +75,6 @@ class AuthenticatedScreen extends React.Component<Props, State> {
|
|||
message = i18n.t("loginScreen.errors.credentials");
|
||||
icon = "account-alert-outline";
|
||||
break;
|
||||
case ERROR_TYPE.BAD_TOKEN:
|
||||
message = "BAD TOKEN"; // TODO translate
|
||||
icon = "access-point-network-off";
|
||||
break;
|
||||
case ERROR_TYPE.CONNECTION_ERROR:
|
||||
message = i18n.t("loginScreen.errors.connection");
|
||||
icon = "access-point-network-off";
|
||||
|
|
@ -132,7 +99,7 @@ class AuthenticatedScreen extends React.Component<Props, State> {
|
|||
return (
|
||||
this.state.loading
|
||||
? <BasicLoadingScreen/>
|
||||
: (this.allRequestsValid()
|
||||
: (this.data !== undefined
|
||||
? this.props.renderFunction(this.data)
|
||||
: this.getErrorRender())
|
||||
);
|
||||
|
|
|
|||
|
|
@ -69,12 +69,6 @@ class SideBar extends React.Component<Props, State> {
|
|||
icon: "account-group",
|
||||
onlyWhenLoggedIn: true,
|
||||
},
|
||||
{
|
||||
name: "VOTE",
|
||||
route: "VoteScreen",
|
||||
icon: "vote",
|
||||
onlyWhenLoggedIn: true,
|
||||
},
|
||||
{
|
||||
name: i18n.t('screens.logout'),
|
||||
route: 'disconnect',
|
||||
|
|
@ -167,17 +161,18 @@ class SideBar extends React.Component<Props, State> {
|
|||
}
|
||||
|
||||
onRouteChange = (event) => {
|
||||
try {
|
||||
const state = event.data.state.routes[0].state; // Get the Drawer's state if it exists
|
||||
// Get the current route name. This will only show Drawer routes.
|
||||
// Tab routes will be shown as 'Main'
|
||||
const routeName = state.routeNames[state.index];
|
||||
if (this.state.activeRoute !== routeName)
|
||||
this.setState({activeRoute: routeName});
|
||||
} catch(e) {
|
||||
this.setState({activeRoute: 'Main'});
|
||||
}
|
||||
if (event.data.state.routes !== undefined) {
|
||||
const route = event.data.state.routes[0]; // get the current route (ROOT)
|
||||
if (route.state !== undefined) {
|
||||
const state = route.state; // Get the Drawer's state if it exists
|
||||
// Get the current route name. This will only show Drawer routes.
|
||||
// Tab routes will be shown as 'Main'
|
||||
const routeName = state.routeNames[state.index];
|
||||
if (this.state.activeRoute !== routeName)
|
||||
this.setState({activeRoute: routeName});
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
showDisconnectDialog = () => this.setState({dialogVisible: true});
|
||||
|
|
|
|||
|
|
@ -3,35 +3,14 @@
|
|||
import * as SecureStore from 'expo-secure-store';
|
||||
|
||||
export const ERROR_TYPE = {
|
||||
SUCCESS: 0,
|
||||
BAD_CREDENTIALS: 1,
|
||||
BAD_TOKEN: 2,
|
||||
NO_CONSENT: 3,
|
||||
BAD_INPUT: 400,
|
||||
FORBIDDEN: 403,
|
||||
CONNECTION_ERROR: 404,
|
||||
SERVER_ERROR: 500,
|
||||
UNKNOWN: 999,
|
||||
BAD_CREDENTIALS: 0,
|
||||
CONNECTION_ERROR: 1,
|
||||
SAVE_TOKEN: 2,
|
||||
NO_TOKEN: 3,
|
||||
NO_CONSENT: 4,
|
||||
};
|
||||
|
||||
type response_format = {
|
||||
error: number,
|
||||
data: Object,
|
||||
}
|
||||
|
||||
/**
|
||||
* champ: error
|
||||
*
|
||||
* 0 : SUCCESS -> pas d'erreurs
|
||||
* 1 : BAD_CREDENTIALS -> email ou mdp invalide
|
||||
* 2 : BAD_TOKEN -> session expirée
|
||||
* 3 : NO_CONSENT
|
||||
* 403 : FORBIDDEN -> accès a la ressource interdit
|
||||
* 500 : SERVER_ERROR -> pb coté serveur
|
||||
*/
|
||||
|
||||
const API_ENDPOINT = "https://www.amicale-insat.fr/api/";
|
||||
const AUTH_PATH = "password";
|
||||
const AUTH_URL = "https://www.amicale-insat.fr/api/password";
|
||||
|
||||
export default class ConnectionManager {
|
||||
static instance: ConnectionManager | null = null;
|
||||
|
|
@ -131,7 +110,7 @@ export default class ConnectionManager {
|
|||
password: password,
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(API_ENDPOINT + AUTH_PATH, {
|
||||
fetch(AUTH_URL, {
|
||||
method: 'POST',
|
||||
headers: new Headers({
|
||||
'Accept': 'application/json',
|
||||
|
|
@ -139,18 +118,22 @@ export default class ConnectionManager {
|
|||
}),
|
||||
body: JSON.stringify(data)
|
||||
}).then(async (response) => response.json())
|
||||
.then((response: response_format) => {
|
||||
if (this.isConnectionResponseValid(response)) {
|
||||
if (response.error === ERROR_TYPE.SUCCESS) {
|
||||
this.saveLogin(email, response.data.token)
|
||||
.then((data) => {
|
||||
if (this.isConnectionResponseValid(data)) {
|
||||
if (data.state) {
|
||||
this.saveLogin(email, data.token)
|
||||
.then(() => {
|
||||
resolve(true);
|
||||
})
|
||||
.catch(() => {
|
||||
reject(ERROR_TYPE.UNKNOWN);
|
||||
reject(ERROR_TYPE.SAVE_TOKEN);
|
||||
});
|
||||
} else
|
||||
reject(response.error);
|
||||
} else if (data.data !== undefined
|
||||
&& data.data.consent !== undefined
|
||||
&& !data.data.consent)
|
||||
reject(ERROR_TYPE.NO_CONSENT);
|
||||
else
|
||||
reject(ERROR_TYPE.BAD_CREDENTIALS);
|
||||
} else
|
||||
reject(ERROR_TYPE.CONNECTION_ERROR);
|
||||
})
|
||||
|
|
@ -160,32 +143,35 @@ export default class ConnectionManager {
|
|||
});
|
||||
}
|
||||
|
||||
isResponseValid(response: response_format) {
|
||||
isRequestResponseValid(response: Object) {
|
||||
let valid = response !== undefined
|
||||
&& response.error !== undefined
|
||||
&& typeof response.error === "number";
|
||||
&& response.state !== undefined
|
||||
&& typeof response.state === "boolean";
|
||||
|
||||
valid = valid
|
||||
&& response.data !== undefined
|
||||
&& typeof response.data === "object";
|
||||
return valid;
|
||||
}
|
||||
|
||||
isConnectionResponseValid(response: response_format) {
|
||||
let valid = this.isResponseValid(response);
|
||||
|
||||
if (valid && response.error === ERROR_TYPE.SUCCESS)
|
||||
if (valid && response.state)
|
||||
valid = valid
|
||||
&& response.data.token !== undefined
|
||||
&& response.data.token !== ''
|
||||
&& typeof response.data.token === "string";
|
||||
&& response.data !== undefined
|
||||
&& typeof response.data === "object";
|
||||
return valid;
|
||||
}
|
||||
|
||||
async authenticatedRequest(path: string) {
|
||||
isConnectionResponseValid(response: Object) {
|
||||
let valid = response !== undefined
|
||||
&& response.state !== undefined
|
||||
&& typeof response.state === "boolean";
|
||||
|
||||
if (valid && response.state)
|
||||
valid = valid
|
||||
&& response.token !== undefined
|
||||
&& response.token !== ''
|
||||
&& typeof response.token === "string";
|
||||
return valid;
|
||||
}
|
||||
|
||||
async authenticatedRequest(url: string) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.getToken() !== null) {
|
||||
fetch(API_ENDPOINT + path, {
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: new Headers({
|
||||
'Accept': 'application/json',
|
||||
|
|
@ -193,13 +179,12 @@ export default class ConnectionManager {
|
|||
}),
|
||||
body: JSON.stringify({token: this.getToken()})
|
||||
}).then(async (response) => response.json())
|
||||
.then((response: response_format) => {
|
||||
console.log(response);
|
||||
if (this.isResponseValid(response)) {
|
||||
if (response.error === ERROR_TYPE.SUCCESS)
|
||||
resolve(response.data);
|
||||
.then((data) => {
|
||||
if (this.isRequestResponseValid(data)) {
|
||||
if (data.state)
|
||||
resolve(data.data);
|
||||
else
|
||||
reject(response.error);
|
||||
reject(ERROR_TYPE.BAD_CREDENTIALS);
|
||||
} else
|
||||
reject(ERROR_TYPE.CONNECTION_ERROR);
|
||||
})
|
||||
|
|
@ -207,7 +192,7 @@ export default class ConnectionManager {
|
|||
reject(ERROR_TYPE.CONNECTION_ERROR);
|
||||
});
|
||||
} else
|
||||
reject(ERROR_TYPE.UNKNOWN);
|
||||
reject(ERROR_TYPE.NO_TOKEN);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import ProfileScreen from "../screens/Amicale/ProfileScreen";
|
|||
import ClubListScreen from "../screens/Amicale/Clubs/ClubListScreen";
|
||||
import ClubDisplayScreen from "../screens/Amicale/Clubs/ClubDisplayScreen";
|
||||
import ClubAboutScreen from "../screens/Amicale/Clubs/ClubAboutScreen";
|
||||
import VoteScreen from "../screens/Amicale/VoteScreen";
|
||||
|
||||
const defaultScreenOptions = {
|
||||
gestureEnabled: true,
|
||||
|
|
@ -240,31 +239,6 @@ function ProfileStackComponent() {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
const VoteStack = createStackNavigator();
|
||||
|
||||
function VoteStackComponent() {
|
||||
return (
|
||||
<VoteStack.Navigator
|
||||
initialRouteName="VoteScreen"
|
||||
headerMode="float"
|
||||
screenOptions={defaultScreenOptions}
|
||||
>
|
||||
<VoteStack.Screen
|
||||
name="VoteScreen"
|
||||
component={VoteScreen}
|
||||
options={({navigation}) => {
|
||||
const openDrawer = getDrawerButton.bind(this, navigation);
|
||||
return {
|
||||
title: "VoteScreen",
|
||||
headerLeft: openDrawer
|
||||
};
|
||||
}}
|
||||
/>
|
||||
</VoteStack.Navigator>
|
||||
);
|
||||
}
|
||||
|
||||
const ClubStack = createStackNavigator();
|
||||
|
||||
function ClubStackComponent() {
|
||||
|
|
@ -367,10 +341,6 @@ export default function DrawerNavigator() {
|
|||
name="ClubListScreen"
|
||||
component={ClubStackComponent}
|
||||
/>
|
||||
<Drawer.Screen
|
||||
name="VoteScreen"
|
||||
component={VoteStackComponent}
|
||||
/>
|
||||
</Drawer.Navigator>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class ClubListScreen extends React.Component<Props, State> {
|
|||
* @return {*}
|
||||
*/
|
||||
getHeaderButtons = () => {
|
||||
const onPress = () => this.props.navigation.navigate("ClubAboutScreen");
|
||||
const onPress = () => this.props.navigation.navigate( "ClubAboutScreen");
|
||||
return <HeaderButton icon={'information'} onPress={onPress}/>;
|
||||
};
|
||||
|
||||
|
|
@ -91,11 +91,11 @@ class ClubListScreen extends React.Component<Props, State> {
|
|||
itemLayout = (data, index) => ({length: LIST_ITEM_HEIGHT, offset: LIST_ITEM_HEIGHT * index, index});
|
||||
|
||||
getScreen = (data: Object) => {
|
||||
this.categories = data[0].categories;
|
||||
this.categories = data.categories;
|
||||
return (
|
||||
//$FlowFixMe
|
||||
<FlatList
|
||||
data={data[0].clubs}
|
||||
data={data.clubs}
|
||||
keyExtractor={this.keyExtractor}
|
||||
renderItem={this.getRenderItem}
|
||||
ListHeaderComponent={this.getListHeader()}
|
||||
|
|
@ -193,12 +193,7 @@ class ClubListScreen extends React.Component<Props, State> {
|
|||
return (
|
||||
<AuthenticatedScreen
|
||||
{...this.props}
|
||||
links={[
|
||||
{
|
||||
link: 'clubs/list',
|
||||
mandatory: true,
|
||||
}
|
||||
]}
|
||||
link={'https://www.amicale-insat.fr/api/clubs/list'}
|
||||
renderFunction={this.getScreen}
|
||||
/>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -149,17 +149,17 @@ class LoginScreen extends React.Component<Props, State> {
|
|||
const title = i18n.t("loginScreen.errors.title");
|
||||
let message;
|
||||
switch (error) {
|
||||
case ERROR_TYPE.BAD_CREDENTIALS:
|
||||
message = i18n.t("loginScreen.errors.credentials");
|
||||
break;
|
||||
case ERROR_TYPE.NO_CONSENT:
|
||||
message = i18n.t("loginScreen.errors.consent");
|
||||
break;
|
||||
case ERROR_TYPE.CONNECTION_ERROR:
|
||||
message = i18n.t("loginScreen.errors.connection");
|
||||
break;
|
||||
case ERROR_TYPE.SERVER_ERROR:
|
||||
message = "SERVER ERROR"; // TODO translate
|
||||
case ERROR_TYPE.BAD_CREDENTIALS:
|
||||
message = i18n.t("loginScreen.errors.credentials");
|
||||
break;
|
||||
case ERROR_TYPE.SAVE_TOKEN:
|
||||
message = i18n.t("loginScreen.errors.saveToken");
|
||||
break;
|
||||
case ERROR_TYPE.NO_CONSENT:
|
||||
message = i18n.t("loginScreen.errors.consent");
|
||||
break;
|
||||
default:
|
||||
message = i18n.t("loginScreen.errors.unknown");
|
||||
|
|
@ -236,6 +236,13 @@ class LoginScreen extends React.Component<Props, State> {
|
|||
<Card.Content>
|
||||
{this.getFormInput()}
|
||||
<Card.Actions>
|
||||
<Button
|
||||
icon="help-circle"
|
||||
mode="contained"
|
||||
onPress={this.onResetPasswordClick}
|
||||
style={{marginLeft: 'auto'}}>
|
||||
{i18n.t("loginScreen.resetPassword")}
|
||||
</Button>
|
||||
<Button
|
||||
icon="send"
|
||||
mode="contained"
|
||||
|
|
@ -246,15 +253,6 @@ class LoginScreen extends React.Component<Props, State> {
|
|||
{i18n.t("loginScreen.login")}
|
||||
</Button>
|
||||
</Card.Actions>
|
||||
<Card.Actions>
|
||||
<Button
|
||||
icon="help-circle"
|
||||
mode="contained"
|
||||
onPress={this.onResetPasswordClick}
|
||||
style={{marginLeft: 'auto'}}>
|
||||
{i18n.t("loginScreen.resetPassword")}
|
||||
</Button>
|
||||
</Card.Actions>
|
||||
</Card.Content>
|
||||
</Card>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// @flow
|
||||
|
||||
import * as React from 'react';
|
||||
import {FlatList, ScrollView, StyleSheet} from "react-native";
|
||||
import {FlatList, StyleSheet, View} from "react-native";
|
||||
import {Avatar, Button, Card, Divider, List, withTheme} from 'react-native-paper';
|
||||
import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen";
|
||||
import {openBrowser} from "../../utils/WebBrowser";
|
||||
|
|
@ -28,9 +28,16 @@ class ProfileScreen extends React.Component<Props, State> {
|
|||
|
||||
data: Object;
|
||||
|
||||
flatListData: Array<Object>;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.colors = props.theme.colors;
|
||||
this.flatListData = [
|
||||
{id: '0'},
|
||||
{id: '1'},
|
||||
{id: '2'},
|
||||
]
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
|
@ -40,29 +47,44 @@ class ProfileScreen extends React.Component<Props, State> {
|
|||
});
|
||||
}
|
||||
|
||||
showDisconnectDialog = () => this.setState({dialogVisible: true});
|
||||
showDisconnectDialog = () => this.setState({ dialogVisible: true });
|
||||
|
||||
hideDisconnectDialog = () => this.setState({dialogVisible: false});
|
||||
hideDisconnectDialog = () => this.setState({ dialogVisible: false });
|
||||
|
||||
getHeaderButtons() {
|
||||
return <HeaderButton icon={'logout'} onPress={this.showDisconnectDialog}/>;
|
||||
}
|
||||
|
||||
getScreen = (data: Object) => {
|
||||
this.data = data[0];
|
||||
getScreen(data: Object) {
|
||||
this.data = data;
|
||||
return (
|
||||
<ScrollView>
|
||||
{this.getPersonalCard()}
|
||||
{this.getClubCard()}
|
||||
{this.getMembershipCar()}
|
||||
<View>
|
||||
<FlatList
|
||||
renderItem={item => this.getRenderItem(item)}
|
||||
keyExtractor={item => item.id}
|
||||
data={this.flatListData}
|
||||
/>
|
||||
<LogoutDialog
|
||||
{...this.props}
|
||||
visible={this.state.dialogVisible}
|
||||
onDismiss={this.hideDisconnectDialog}
|
||||
/>
|
||||
</ScrollView>
|
||||
</View>
|
||||
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
getRenderItem({item}: Object): any {
|
||||
switch (item.id) {
|
||||
case '0':
|
||||
return this.getPersonalCard();
|
||||
case '1':
|
||||
return this.getClubCard();
|
||||
case '2':
|
||||
return this.getMembershipCar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
getPersonalCard() {
|
||||
return (
|
||||
|
|
@ -210,13 +232,8 @@ class ProfileScreen extends React.Component<Props, State> {
|
|||
return (
|
||||
<AuthenticatedScreen
|
||||
{...this.props}
|
||||
links={[
|
||||
{
|
||||
link: 'user/profile',
|
||||
mandatory: true,
|
||||
}
|
||||
]}
|
||||
renderFunction={this.getScreen}
|
||||
link={'https://www.amicale-insat.fr/api/user/profile'}
|
||||
renderFunction={(data) => this.getScreen(data)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,256 +0,0 @@
|
|||
// @flow
|
||||
|
||||
import * as React from 'react';
|
||||
import {ScrollView, StyleSheet} from "react-native";
|
||||
import {Avatar, Card, Paragraph, withTheme} from 'react-native-paper';
|
||||
import AuthenticatedScreen from "../../components/Amicale/AuthenticatedScreen";
|
||||
import {stringToDate} from "../../utils/Planning";
|
||||
|
||||
const ICON_AMICALE = require('../../../assets/amicale.png');
|
||||
|
||||
type Props = {
|
||||
navigation: Object,
|
||||
theme: Object,
|
||||
}
|
||||
|
||||
const FAKE_DATE = {
|
||||
"date_begin": "2020-04-06 13:00",
|
||||
"date_end": "2020-04-06 20:00",
|
||||
"date_result_begin": "2020-04-06 20:15",
|
||||
"date_result_end": "2020-04-07 12:00",
|
||||
};
|
||||
|
||||
const FAKE_DATE2 = {
|
||||
"date_begin": null,
|
||||
"date_end": null,
|
||||
"date_result_begin": null,
|
||||
"date_result_end": null,
|
||||
};
|
||||
|
||||
const FAKE_TEAMS = {
|
||||
has_voted: false,
|
||||
teams: [
|
||||
{
|
||||
id: 1,
|
||||
name: "TEST TEAM",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
type State = {}
|
||||
|
||||
class VoteScreen extends React.Component<Props, State> {
|
||||
|
||||
state = {};
|
||||
|
||||
colors: Object;
|
||||
|
||||
teams: Array<Object> | null;
|
||||
hasVoted: boolean;
|
||||
datesString: Object;
|
||||
dates: Object;
|
||||
|
||||
today: Date;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.colors = props.theme.colors;
|
||||
this.hasVoted = false;
|
||||
this.teams = null;
|
||||
this.today = new Date();
|
||||
}
|
||||
|
||||
getScreen = (data: Array<Object>) => {
|
||||
data[0] = FAKE_TEAMS;
|
||||
data[1] = FAKE_DATE;
|
||||
|
||||
if (data[0] !== null) {
|
||||
this.teams = data[0].teams;
|
||||
this.hasVoted = data[0].has_voted;
|
||||
}
|
||||
this.datesString = data[1];
|
||||
this.generateDateObject();
|
||||
console.log(this.teams);
|
||||
console.log(this.datesString);
|
||||
console.log(this.dates);
|
||||
return (
|
||||
<ScrollView>
|
||||
{
|
||||
this.isVoteAvailable()
|
||||
? this.getContent()
|
||||
: null
|
||||
}
|
||||
{this.getTitleCard()}
|
||||
</ScrollView>
|
||||
);
|
||||
};
|
||||
|
||||
generateDateObject() {
|
||||
this.dates = {
|
||||
date_begin: stringToDate(this.datesString.date_begin),
|
||||
date_end: stringToDate(this.datesString.date_end),
|
||||
date_result_begin: stringToDate(this.datesString.date_result_begin),
|
||||
date_result_end: stringToDate(this.datesString.date_result_end),
|
||||
};
|
||||
}
|
||||
|
||||
isVoteAvailable() {
|
||||
return this.dates.date_begin !== null;
|
||||
}
|
||||
|
||||
isVoteRunning() {
|
||||
return this.today > this.dates.date_begin && this.today < this.dates.date_end;
|
||||
}
|
||||
|
||||
isVoteStarted() {
|
||||
return this.today > this.dates.date_begin;
|
||||
}
|
||||
|
||||
isResultRunning() {
|
||||
return this.today > this.dates.date_result_begin && this.today < this.dates.date_result_end;
|
||||
}
|
||||
|
||||
isResultStarted() {
|
||||
return this.today > this.dates.date_result_begin;
|
||||
}
|
||||
|
||||
getContent() {
|
||||
if (!this.isVoteStarted())
|
||||
return this.getTeaseVoteCard();
|
||||
else if (this.isVoteRunning() && !this.hasVoted)
|
||||
return this.getVoteCard();
|
||||
else if (!this.isResultStarted())
|
||||
return this.getWaitVoteCard();
|
||||
else if (this.isResultRunning())
|
||||
return this.getVoteResultCard();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
getTitleCard() {
|
||||
return (
|
||||
<Card style={styles.card}>
|
||||
<Card.Title
|
||||
title={"VOTE"}
|
||||
subtitle={"WHY"}
|
||||
left={(props) => <Avatar.Image
|
||||
{...props}
|
||||
source={ICON_AMICALE}
|
||||
style={styles.icon}
|
||||
/>}
|
||||
/>
|
||||
<Card.Content>
|
||||
<Paragraph>
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus rhoncus porttitor
|
||||
suscipit. Quisque hendrerit, quam id vestibulum vestibulum, lorem nisi hendrerit nisi, a
|
||||
eleifend sapien diam ut elit. Curabitur sit amet vulputate lectus. Donec semper cursus sapien
|
||||
vel finibus.
|
||||
</Paragraph>
|
||||
<Paragraph>
|
||||
Sed et venenatis turpis. Fusce malesuada magna urna, sed vehicula sem luctus in. Vivamus
|
||||
faucibus vel eros a ultricies. In sed laoreet ante, luctus mattis tellus. Etiam vitae ipsum
|
||||
sagittis, consequat purus sed, blandit risus.
|
||||
</Paragraph>
|
||||
</Card.Content>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The user has not voted yet, and the votes are open
|
||||
*/
|
||||
getVoteCard() {
|
||||
return (
|
||||
<Card style={styles.card}>
|
||||
<Card.Title
|
||||
title={"getVoteCard"}
|
||||
subtitle={"getVoteCard"}
|
||||
/>
|
||||
<Card.Content>
|
||||
<Paragraph>TEAM1</Paragraph>
|
||||
<Paragraph>TEAM2</Paragraph>
|
||||
</Card.Content>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Votes have ended, results can be displayed
|
||||
*/
|
||||
getVoteResultCard() {
|
||||
return (
|
||||
<Card style={styles.card}>
|
||||
<Card.Title
|
||||
title={"getVoteResultCard"}
|
||||
subtitle={"getVoteResultCard"}
|
||||
/>
|
||||
<Card.Content>
|
||||
<Paragraph>TEAM1</Paragraph>
|
||||
<Paragraph>TEAM2</Paragraph>
|
||||
</Card.Content>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vote will open shortly
|
||||
*/
|
||||
getTeaseVoteCard() {
|
||||
return (
|
||||
<Card style={styles.card}>
|
||||
<Card.Title
|
||||
title={"getTeaseVoteCard"}
|
||||
subtitle={"getTeaseVoteCard"}
|
||||
/>
|
||||
<Card.Content>
|
||||
</Card.Content>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* User has voted, waiting for results
|
||||
*/
|
||||
getWaitVoteCard() {
|
||||
return (
|
||||
<Card style={styles.card}>
|
||||
<Card.Title
|
||||
title={"getWaitVoteCard"}
|
||||
subtitle={"getWaitVoteCard"}
|
||||
/>
|
||||
<Card.Content>
|
||||
</Card.Content>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<AuthenticatedScreen
|
||||
{...this.props}
|
||||
links={[
|
||||
{
|
||||
link: 'elections/teams',
|
||||
mandatory: false,
|
||||
},
|
||||
{
|
||||
link: 'elections/datesString',
|
||||
mandatory: false,
|
||||
},
|
||||
]}
|
||||
renderFunction={this.getScreen}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
card: {
|
||||
margin: 10,
|
||||
},
|
||||
icon: {
|
||||
backgroundColor: 'transparent'
|
||||
},
|
||||
});
|
||||
|
||||
export default withTheme(VoteScreen);
|
||||
Loading…
Reference in a new issue