-
Notifications
You must be signed in to change notification settings - Fork 0
/
Signup.js
57 lines (51 loc) · 2.16 KB
/
Signup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React from "react";
import { View } from "react-native";
import { Button } from "react-native-material-ui";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { createBooking, cancelParticipant } from "./eventActions";
const buttonStyle = {
container: {
borderWidth: 1,
marginRight: 1,
borderRadius: 5,
borderColor: "#ccc"
}
};
const mapStateToProps = state => ({
contact: state.contactState.selectedContact
});
const mapDispatchToProps = dispatch => ({
participate: (eventID, contact, participant) => dispatch(createBooking(eventID, contact, "", participant)),
decline: (eventID, contact, participant) => dispatch(cancelParticipant(eventID, contact, "", participant))
});
const Signup = ({
eventID, participantsLoading = true, participants, contact, participate, decline, modifyingBooking, ...props
}) => {
let confirmed = false, declined = false;
const participant = participants && participants.find(x => x.PersonID === contact.PersonID);
if(participant){
confirmed = participant.Canceled !== "true";
declined = !confirmed;
}
return (
<View {...props} style={{flexDirection: "row", width: "100%"}}>
<View style={{flex: 1}}>
<Button text="" disabled={modifyingBooking || participantsLoading} raised={confirmed} style={buttonStyle} primary icon="check" onPress={confirmed ? null : () => participate(eventID, contact, participant)} />
</View>
<View style={{flex: 1}}>
<Button text="" disabled={modifyingBooking || participantsLoading} raised={declined} style={buttonStyle} accent icon="cancel" onPress={declined ? null : () => decline(eventID, contact, participant)} />
</View>
</View>
);
};
Signup.propTypes = {
participantsLoading: PropTypes.bool,
participants: PropTypes.array,
eventID: PropTypes.number.isRequired,
participate: PropTypes.func.isRequired,
decline: PropTypes.func.isRequired,
contact: PropTypes.object.isRequired,
modifyingBooking: PropTypes.bool.isRequired
};
export default connect(mapStateToProps, mapDispatchToProps)(Signup);