This commit is contained in:
henrydays 2019-03-16 19:33:07 +00:00
parent d51f6f4478
commit c962779aea
7 changed files with 293 additions and 280 deletions

View File

@ -29,7 +29,8 @@ const formatObj = obj => {
return a;
};
const SCREEN_HEIGHT = Dimensions.get("window").height;
const SCREEN_WIDTH = Dimensions.get("window").width;
class Calendar extends React.Component {
state = {
index: 0,
@ -45,7 +46,7 @@ class Calendar extends React.Component {
};
componentDidMount() {
this.props.getEvents(this.props.user);
this.props.getEvents(this.props.user,this.props.careerPath);
this.props.getSessions(this.props.token);
}
@ -141,7 +142,7 @@ class Calendar extends React.Component {
super();
}
_refresh=()=>{
this.props.getEvents(this.props.user);
this.props.getEvents(this.props.user,this.props.careerPath);
}
@ -315,10 +316,10 @@ class Calendar extends React.Component {
height: Dimensions.get("window").height
}}
style={{ backgroundColor: "#F2F2F2" }}
indicatorStyle={{ backgroundColor: "pink" }}
/>
<Button onPress={this._refresh} title="Refresh" color="#841584"
/>
indicatorStyle={{ backgroundColor: "pink"}}
/><View style={{ alignContent:'center', alignItems:'center', backgroundColor:'transparent',position: 'absolute',marginTop:SCREEN_HEIGHT*0.75,marginLeft:10}}><Button onPress={this._refresh} title="Refresh" color="#CC1A17"
/></View>
</View>

View File

@ -8,9 +8,13 @@ import {
Text,
Button,
TouchableOpacity,
ImageBackground
ImageBackground,
ListView,
FlatList,
ActivityIndicator
} from "react-native";
import moment from "moment";
import { Divider, Icon, Avatar } from "react-native-elements";
import { TabView, TabBar, SceneMap } from "react-native-tab-view";
import { RkButton, RkCard, RkText, RkTheme } from "react-native-ui-kitten";
@ -56,12 +60,15 @@ class calendarDetail extends React.Component {
componentDidMount() {
this.props.getEvents(this.props.user);
console.log("didMount");
console.log(this.props.events);
const { navigation } = this.props;
const info = navigation.getParam("info", "error");
console.log("putas");
console.log(info);
this.props.getSessionDetails(this.props.token, info.Id);
var a = moment(info.SessionStart);
var b = moment(info.SessionEnd);
console.log(b.diff(a, "minutes")); // 44700
}
_update = () => {
@ -75,201 +82,164 @@ class calendarDetail extends React.Component {
this.data = [];
}
renderHeader = info => {
return (
<View style={styles.headerContainer}>
<View style={styles.coverContainer}>
<ImageBackground
source={{
uri: info.imageUrl
}}
style={styles.coverImage}
/>
</View>
</View>
);
};
renderDescription = info => {
return (
<View>
<View style={styles.header}>
<View
style={{
flexDirection: "row",
alignItems: "center",
alignSelf: "center"
}}
>
<View style={styles.timeText}>
<Text style={{ color: "#CC1A17", fontSize: 15 }}>
{info.time === info.timeEnd
? info.time
: `${info.time}H - ${info.timeEnd}H`}
</Text>
</View>
</View>
<View>
<Text
style={{
margin: 10,
marginBottom: 0,
marginTop: 0,
fontSize: 20,
color: "#CC1A17"
}}
>
{info.name}
</Text>
<Text style={{ marginLeft: 10 }}>Workshop</Text>
</View>
<View style={{ margin: 10 }}>
<Progress.Bar
color={"#000000"}
progress={info.Enrolled / info.MaxAttendees}
height={10}
unfilledColor={"white"}
width={210}
/>
<Text>
{info.Enrolled} / {info.MaxAttendees}
</Text>
</View>
<Divider style={{ backgroundColor: "#eeeeee" }} />
<View style={{ flex: 1, flexDirection: "row", marginTop: 10 }}>
<View style={{ width: 100, height: 100, padding: 5 }}>
<FitImage
source={{
uri:
"http://enei2019.uingress.com/adminpoint/Content/Images/Uploads/Speakers/ffb043cb-3073-421c-a070-5d273b50fc23.jpeg"
}}
style={{ padding: 5 }}
/>
</View>
<View>
<Text style={{ fontWeight: "bold", fontSize: 20, margin: 10 }}>
André Duarte
</Text>
<Text style={{ marginLeft: 10 }}>
Project manager at ubiwhere
</Text>
<TouchableOpacity>
<Text style={{ color: "#CC1A17", marginLeft: 10 }}>
website
</Text>
</TouchableOpacity>
</View>
</View>
<View>
<Text
style={{
fontWeight: "bold",
color: "#CC1A17",
margin: 10,
marginBottom: 0,
fontSize: 15
}}
>
Descrição do orador:
</Text>
<Text style={{ margin: 10 }}>
Existem muitas variações das passagens do Lorem Ipsum disponíveis,
mas a maior parte sofreu alterações de alguma forma, pela injecção
de humor, ou de palavras aleatórias que nem sequer parecem
suficientemente credíveis.{" "}
</Text>
</View>
</View>
<View style={styles.block}>
<Text style={{ fontSize: 15, color: "#CC1A17", fontWeight:'bold' }}>Descrição da palestra/workshop</Text>
<Divider style={{ backgroundColor: "#000" }} />
<View style={{ marginTop: 10 }}>
<Text>{info.description}</Text>
</View>
</View>
</View>
);
};
/*
renderMap = () => {
return (
<MapView
provider={PROVIDER_GOOGLE}
style={{flex: 2}}
region={{
latitude: 40.19092111672049,
latitudeDelta: 0.007664297080957283,
longitude: -8.410662319511175,
longitudeDelta: 0.007551424205303192
}}
onRegionChangeComplete={(region) => {
console.log(region);
}}
/>
)
};
*/
renderAttendee = () => {
return (
<View style={{ backgroundColor: "#fff", height: SCREEN_HEIGHT * 0.1 }}>
<View style={styles.AttendeeContainer}>
<View style={styles.leftRow}>
<Avatar
rounded
size="medium"
source={{
uri:
"https://cdn3.iconfinder.com/data/icons/vector-icons-6/96/256-512.png"
}}
/>
</View>
<View style={styles.centerRow}>
<Text style={styles.titleText} numberOfLines={1}>
Nome do gajo
</Text>
</View>
<View style={styles.rightRow}>
<Icon
size={24}
name="visibility"
type="material-icon"
onPress={() => navigation.goBack(null)}
color="#000"
iconStyle={styles.icon}
underlayColor="transparent"
underlineColorAndroid="transparent"
containerStyle={styles.iconContainer}
hitSlop={{ top: 15, bottom: 15, left: 15, right: 15 }}
/>
</View>
</View>
</View>
);
};
render() {
const { navigation } = this.props;
const info = navigation.getParam("info", "error");
if(this.props.sessionDetail==undefined){
return(<View style={{flex:1, alignSelf:'center',margin:SCREEN_HEIGHT*0.45}}>
<ActivityIndicator size="large" color="#CC1A17" />
</View>
)
}
return (
<View style={styles.mainViewStyle}>
<ScrollView style={styles.scroll}>
<View style={styles.container}>
<View style={styles.headerContainer}>
{this.renderHeader(info)}
<View style={styles.headerContainer}>
<View style={styles.coverContainer}>
<ImageBackground
source={{
uri: `https://tickets.enei.pt/adminpoint/Content/Images/Uploads/Sessions/${this.props.sessionDetail.Image}`
}}
style={styles.coverImage}
/>
</View>
</View>
</View>
<View>
<View style={styles.header}>
<View
style={{
flexDirection: "row",
alignItems: "center",
alignSelf: "center"
}}
>
<View style={styles.timeText}>
<Text style={{ color: "#CC1A17", fontSize: 15 }}>
{`${moment(this.props.sessionDetail.SessionStart).format("HH:mm")}H - ${moment(this.props.sessionDetail.SessionEnd).format("HH:mm")}H`}
</Text>
</View>
</View>
<View>
<Text
style={{
margin: 10,
marginBottom: 0,
marginTop: 0,
fontSize: 20,
color: "#CC1A17"
}}
>
{this.props.sessionDetail.Name}
</Text>
</View>
<View style={{ margin: 10 }}>
<Progress.Bar
color={"#000000"}
progress={this.props.sessionDetail.Enrolled / this.props.sessionDetail.MaxAttendees}
height={10}
unfilledColor={"white"}
width={210}
/>
<Text>
{this.props.sessionDetail.Enrolled} / {this.props.sessionDetail.MaxAttendees}
</Text>
</View>
{this.props.sessionDetail != undefined && (
<FlatList
data={this.props.sessionDetail.Speakers}
renderItem={({ item }) => (
<View>
<View
style={{
flex: 1,
flexDirection: "row",
marginTop: 10
}}
>
<View style={{ width: 100, height: 100, padding: 5 }}>
<FitImage
source={{
uri:
"https://tickets.enei.pt/adminpoint/Content/Images/Uploads/Speakers/ffb043cb-3073-421c-a070-5d273b50fc23.jpeg"
}}
style={{ padding: 5 }}
/>
</View>
<View>
<Text
style={{
fontWeight: "bold",
fontSize: 20,
margin: 10
}}
>
{item.Name}
</Text>
<Text style={{ marginLeft: 10 }}>
{item.MoreInfo}
</Text>
<TouchableOpacity>
<Text
style={{ color: "#CC1A17", marginLeft: 10 }}
>
{item.Title}
</Text>
</TouchableOpacity>
</View>
</View>
<View>
<Text
style={{
fontWeight: "bold",
color: "#CC1A17",
margin: 10,
marginBottom: 0,
fontSize: 15
}}
>
Descrição do orador:
</Text>
<Text style={{ margin: 10 }}>{item.Description}</Text>
</View>
</View>
)}
/>
)}
</View>
<View style={styles.block}>
<Text
style={{ fontSize: 15, color: "#CC1A17", fontWeight: "bold" }}
>
Descrição da palestra/workshop
</Text>
<Divider style={{ backgroundColor: "#000" }} />
<View style={{ marginTop: 10 }}>
<Text>{this.props.sessionDetail.Description}</Text>
</View>
</View>
</View>
{this.renderDescription(info)}
</View>
<View style={styles.block}>
<Text style={{ fontSize: 15, color: "#CC1A17",fontWeight:'bold' }}>Localização</Text>
<Text
style={{ fontSize: 15, color: "#CC1A17", fontWeight: "bold" }}
>
Localização
</Text>
<Divider style={{ backgroundColor: "#000", marginBottom: 10 }} />
<Image source={require('../assets/img/campus.png')} style={{width:SCREEN_WIDTH*0.9}}></Image>
<Image
source={require("../assets/img/campus.png")}
style={{ width: SCREEN_WIDTH * 0.9 }}
/>
</View>
</ScrollView>
<Divider style={{ backgroundColor: "black" }} />
@ -481,7 +451,8 @@ function mapStateToProps(state, props) {
user: state.apiReducer.user,
logged: state.apiReducer.logged,
events: state.apiReducer.events,
careerPath: state.apiReducer.careerPath
careerPath: state.apiReducer.careerPath,
sessionDetail: state.apiReducer.sessionDetail
};
}

View File

@ -156,6 +156,7 @@ class choosePath extends React.Component {
};
render() {
const { navigate } = this.props.navigation;
return (
<View>
@ -364,7 +365,7 @@ class choosePath extends React.Component {
<TouchableOpacity
onPress={() =>
this.props.navigation.navigate("febrada")
{ navigate("calendarDetail", { info: item[index] })}
}
>
<View style={styles.sessionInfo}>

View File

@ -12,7 +12,7 @@ export const GET_EVENTS='GET_EVENTS'
export const UPDATE_USER='UPDATE_USER'
export const RESET_PASSWORD='RESET_PASSWORD'
export const CHECK_AND_RENEW='CHECK_AND_RENEW'
export const SESSION_DETAIL='SESSION_DETAIL'

View File

@ -22,7 +22,8 @@ import {
OPEN_MODAL,
LOADINGLOGIN,
REMOVE_SESSION,
UPDATE_USER
UPDATE_USER,
SESSION_DETAIL
} from "./actionTypes"; //Import the actions types constant we defined in our actions
import moment from "moment";
@ -54,9 +55,7 @@ var checkAndRefresh = function(token) {
if (token == undefined || token.access_token == undefined) {
reject("user logged out");
console.log("fds");
} else if (
Math.round(new Date().getTime() / 1000) >= token.expirationDateToken
) {
} else if (Math.round(new Date().getTime() / 1000) >= token.expirationDateToken) {
console.log("vai renovar");
var obj;
@ -95,17 +94,23 @@ var checkAndRefresh = function(token) {
})
.then(res => res.json())
.then(parsed => {
console.log("parsed")
console.log(parsed)
console.log("parsed")
if (parsed.error == "invalid_grant") {
console.log("Erro de invalid grant")
reject("erro");
} else {
}
else {
var obj = {
access_token: parsed.access_token,
refresh_token: parsed.refresh_token,
expirationDateToken:
Math.round(new Date().getTime() / 1000) + 3598
};
resolve(obj);
console.log(parsed);
resolve(obj);
}
});
} else {
@ -204,6 +209,32 @@ export function closeModal() {
};
}
export function getSessionDetails(token, sessionId){
http://enei2019.uingress.com/internal/api/Session/Detail/1
axios.defaults.baseURL = "https://tickets.enei.pt/internal/api";
return dispatch => {
checkAndRefresh(token)
.then(newToken => {
axios.defaults.headers.common = {
Authorization: `bearer ${newToken.access_token}`
};
axios.get(`/Session/Detail/${sessionId}`)
.then(result=>{
console.log(result.data)
dispatch({
type: SESSION_DETAIL,
sessionDetail: result.data,
token:newToken
});
}).catch(err=>{
Alert.alert("ERROR!!", "Aconteceu um erro a obter os detalhes da sessão.")
console.log(err)
})
})
}
}
export function updateUser(token, user) {
axios.defaults.baseURL = "https://tickets.enei.pt/internal/api";
@ -226,7 +257,8 @@ export function updateUser(token, user) {
console.log(a.data);
dispatch({
type: UPDATE_USER,
user: a.data
user: a.data,
token: newToken
});
})
.catch(b => {
@ -354,9 +386,10 @@ export function removeSession(user, token, idSession) {
Blocks: cenas,
changeGuestList: false,
careerPath: careerPath,
user: sucess.data
user: sucess.data,
token: newToken
});
getEvents(user);
getEvents(user,careerPath);
});
})
.catch(function(error) {
@ -454,7 +487,8 @@ export function signSession(user, token, idSession) {
day1: result.a,
day2: result.b,
day3: result.c,
day4: result.d
day4: result.d,
token:newToken
});
});
})
@ -523,7 +557,8 @@ export function getSessions(token) {
type: GET_SESSIONS,
sessions: response.data,
Blocks: cenas,
careerPath: careerPath
careerPath: careerPath,
token: newToken
//guests: response.data
});
})
@ -558,7 +593,8 @@ export function getAvailableGuestlists(token) {
console.log(response);
dispatch({
type: GET_CAREERS,
guests: response.data
guests: response.data,
token: newToken
});
})
.catch(function(error) {
@ -632,7 +668,8 @@ export function changeGuestList(token, guestID) {
type: CHANGE_GUEST,
sessions: response.data,
Blocks: cenas,
careerPath: c
careerPath: c,
token:newToken
//guests: response.data
});
@ -664,8 +701,7 @@ export function getSessionBlocks(sessions) {
const result = flow(
groupBy("SessionStart")
// map((Id) => ({Id})),
//tap(console.log)
)(sessions);
return dispatch => {
@ -706,8 +742,6 @@ export function getAvailableSessions(token) {
const result = flow(
groupBy("SessionStart")
// map((Id) => ({Id})),
//tap(console.log)
)(response.data);
for (let key in result) {
cenas.push(result[key]);
@ -717,8 +751,9 @@ export function getAvailableSessions(token) {
dispatch({
type: GET_SESSIONS,
sessions: response.data,
Blocks: cenas,
token: newToken
Blocks: cenas
});
})
.catch(function(error) {
@ -737,8 +772,9 @@ export function getAvailableSessions(token) {
//ESTA FUNÇÃO TEM MUITO CÓDIGO MAL FEITO...
function getE(user) {
function getE(user, careerPath) {
console.log("career path: ")
var cenas = [];
let events = [];
var alimentacao=[];
@ -805,6 +841,7 @@ function getE(user) {
events.push({
key: i++,
Id: user.Sessions[key].Id,
time: moment(user.Sessions[key].SessionStart).format("HH:mm"),
timeEnd: moment(user.Sessions[key].SessionEnd).format("HH:mm"),
//lineColor:'#009688',
@ -833,6 +870,7 @@ function getE(user) {
for (let key in result["12"]) {
a.push({
Id: result["12"][key].Id,
time: result["12"][key].time,
timeEnd: result["12"][key].timeEnd,
imageUrl:result["12"][key].imageUrl,
@ -846,6 +884,7 @@ function getE(user) {
for (let key in result["13"]) {
b.push({
Id: result["13"][key].Id,
time: result["13"][key].time,
timeEnd: result["13"][key].timeEnd,
imageUrl: result["13"][key].imageUrl,
@ -858,6 +897,7 @@ function getE(user) {
}
for (let key in result["14"]) {
c.push({
Id: result["14"][key].Id,
time: result["14"][key].time,
timeEnd: result["14"][key].timeEnd,
imageUrl: result["14"][key].imageUrl,
@ -871,6 +911,7 @@ function getE(user) {
for (let key in result["15"]) {
d.push({
Id: result["15"][key].Id,
time: result["15"][key].time,
timeEnd: result["15"][key].timeEnd,
imageUrl:result["15"][key].imageUrl,
@ -898,8 +939,8 @@ function getE(user) {
return { a, b, c, d ,ab:alimentacao, acc: acesso, al:alojamento};
}
export function getEvents(user) {
var result = getE(user);
export function getEvents(user,careerPath) {
var result = getE(user,careerPath);
return dispatch => {
dispatch({
@ -1079,10 +1120,10 @@ export function checkUser(token) {
console.log(err);
dispatch({
type: CHECK_USER,
logged: true,
logged: false,
onHold: false,
userDetails: u,
token: obj
token: false
});
})
.then(newToken => {

View File

@ -19,7 +19,8 @@ export {checkUser,
waitLogin,
removeSession,
changePassword,
resetPassword
resetPassword,
getSessionDetails
} from "./api"

View File

@ -18,7 +18,7 @@ import {
LOADINGLOGIN,
REMOVE_SESSION,
UPDATE_USER,
SESSION_DETAIL
} from "../actions/actionTypes"; //Import the actions types constant we defined in our actions
import { REHYDRATE } from "redux-persist";
@ -31,13 +31,14 @@ let apiState = {
events: [],
showAlert: true,
failedAttempt: false,
token:'',
userDetails: {
username: "",
password: "",
token: {
expirationDateToken: 0,
access_token: "",
refresh_token:""
refresh_token: ""
}
},
calendar: {},
@ -51,9 +52,10 @@ let apiState = {
c: {},
d: {},
loadingLogin: false,
alimentacao:[],
acesso:[],
alojamento:[]
alimentacao: [],
acesso: [],
alojamento: [],
sessionDetail:{}
};
const apiReducer = (state = apiState, action) => {
@ -65,31 +67,21 @@ const apiReducer = (state = apiState, action) => {
var expirationDateTokenA = 0;
var access_tokenA = "";
var refresh_tokenA= "puta";
var refresh_tokenA = "puta";
if (action.payload.apiReducer.token != undefined) {
if (
action.payload.apiReducer.token.expirationDateToken !=
undefined
action.payload.apiReducer.token.expirationDateToken != undefined
) {
expirationDateTokenA =
action.payload.apiReducer.token.expirationDateToken;
}
if (
action.payload.apiReducer.token.access_token !=
undefined
) {
access_tokenA =
action.payload.apiReducer.token.access_token;
if (action.payload.apiReducer.token.access_token != undefined) {
access_tokenA = action.payload.apiReducer.token.access_token;
}
if (
action.payload.apiReducer.token.refresh_token !=
undefined
) {
refresh_tokenA =
action.payload.apiReducer.token.refresh_token;
if (action.payload.apiReducer.token.refresh_token != undefined) {
refresh_tokenA = action.payload.apiReducer.token.refresh_token;
}
}
@ -102,12 +94,12 @@ const apiReducer = (state = apiState, action) => {
token: {
expirationDateToken: expirationDateTokenA,
access_token: access_tokenA,
refresh_token:refresh_tokenA,
refresh_token: refresh_tokenA
},
username: action.payload.apiReducer.userDetails.username,
password: action.payload.apiReducer.userDetails.password
},
token:action.payload.apiReducer.token
token: action.payload.apiReducer.token
};
}
@ -116,12 +108,19 @@ const apiReducer = (state = apiState, action) => {
isConnected: action.isConnected
});
case SESSION_DETAIL:
state = Object.assign({}, state, {
token: action.token,
sessionDetail: action.sessionDetail
});
return state;
case UPDATE_USER:
state = Object.assign({}, state, { user:action.user});
return state
state = Object.assign({}, state, { user: action.user , toke: action.token});
return state;
case LOADINGLOGIN:
state = Object.assign({}, state, { loadingLogin: true });
return state;
case HOLD:
state = Object.assign({}, state, { onHold: true });
return state;
@ -139,18 +138,17 @@ const apiReducer = (state = apiState, action) => {
},
loadingLogin: false,
onHold: action.onHold,
token:action.token
token: action.token
});
return state;
case CHECK_USER:
state = Object.assign({}, state, {
logged: action.logged,
onHold: action.onHold,
// userDetails: u,
token:action.token
// userDetails: u,
token: action.token
});
return state;
@ -159,20 +157,18 @@ const apiReducer = (state = apiState, action) => {
state = Object.assign({}, state, {
user: {},
userDetails: {},
token:{},
token: {},
logged: false
});
return state;
case USER_INFO:
state = Object.assign({}, state, {
user: action.user,
loggedIn: action.loggedIn,
onHold: action.onHold,
token: action.token
});
return state;
@ -186,8 +182,7 @@ const apiReducer = (state = apiState, action) => {
d: action.day4,
alimentacao: action.alimentacao,
alojamento: action.alojamento,
acesso:action.acesso
acesso: action.acesso
});
return state;
@ -198,7 +193,8 @@ const apiReducer = (state = apiState, action) => {
Blocks: action.Blocks,
careerPath: action.careerPath,
changingGuest: action.changingGuest,
user: action.user
user: action.user,
token: action.token
});
return state;
@ -220,30 +216,29 @@ const apiReducer = (state = apiState, action) => {
return state;
case SIGN_SESSION:
if(action.sessions==undefined || action.Blocks==undefined || action.user==undefined){
if (
action.sessions == undefined ||
action.Blocks == undefined ||
action.user == undefined
) {
state = Object.assign({}, state, {
changingGuest: false
});
} else {
state = Object.assign({}, state, {
sessions: action.sessions,
Blocks: action.Blocks,
careerPath: action.careerPath,
changingGuest: false,
user: action.user,
a: action.day1,
b: action.day2,
c: action.day3,
d: action.day4,
token: action.token
});
}
else{
state = Object.assign({}, state, {
sessions: action.sessions,
Blocks: action.Blocks,
careerPath: action.careerPath,
changingGuest: false,
user: action.user,
a:action.day1,
b:action.day2,
c:action.day3,
d:action.day4
});
}
return state;
case SESSION_BLOCKS:
@ -258,7 +253,7 @@ const apiReducer = (state = apiState, action) => {
var c = {
guests: action.guests
};
state = Object.assign({}, state, { calendar: c });
state = Object.assign({}, state, { calendar: c, token: action.token });
return state;
@ -267,7 +262,8 @@ const apiReducer = (state = apiState, action) => {
changingGuest: false,
sessions: action.sessions,
Blocks: action.Blocks,
careerPath: action.careerPath
careerPath: action.careerPath,
token: action.token
});
return state;
@ -278,15 +274,17 @@ const apiReducer = (state = apiState, action) => {
case TIMERWAIT_CHANGE:
state = Object.assign({}, state, { Blocks: true });
return state;
case GET_SESSIONS:
state = Object.assign({}, state, {
sessions: action.sessions,
Blocks: action.Blocks,
careerPath: action.careerPath
careerPath: action.careerPath,
token: action.token
});
return state;
default:
return state;
}
};
export default apiReducer;
export default apiReducer;