Skip to content

Commit

Permalink
Merge pull request #88 from nllahat/master
Browse files Browse the repository at this point in the history
issue 82 fix
  • Loading branch information
idanlevi1 authored Feb 20, 2019
2 parents 4a3e638 + b4270f8 commit f102b79
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 35 deletions.
5 changes: 3 additions & 2 deletions src/store/modules/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const deleteParticipantRes = (eventId, insId, newParticipants) => ({
export const getEvents = instituteId => async (dispatch, state) => {
if (state().events.status != 'reqEvents') {
dispatch(eventsReq(instituteId))
res = firebase.database().ref('events/').child(instituteId).once('value',
const res = firebase.database().ref('events/').child(instituteId).once('value',
snapshot => {
dispatch(eventsRes(snapshot.val()));
})
Expand All @@ -96,6 +96,7 @@ export const getEvents = instituteId => async (dispatch, state) => {
.catch(error => {
return 'err'
});

return res;
}
return 'reqEvents'
Expand Down Expand Up @@ -211,4 +212,4 @@ export const deleteParticipant = (activityId, insId, appId) => async (dispatch,
if (eventsState)
dispatch(deleteParticipantRes(activityId, insId, currParticipants))
})
}
}
2 changes: 1 addition & 1 deletion src/views/activities/ActivitiesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {AnimatableView} from '../AnimatableService'
import * as Animatable from 'react-native-animatable'

const renderText = (text)=> {
if (text.length > 17 )
if (text.length > 15 )
return text.slice(0,14)+'...'
return text
}
Expand Down
59 changes: 35 additions & 24 deletions src/views/adminActivities/EventView.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {getUserData, setMessage, makeArrayFromObjects, deleteActivityByUserId} f
import {getUserTokenNotification, sendPushNotification} from '../notification/NotificationService';
import Toast from 'react-native-easy-toast'
import {showToast} from '../../utils/taost';
import * as firebase from "firebase";

export const ParticipantItem = ({avatarUrl, phone, _name, isCoordinator, participant}) => {
return (
Expand Down Expand Up @@ -53,38 +54,48 @@ class EventView extends Component {
};
}

async getEventById () {
const {params} = this.props.navigation.state
const eventId = params.event.id
const instituteId = params.event.institute
let event

await firebase
.database()
.ref('events/')
.child(instituteId)
.child(eventId)
.once('value', snapshot => {
event = snapshot.val()
})

return event
}

async componentWillMount() {
let event = await this.getEventById()
this.state.userIdArray = null
const {params} = this.props.navigation.state
const currParticipants = params.adminActivityScreen ? params.event.participants : params.updateParticipants(params.event.id)
const currParticipants = event.participants || {}
// const currParticipants = params.adminActivityScreen ? params.event.participants : params.updateParticipants(params.event.id)
const participants = await makeArrayFromObjects(currParticipants)

if (!this.state.userIdArray) {
registeredNow = await this.checkAlreadyRegistered(participants, params.appId)
avatarsArray = []
phonesArray = []
userIdArray = []
namesArray = []
coordinatorData = await getUserData(params.event.coordinator)
for (var i in participants) {
userInfo = await getUserData(participants[i].appId)
const registeredNow = await this.checkAlreadyRegistered(participants, params.appId)
const avatarsArray = []
const phonesArray = []
const userIdArray = []
const namesArray = []
const coordinatorData = await getUserData(params.event.coordinator)

for (const key in participants) {
const userInfo = await getUserData(participants[key].appId)

avatarsArray.push(userInfo.avatarUrl)
phonesArray.push(userInfo.phone)
userIdArray.push(userInfo.userId)
namesArray.push(userInfo.name)
}
}
else {
avatarsArray = this.state.avatarsArray
phonesArray = this.state.phonesArray
userIdArray = this.state.userIdArray
coordinatorData = this.state.coordinatorData
userInfo = await getUserData(params.appId)
avatarsArray.push(userInfo.avatarUrl)
phonesArray.push(userInfo.phone)
userIdArray.push(userInfo.userId)
namesArray.push(userInfo.name)
registeredNow = true
}

this.setState({
avatarsArray: avatarsArray,
phonesArray: phonesArray,
Expand Down Expand Up @@ -160,7 +171,7 @@ class EventView extends Component {
res = await addEventToUser(userId, event)
//push notification to the coordinator
if (res === 'ok') {
let coordinatorToken = await getUserTokenNotification(coordinatorData.userId)
let coordinatorToken = await getUserTokenNotification(this.state.coordinatorData.userId)
if (coordinatorToken) {
let title = 'רישום חדש להתנדבות'
let msg = fullName + ' נרשם לפעילות: ' + event.caption
Expand Down
18 changes: 13 additions & 5 deletions src/views/institutes/EventRegistrationView.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ class EventRegistrationView extends Component {
this.setState({displayCancelEventDialog: false});

registration = async () => {
const res = await this.props.registerUserEventHandler(this.state.extraParticipants)
if (res !== 'ok')
alert("שגיאה בהרשמה, אנא נסה שנית מאוחר יותר")
this.hideCancelEventDialog()
debugger
try {
const res = await this.props.registerUserEventHandler(this.state.extraParticipants)

if (res !== 'ok') {
alert("שגיאה בהרשמה, אנא נסה שנית מאוחר יותר")
}

this.hideCancelEventDialog()
} catch (e) {
console.error(e)
}
}

onChanged = (text) => {
Expand Down Expand Up @@ -165,4 +173,4 @@ class EventRegistrationView extends Component {
}
}

export default EventRegistrationView
export default EventRegistrationView
6 changes: 3 additions & 3 deletions src/views/institutes/SelectDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SelectDate extends Component {
return (
<SelectDateView
navigation = {this.props.navigation}
events={this.state.events}
events={this.state.events}
eventDates={this.state.eventDates}
openEventView={this.openEventView}
/>
Expand All @@ -64,7 +64,7 @@ class SelectDate extends Component {

}

mapStateToProps = state =>{
const mapStateToProps = state =>{
return {
events:state.events.events,
userId:state.user.user.userId,
Expand All @@ -73,4 +73,4 @@ mapStateToProps = state =>{
}
}

export default connect (mapStateToProps, {addEventToUser, addUserToEvent})(SelectDate);
export default connect (mapStateToProps, {addEventToUser, addUserToEvent})(SelectDate);

0 comments on commit f102b79

Please sign in to comment.