From 58ffa75fb03f630a5da8787d25725b86cf1f70ab Mon Sep 17 00:00:00 2001 From: Jacques Chen Date: Sat, 22 Feb 2020 22:04:38 -0800 Subject: [PATCH 1/3] simple registration --- App/actions/Login.js | 64 +++++++++++++++++++++++++++++++++ App/components/EventCard.js | 2 +- App/reducers/LoginReducers.js | 13 ++++++- App/screens/EventScreen.js | 67 ++++++++++++++++++++++++++++++++--- android/gradlew | 0 5 files changed, 139 insertions(+), 7 deletions(-) mode change 100644 => 100755 android/gradlew diff --git a/App/actions/Login.js b/App/actions/Login.js index e70887bbd..56297ecf0 100644 --- a/App/actions/Login.js +++ b/App/actions/Login.js @@ -93,6 +93,70 @@ export function populateEvents(events) { } } +export function getRegistrations(id) { + return (dispatch) => { + dispatch(isLoading()); + fetch(AMAZON_API + '/registration/queryStudent?id=' + id) + .then((response) => response.json()) + .then((response) => { + console.log('getRegistration success'); + dispatch(getRegistrationSuccess(response)); + }) + .catch(err => { + console.log('getRegistration failed'); + dispatch(registrationFailed(err)); + }) + } +} + +export function getRegistrationSuccess(response) { + return { + type: 'registrationSuccess', + response + } +} + +export function registrationFailed(err) { + return { + type: 'registrationFailed', + err + } +} + +export function registerUser(id, eventID) { + console.log("hello"); + return (dispatch) => { + dispatch(isLoading()); + const body = JSON.stringify({ + id, + eventID, + registrationStatus: 'registered' + }) + console.log(body) + fetch(AMAZON_API + '/registration/create', { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + body: body + }) + .then((response) => response.json()) + .then((response) => { + console.log(response) + if (response.message == 'Update succeeded') { + dispatch(getRegistrations(id)); + } else { + dispatch(registrationFailed(err)); + } + }) + .catch(err => { + console.log('registration failed'); + dispatch(registrationFailed(err)); + }) + } +} + export function hideSuccess() { return { type: 'hideSuccess' diff --git a/App/components/EventCard.js b/App/components/EventCard.js index 8e9c10e00..1aff2cc11 100644 --- a/App/components/EventCard.js +++ b/App/components/EventCard.js @@ -22,7 +22,7 @@ export default class EventCard extends Component { entry.eventID == eventID); + if (entry.length == 1) { + this.state.disableButton = true; + console.log(this.state.disableButton) + if (entry[0].registrationStatus == 'registered') { + return 'You have registered for this event!' + } else if (entry[0].registrationStatus == 'waitlist') { + return 'You have been added to the waitlist for this event.' + } else if (entry[0].registrationStatus == 'checkedin') { + return "You've checked into this event!" + } + } else { + return 'Click below to register!' + } + } + + handleRegistration(eventID) { + if (!this.state.disableButton) { + this.props.registerUser(this.props.userData.id, eventID); + } + } + render() { + if (this.props.isLoading) { + return ( + + Loading Screen + + ) + } const { navigation } = this.props const event = navigation.getParam('event') return ( {event.ename} {event.edate} {this.getDescription(event)} -