Permalink
Browse files

Add screen working and posting to server

  • Loading branch information...
ehelin committed Feb 10, 2019
1 parent d6c8109 commit 2dfd9490c1dc6dd37c462132e152cff6e5ab5fed
@@ -9,12 +9,12 @@ class Add extends React.Component {
constructor(props) {
super(props);
this.state = {
name: null,
dateCreated: null,
bucketListItemType: null,
name: '',
dateCreated: new Date().toLocaleDateString('en-US'),
bucketListItemType: 'Cool',
completed: null,
latitude: null,
longitude: null
latitude: '',
longitude: ''
};
}

@@ -62,9 +62,11 @@ class Add extends React.Component {
<tr>
<td>
<label>Category:</label>
<select id="USER_CONTROL_ADD_ITEM_CATEGORY" value={bucketListItemType}>
<select id="USER_CONTROL_ADD_ITEM_CATEGORY"
value={bucketListItemType}
onChange={event => this.setState({ bucketListItemType: event.target.value })} >
<option value="Hot">Hot</option>
<option value="Warm" selected="selected">Warm</option>
<option value="Warm">Warm</option>
<option value="Cool">Cool</option>
</select>
</td>
@@ -77,7 +79,7 @@ class Add extends React.Component {
type="checkbox"
value={completed}
onChange={event => this.setState({ completed: event.target.value })}
checked
//checked
/>
</td>
</tr>
@@ -18,7 +18,7 @@ class Table extends React.Component {
<td>{bucketListItem.name}</td>
<td>{bucketListItem.dateCreated}</td>
<td>{bucketListItem.bucketListItemType}</td>
<td>{bucketListItem.completed}</td>
<td>{bucketListItem.completed === true ? 'true' : 'false'}</td>
<td>{bucketListItem.latitude}</td>
<td>{bucketListItem.longitude}</td>
</tr>);
@@ -2,7 +2,7 @@
var constantsRef = require('../common/Constants');
var sessionRef = require('../common/Session');

const ACTION_TYPE_ADD = 'Add';
const ACTION_TYPE_ADD_TO_SERVER = 'AddToServer';
const ACTION_TYPE_CANCEL = 'Cancel';

const initialState = {
@@ -28,7 +28,7 @@ export const actionCreators = {
) => async (dispatch, getState) => {
dispatch
({
type: ACTION_TYPE_ADD,
type: ACTION_TYPE_ADD_TO_SERVER,
name,
dateCreated,
bucketListItemType,
@@ -42,8 +42,41 @@ export const actionCreators = {
export const reducer = (state, action) => {
state = state || initialState;

if (action.type == ACTION_TYPE_ADD) {
alert('Add Reducer Event -> implement');
if (action.type == ACTION_TYPE_ADD_TO_SERVER) {
var constants = Object.create(constantsRef.Constants);
var session = Object.create(sessionRef.Session);

var utils = Object.create(utilsRef.Utilities);
var host = utils.GetHost();

var userName = session.SessionGet(constants.SESSION_USERNAME);
var completed = action.completed == 'on' ? 'true' : 'false';

const url = host + '/BucketListItem/AddBucketListItem'
+ '?Name=' + action.name
+ '&DateCreated=' + action.dateCreated
+ '&BucketListItemType=' + action.bucketListItemType
+ '&Completed=' + completed
+ '&Latitude=' + action.latitude
+ '&Longitude=' + action.longitude
+ '&DatabaseId=' + ''
+ '&UserName=' + userName
+ '&encodedUser=' + btoa(userName)
+ '&encodedToken=' + btoa(session.SessionGet(constants.SESSION_TOKEN));

const xhr = new XMLHttpRequest();
xhr.open('post', url, true);
xhr.onload = (data) => {
if (data && data.currentTarget
&& data.currentTarget && data.currentTarget.response
&& data.currentTarget.response.length > 0
&& data.currentTarget.response === 'true') {
window.location = host + '/main';
} else {
alert('Add failed');
}
};
xhr.send();
}
else if (action.type === ACTION_TYPE_CANCEL) {
var utils = Object.create(utilsRef.Utilities);

0 comments on commit 2dfd949

Please sign in to comment.