This commit is contained in:
henrydays 2019-03-19 18:33:03 +00:00
parent 2897fccb1c
commit 2b90ed32a6
9 changed files with 289 additions and 201 deletions

View File

@ -105,7 +105,7 @@ class App extends Component {
componentDidMount() {
//this.props.hold();
// this.props.loginInternal();
this.setState({ isModalVisible: false });
@ -155,7 +155,7 @@ class App extends Component {
if (!this.props.logged && this.props.onHold) {
return (
<View style={UtilStyles.containerLoading}>
<ActivityIndicator size="large" color="red" />
<ActivityIndicator size="large" color="#CC1A17" />
</View>
);
} else {

View File

@ -144,6 +144,16 @@ const Stack = createStackNavigator({
)
}
}
if (navigation.state.routes[index].routeName == 'Jogo do...') {
return {
header: (<View style={{backgroundColor:'#CC1A17', padding:15}}>
<Text style={{textAlign:'center', alignSelf:'center', color:'white', fontSize:20, fontWeight:'bold'}}>Jogo do ENEI'19</Text>
</View>)
}
}
else if (navigation.state.routes[index].routeName == 'Calendário') {
return {
headerTitle: 'Calendário',

View File

@ -86,6 +86,8 @@ class Home extends Component {
console.log(this.props.internalToken)
this.props.getUserTeam(this.props.user, this.props.internalToken );
this.props.getEvents(this.props.user);
this.props.loginInternal(this.props.user, this.props.token);
}
componentWillUnmount() {}

View File

@ -7,7 +7,8 @@ import {
Dimensions,
Button,
TouchableOpacity,
FlatList
FlatList,
Linking
} from "react-native";
import ProgressBarAnimated from "react-native-progress-bar-animated";
import Modal from "react-native-modal";
@ -23,24 +24,47 @@ import FitImage from "react-native-fit-image";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import PTRView from "react-native-pull-to-refresh";
import * as Actions from "../store/actions"; //Import your actionss
class Jogo extends React.Component {
static navigationOptions = ({ navigation }) => ({
header: (
<View style={{backgroundColor:'#CC1A17'}}>
<Text>a</Text>
</View>
)
});
handleClick = (link) => {
Linking.canOpenURL(link).then(supported => {
if (supported) {
Linking.openURL(link);
} else {
console.log("Don't know how to open URI: " + link);
}
});
};
state = {
progress: 20,
progressWithOnComplete: 0,
progressCustomized: 0,
isModalVisible: false
isModalVisible: false,
cromo:{}
};
increase = (key, value) => {
this.setState({
[key]: this.state[key] + value
});
};
_toggleModal = () => {
this.setState({ isModalVisible: !this.state.isModalVisible });
_update = () => {
this.props.getCromos(this.props.user, this.props.internalToken);
};
_toggleModal = (item) => {
this.setState({ isModalVisible: !this.state.isModalVisible , cromo: item});
console.log("assd");
};
@ -64,6 +88,7 @@ class Jogo extends React.Component {
isVisible={this.state.isModalVisible}
animationInTiming={1000}
animationOutTiming={800}
onBackdropPress={()=>this.setState({isModalVisible:false})}
>
<View
style={{
@ -89,13 +114,15 @@ class Jogo extends React.Component {
<View style={{ width: "100%", margin: -10 }}>
<View style={{ width: 30 }}>
<Button
onPress={this._toggleModal}
onPress={()=>this.setState({isModalVisible:false})}
title="X"
color="#CC1A17"
accessibilityLabel="Learn more about this purple button"
/>
</View>
</View>
{ this.state.cromo.unlocked &&
<View
style={{
flex: 1,
@ -105,13 +132,13 @@ class Jogo extends React.Component {
}}
>
<View style={{ paddingTop: 25, width: "40%" }}>
<FitImage
source={{
uri:
"https://upload.wikimedia.org/wikipedia/commons/8/8a/CSW_Gradiente_rgb.png"
}}
uri: this.state.cromo.logo}}
style={styles.fitImage}
/>
</View>
<View
style={{
@ -121,15 +148,11 @@ class Jogo extends React.Component {
}}
>
<Text style={{ padding: 10 }}>
A CRITICAL Software fornece sistemas e serviços de software
para segurança e aplicações essenciais aos negócios,
ajudando a garantir que os clientes atendam aos requisitos
mais exigentes de qualidade - padrões de segurança,
desempenho e fiabilidade
{this.state.cromo.descMostrar}
</Text>
</View>
<View style={{ width: "100%", marginTop: 10 }}>
<TouchableOpacity>
<TouchableOpacity onPress={()=>this.handleClick(this.state.cromo.websitecromo)} >
<Text
style={{
textAlign: "center",
@ -143,16 +166,48 @@ class Jogo extends React.Component {
</TouchableOpacity>
</View>
</View>
}
{ this.state.cromo.unlocked!= true &&
<View
style={{
flex: 1,
alignContent: "center",
width: "96%",
alignItems: "center"
}}
>
<View style={{ paddingTop: 25, width: "40%" }}>
<FitImage
source={{uri:"https://i.imgur.com/LrOOupY.png"}}
style={styles.fitImage}
/>
</View>
<View
style={{
backgroundColor: "rgba(255,255,255,0.6)",
width: "100%",
marginTop: 35
}}
>
<Text style={{ padding: 10 }}>
{this.state.cromo.descMostrar}
</Text>
</View>
<View style={{ width: "100%", marginTop: 10 }}>
</View>
</View>
}
</ImageBackground>
</View>
</Modal>
<View style={styles.header}>
<View style={styles.titleContainer}>
<Text style={styles.title}>Jogo do ENEI'19</Text>
</View>
</View>
<View style={{ height: 50, backgroundColor: "white" }}>
<PTRView onRefresh={this._update}>
<View style={{ height: 50, backgroundColor: "#eeeeee" }}>
<View
style={{
flex: 1,
@ -170,11 +225,13 @@ class Jogo extends React.Component {
}}
>
<IconFA name="trophy" size={30} />
{this.props.cromos!= undefined &&
<Text
style={{ fontWeight: "bold", fontSize: 20, marginLeft: 10 }}
>
45
{ this.props.cromos.pontuacao}
</Text>
}
<Text style={{ margin: 5 }}>pontos</Text>
</View>
<View
@ -185,7 +242,7 @@ class Jogo extends React.Component {
}}
>
<Button
onPress={this._toggleModal}
onPress={()=>this.handleClick("https://enei.pt/jogoenei")}
title="Prémios"
color="#CC1A17"
accessibilityLabel="Learn more about this purple button"
@ -227,31 +284,50 @@ class Jogo extends React.Component {
horizontal={true}
>
<ScrollView>
<View style={styles.cromosContainer}>
<View style={styles.cromosContainer}>{this.props.cromos!=undefined &&
<FlatList
data={this.props.cromos}
data={this.props.cromos.cromos}
renderItem={({ item }) => (
<TouchableOpacity onPress={this._toggleModal}>
<View style={styles.cromo}>
<TouchableOpacity onPress={()=>this._toggleModal(item)}>
<View style={styles.cromo}>{
item.unlocked &&
<ImageBackground
source={require("../assets/img/jogo/critical.png")}
source={{uri:item.img}}
style={styles.imageBg}
>
<View style={[styles.triangle, this.props.style]} />
<Text style={styles.points}>15</Text>
<Text style={styles.points}>{item.pontos}</Text>
<View
style={[styles.triangleNumber, this.props.style]}
/>
<Text style={styles.number}>0</Text>
<Text style={styles.number}>{item.id-1}</Text>
</ImageBackground>
}
{
!item.unlocked &&
<ImageBackground
source={require('../assets/img/jogo/enei_black_2.png')}
style={styles.imageBg}
>
<View style={[styles.triangle, this.props.style]} />
<Text style={styles.points}>{item.pontos}</Text>
<View
style={[styles.triangleNumber, this.props.style]}
/>
<Text style={styles.number}>{item.id-1}</Text>
</ImageBackground>
}
</View>
</TouchableOpacity>
)}
numColumns={3} // Número de colunas
/>
/>}
</View>
</ScrollView>
</ScrollView>
</PTRView>
</View>
);
}

View File

@ -1,174 +1,111 @@
import React from 'react';
import {View, Image, Vibration, Dimensions, Text, Button, TouchableOpacity, ActivityIndicator} from 'react-native';
import { View, Image, Vibration, Dimensions,Text ,Button ,TouchableOpacity } from 'react-native';
import QRCodeScanner from 'react-native-qrcode-scanner';
import {UtilStyles} from '../assets/styles'
import CodeInput from 'react-native-confirmation-code-input';
import Modal from "react-native-modal";
import {TabView, TabBar, SceneMap} from 'react-native-tab-view';
import {
RkButton,
RkTheme, RkText
} from 'react-native-ui-kitten';
import IconMI from "react-native-vector-icons/MaterialIcons"
import { bindActionCreators } from "redux";
import PTRView from "react-native-pull-to-refresh";
import * as Actions from "../store/actions";
import { connect } from "react-redux";
import {RkButton,
RkTheme , RkText} from 'react-native-ui-kitten';
const SCREEN_HEIGHT = Dimensions.get("window").height;
const SCREEN_WIDTH = Dimensions.get("window").width;
const SCREEN_HEIGHT = Dimensions.get("window").height;
const SCREEN_WIDTH = Dimensions.get("window").width;
export default class Scan extends React.Component {
class Scan extends React.Component {
_toggleModal = () =>
this.setState({isModalVisible: !this.state.isModalVisible});
this.setState({ isModalVisible: !this.state.isModalVisible });
_activate = () => {
_activate=()=>{
this.setState({isModalVisible: !this.state.isModalVisible, reactivate: true});
this.setState({ isModalVisible: !this.state.isModalVisible ,reactivate:true});
this.scanner.reactivate();
}
onSuccess = (e) => {
this.setState({isModalVisible: !this.state.isModalVisible, isActive: false});
this.setState({code: e.data});
};
this.setState({ isModalVisible: !this.state.isModalVisible ,isActive:false});
this.setState({code:e.data});
this.props.scanQrCode({UserQR:this.props.user.Code, ScanQR: e.data},this.props.internalToken);
};
state = {
isActive: true,
isRender: true,
reactivate: false,
isModalVisible: false,
code: '',
index: 0,
routes: [
{key: 'scan', title: 'Scan', icon: ''},
{key: 'history', title: 'Histórico', icon: 'history'},
{key: 'fav', title: 'Favoritos', icon: 'favorite'},
],
};
componentDidMount() {
state = {
isActive:true,
isRender: true,
reactivate:false,
isModalVisible: false,
code:''
}
componentDidMount() {
this.props.navigation.addListener('willFocus', (route) => {
this.setState({isRender: true})
this.setState({ isRender: true })
});
this.props.navigation.addListener('willBlur', (route) => {
this.setState({isRender: false})
this.setState({ isRender: false })
});
}
render() {
/*Screen SCAN*/
const scanScreen = () => (
<QRCodeScanner
showMarker
ref={(node) => {
this.scanner = node
}}
reactivate={false}
cameraProps={{captureAudio: false}}
onRead={this.onSuccess.bind(this)}
showMarker={true}
cameraStyle={{height: SCREEN_HEIGHT}}
fadeIn={true}
customMarker={
<View style={{flex: 1}}>
<Modal isVisible={this.state.isModalVisible}
style={{backgroundColor: '#E8E8E8', borderRadius: 30, height: 100}}>
<View style={{flex: 1}}>
<Text></Text>
<Text> Qr code data: {this.state.code}</Text>
<Button onPress={this._activate} title="Close" color="#841584"
accessibilityLabel="Learn more about this purple button"/>
</View>
</Modal>
</View>
}
/>
);
const historyScreen = () => (
<View style={{backgroundColor: '#ff4081'}}>
</View>
);
const favScreen = () => (
<View style={{backgroundColor: '#a95'}}>
</View>
);
_renderLazyPlaceholder = () => {
return (
<ActivityIndicator size="large" color="red" />
);
};
{
return (
<View style={{flex: 1}}>
{this.state.isRender &&
<TabView
lazy
navigationState={this.state}
renderScene={SceneMap({
scan: scanScreen,
history: historyScreen,
fav: favScreen,
})}
renderLazyPlaceholder={this._renderLazyPlaceholder}
onIndexChange={(index) => this.setState({index})}
initialLayout={{width: SCREEN_WIDTH, height: SCREEN_HEIGHT}}
renderIcon={({route}) => (
<IconMI
name={route.icon}
size={15}
color={'white'}
/>
)}
/>
}
</View>
)
}
}
render() {
{
return (
<View style={{flex: 1}}>
<TouchableOpacity onPress={this._toggleModal}>
<Text>Show Modal</Text>
</TouchableOpacity>
<Modal isVisible={this.state.isModalVisible}>
<View style={{flex: 1}}>
<Text>Hello!</Text>
<TouchableOpacity onPress={this._toggleModal}>
<Text>Hide me!</Text>
</TouchableOpacity>
</View>
</Modal>
</View>
);
}
<View style={{flex: 1}}>
<Modal
onBackdropPress={this._activate}
isVisible={this.state.isModalVisible} style={{backgroundColor:'#E8E8E8', borderRadius:3, marginTop: SCREEN_HEIGHT*0.2, marginBottom: SCREEN_HEIGHT*0.2}}>
<View style={{ flex: 1 }}>
<Text></Text>
<Text> Qr code data: {this.state.code}</Text>
<Button onPress={this._activate} title="Close" color="#841584" accessibilityLabel="Learn more about this purple button"/>
</View>
</Modal>
{ this.state.isRender &&
<QRCodeScanner
showMarker
ref={(node) => { this.scanner = node }}
reactivate={false}
onRead={this.onSuccess.bind(this)}
showMarker={true}
cameraStyle={{ height: SCREEN_HEIGHT }}
fadeIn={true}
/>
}
</View>
)}
}
}
RkTheme.setType('RkButton', 'dark', {
container: {
paddingTop: 10,
backgroundColor: 'gray',
borderRadius: 90,
paddingTop:10,
backgroundColor: 'gray',
borderRadius: 90,
}
});
});
const rectDimensions = SCREEN_WIDTH * 0.85; // this is equivalent to 255 from a 393 device width
@ -176,31 +113,35 @@ const rectDimensions = SCREEN_WIDTH * 0.85; // this is equivalent to 255 from a
const overlayColor = 'rgba(0,0,0,0.30)';
const styles = {
recover: {
paddingTop: 10,
recover:{
paddingTop:10,
color: "red",
paddingBottom: 10
paddingBottom:10
},
manual: {},
manual:{
logo: {
},
logo:{
height: SCREEN_HEIGHT * 0.35,
width: SCREEN_WIDTH,
height:SCREEN_HEIGHT*0.35,
width:SCREEN_WIDTH,
backgroundColor: overlayColor,
},
rectangleContainer: {
flex: 1,
alignItems: "center",
justifyContent: "center",
backgroundColor: "transparent",
},
rectangle: {
height: rectDimensions,
width: rectDimensions,
alignItems: "center",
@ -228,4 +169,24 @@ const styles = {
width: SCREEN_WIDTH,
backgroundColor: overlayColor
},
};
};
function mapStateToProps(state, props) {
return {
token: state.apiReducer.token,
user: state.apiReducer.user,
internalToken: state.apiReducer.internalToken,
cromos: state.apiReducer.cromos
};
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(Actions, dispatch);
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(Scan);

View File

@ -6,7 +6,8 @@ export const CREATE_TEAM='CREATE_TEAM'
export const DELETE_TEAM='DELETE_TEAM'
export const GET_CROMOS='GET_CROMOS'
export const GET_LOCS_VISITED= 'GET_LOCS_VISITED'
export const SCAN_QR = 'SCAN_QR'
export const LOGIN_INTERNAL ='LOGIN_INTERNAL'
//API BLUETREND

View File

@ -29,7 +29,9 @@ import {
CREATE_TEAM,
DELETE_TEAM,
GET_CROMOS,
GET_LOCS_VISITED
GET_LOCS_VISITED,
SCAN_QR,
LOGIN_INTERNAL
} from "./actionTypes"; //Import the actions types constant we defined in our actions
import moment from "moment";
@ -46,6 +48,29 @@ axios.defaults.baseURL = "https://api.enei.pt/internal/api";
const map = require("lodash/fp/map").convert({ cap: false });
export function scanQrCode(data,tokenInternal){
axios.defaults.baseURL = "https://api.enei.pt";
axios.defaults.headers.common = {
Authorization: `bearer ${tokenInternal}`
};
console.log(data)
return dispatch => {
axios
.post("/api/Scan", data)
.then(a => {
console.log(a.data);
Alert.alert("SUCESSO!", a.data);
dispatch({
type: SCAN_QR
});
})
.catch(err => {
console.log(err);
Alert.alert("ERRO!", "Existiu um no scan do QRCode");
});
};
}
export function getEventLocsVisited(teamId, tokenInternal ) {
axios.defaults.headers.common = {
Authorization: `bearer ${tokenInternal}`
@ -385,24 +410,29 @@ export function changePassword(token, old, new1, new2) {
};
}
//faz autenticação com API interna
export function loginInternal(userDetails) {
axios.defaults.baseURL = "http://127.0.0.1:5000";
export function loginInternal(user,t) {
axios.defaults.baseURL = "https://api.enei.pt";
console.log(user)
return dispatch => {
axios
.post("/api/login", {
username: "cena",
password: "password"
.post("/api/loginQR", {
Qrcode: user.Code,
token: t.access_token
})
.then(a => {
console.log("sucesso!");
console.log(a);
dispatch({
type: LOGIN_INTERNAL,
internalToken:a.data.token
});
})
.catch(p => {
console.log(p);
Alert.alert("Erro","Existiu um erro a obter o token... Contacta a comissão se vires esta mensagem de erro.")
});
dispatch({
type: OPEN_MODAL
type: LOGIN_INTERNAL,
internalToken:'error'
});
};
}

View File

@ -28,7 +28,8 @@ export {checkUser,
createTeam,
deleteTeam,
getCromos,
getEventLocsVisited
getEventLocsVisited,
scanQrCode
} from "./api"

View File

@ -23,7 +23,9 @@ import {
GET_INTERNAL_EVENTS,
CREATE_TEAM,
GET_CROMOS,
GET_LOCS_VISITED
GET_LOCS_VISITED,
SCAN_QR,
LOGIN_INTERNAL
} from "../actions/actionTypes"; //Import the actions types constant we defined in our actions
import { REHYDRATE } from "redux-persist";
@ -31,7 +33,7 @@ import { REHYDRATE } from "redux-persist";
let apiState = {
isConnected: false,
logged: false,
onHold: true,
onHold: false,
user: {},
events: [],
showAlert: true,
@ -115,7 +117,8 @@ const apiReducer = (state = apiState, action) => {
alimentacao: action.payload.apiReducer.alimentacao,
acesso: action.payload.apiReducer.acesso,
alojamento: action.payload.apiReducer.alojamento,
internalToken:"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxIiwidW5pcXVlX25hbWUiOiJjZW5hIiwicm9sZSI6IkFkbWluIiwibmJmIjoxNTUyODcwODcwLCJleHAiOjE1NTU0NTkyNzAsImlhdCI6MTU1Mjg3MDg3MH0.wkBk-CUDMCaU-K9jI0pTRJ794IGCl-C9md39dMfHqa5zTf-gNpD76xEYea3PhIbW2dnUVgo0m1fxR1sW7k9LMg"
internalToken:"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxIiwidW5pcXVlX25hbWUiOiJjZW5hIiwicm9sZSI6IkFkbWluIiwibmJmIjoxNTUyODcwODcwLCJleHAiOjE1NTU0NTkyNzAsImlhdCI6MTU1Mjg3MDg3MH0.wkBk-CUDMCaU-K9jI0pTRJ794IGCl-C9md39dMfHqa5zTf-gNpD76xEYea3PhIbW2dnUVgo0m1fxR1sW7k9LMg",
cromos: action.payload.apiReducer.cromos
};
}
@ -124,6 +127,10 @@ const apiReducer = (state = apiState, action) => {
cromos: action.cromos
});
case LOGIN_INTERNAL:
return Object.assign({}, state, {
internalToken: action.internalToken
});
case GET_LOCS_VISITED:
return Object.assign({}, state, {
locais: action.locais
@ -185,7 +192,7 @@ const apiReducer = (state = apiState, action) => {
case CHECK_USER:
state = Object.assign({}, state, {
logged: action.logged,
onHold: action.onHold,
onHold: false,
// userDetails: u,
token: action.token
});