Skip to content

Commit

Permalink
Merge pull request #39 from idanlevi1/master
Browse files Browse the repository at this point in the history
fix double registration and view participants
  • Loading branch information
dansha committed Jun 12, 2018
2 parents 9f067a6 + 89edf4d commit e8e27a7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
22 changes: 19 additions & 3 deletions src/views/adminActivities/EventView.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ class EventView extends Component{
userIdArray:null,
participants:this.props.navigation.state.params.event.participants || [],
process:false,
registeredNow:false,
};
}

async componentWillMount() {
const {params} = this.props.navigation.state
const participants = await makeArrayFromObjects(params.event.participants)
if(params.adminActivityScreen)
currParticipants = params.event.participants
else
currParticipants=params.updateParticipants(params.event.id)
const participants = await makeArrayFromObjects(currParticipants)
if(!this.state.userIdArray){
registeredNow = await this.checkAlreadyRegistered(participants,params.appId)
avatarsArray=[]
phonesArray=[]
userIdArray=[]
Expand All @@ -69,7 +75,7 @@ class EventView extends Component{
avatarsArray.push(userInfo.avatarUrl)
phonesArray.push(userInfo.phone)
userIdArray.push(userInfo.userId)
participants.push({appId:params.appId,name:params.fullName})
registeredNow=true
}
this.setState({
avatarsArray:avatarsArray,
Expand All @@ -78,9 +84,15 @@ class EventView extends Component{
coordinatorData:coordinatorData,
participants:participants,
process:false,
registeredNow:registeredNow
})
}

checkAlreadyRegistered = async(participants,appId) =>{
result = Object.keys(participants).filter(key => {return participants[key].appId===appId}) || []
return result.length > 0
}

deleteActivity = async() =>{
const {params} = this.props.navigation.state
this.setState({process:true})
Expand Down Expand Up @@ -185,16 +197,20 @@ class EventView extends Component{
emptyList={participants.length==0}
/>
:
this.state.phonesArray ?
activity.fullFormatDate >= new Date().toISOString() ?
<EventRegistrationView
participants={this.state.participants}
appId={params.appId}
process={this.state.process}
registerUserEventHandler={this.registerUserEventHandler}
registeredNow={this.state.registeredNow}
/>
:
<Text style={[styles.participantText,{margin:5,paddingTop:10,paddingBottom:15,fontWeight: 'bold'}]}>הרישום לפעילות זו הסתיים</Text>
}
:
null
}
</View>
)
}
Expand Down
15 changes: 1 addition & 14 deletions src/views/institutes/EventRegistrationView.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,25 @@ import { FontAwesome } from '@expo/vector-icons';
class EventRegistrationView extends Component{
state = {
displayCancelEventDialog: false,
alreadyRegistered:null,
}

async componentWillMount(){
alreadyRegistered = await this.checkAlreadyRegistered(this.props.appId)
this.setState({alreadyRegistered:alreadyRegistered})
}

showCancelEventDialog = () =>
this.setState({displayCancelEventDialog: true})

hideCancelEventDialog = () =>
this.setState({displayCancelEventDialog: false});

checkAlreadyRegistered = async(appId) =>{
participants = this.props.participants
result = Object.keys(participants).filter(key => {return participants[key].appId===appId}) || []
return result.length > 0
}

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

render() {
return (
<View>
{this.state.alreadyRegistered ?
{ this.props.registeredNow ?
<TouchableOpacity onPress={() => alert('אתה כבר רשום לפעילות זו')}>
<View style={[styles.cancelButton,{backgroundColor:'#009B77'}]}>
<Text style={styles.cancelText}>נרשמת לפעילות</Text>
Expand Down
7 changes: 6 additions & 1 deletion src/views/institutes/SelectDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ class SelectDate extends Component {
addUserToEvent: this.props.addUserToEvent,
userId:this.props.userId,
appId:this.props.appId,
fullName:this.props.fullName
fullName:this.props.fullName,
updateParticipants: this.updateParticipants,
})
}

updateParticipants = (eventId)=>{
return this.props.events[eventId].participants
}

render() {
return (
<SelectDateView
Expand Down

0 comments on commit e8e27a7

Please sign in to comment.