Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Jake/settings (#60)
Browse files Browse the repository at this point in the history
* backend support

* amplify

* Basic create settings progress

* Initial settings page on sign up

* Create manager settings works after making an account

* Finished settings account creation and update in settings tab
Added bootstrap error message instead of alert

* Small star rating fix

* Fixed bug from merging

Co-authored-by: evansegaul <[email protected]>
Co-authored-by: jsladerman <[email protected]>
  • Loading branch information
3 people authored Aug 2, 2020
1 parent 5e5e532 commit a9fe848
Show file tree
Hide file tree
Showing 13 changed files with 432 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"Timeout": "25",
"Code": {
"S3Bucket": "amplify-cleanviewweb-dev-143211-deployment",
"S3Key": "amplify-builds/AccountSettingsLambda-4c66787172322f436537-build.zip"
"S3Key": "amplify-builds/AccountSettingsLambda-4e6f34627a48316b3471-build.zip"
}
}
},
Expand Down
36 changes: 0 additions & 36 deletions amplify/backend/function/AccountSettingsLambda/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,6 @@ const convertUrlType = (param, type) => {
}
}

/********************************
* Template: HTTP Get method for list objects *
********************************/

app.get(path + hashKeyPath, function(req, res) {
var condition = {}
condition[partitionKeyName] = {
ComparisonOperator: 'EQ'
}

if (userIdPresent && req.apiGateway) {
condition[partitionKeyName]['AttributeValueList'] = [req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH ];
} else {
try {
condition[partitionKeyName]['AttributeValueList'] = [ convertUrlType(req.params[partitionKeyName], partitionKeyType) ];
} catch(err) {
res.statusCode = 500;
res.json({error: 'Wrong column type ' + err});
}
}

let queryParams = {
TableName: tableName,
KeyConditions: condition
}

dynamodb.query(queryParams, (err, data) => {
if (err) {
res.statusCode = 500;
res.json({error: 'Could not load items: ' + err});
} else {
res.json(data.Items);
}
});
});

/*****************************************
* HTTP Get method for get single account by ID *
*****************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"Timeout": "25",
"Code": {
"S3Bucket": "amplify-cleanviewweb-dev-143211-deployment",
"S3Key": "amplify-builds/ManageLocationLambda-71414e2f77625a6d6630-build.zip"
"S3Key": "amplify-builds/ManageLocationLambda-4c36646c4d654a413039-build.zip"
}
}
},
Expand Down
5 changes: 3 additions & 2 deletions src/Components/Dashboard/LocationBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ class LocationBox extends Component {
renderRating = () => {
const arr = [];
const starImg = require('../../images/star.svg');
let fractionalWidth = 16 * (this.props.rating % 1);
// fractionalWidth = 16 * (fractionalWidth === 0 ? 1 : fractionalWidth);
const ratingFraction = this.props.rating % 1;
let fractionalWidth = 16 * (ratingFraction === 0 ? 1 : ratingFraction);
fractionalWidth = (this.props.rating !== 0 ? fractionalWidth : 0);
for (let i = 0; i < this.props.rating - 1; i++) {
arr.push(<div key={i} style={{
backgroundImage: 'url(' + starImg + ')',
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Dashboard/LocationsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class LocationsTable extends Component {
key={loc.id + 'key'}
imageUrl={loc.imageUrl}
id={loc.id}
rating={3.5}
rating={0}
/>
)
});
Expand Down
24 changes: 0 additions & 24 deletions src/Components/Dashboard/Settings.js

This file was deleted.

96 changes: 96 additions & 0 deletions src/Components/Dashboard/SettingsBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React, {Component} from 'react';
import styles from './css/SettingsBox.module.css';
import {Field, Form, Formik} from "formik";
import Button from "react-bootstrap/Button";
import FormControl from "react-bootstrap/FormControl"

class SettingsBox extends Component {
constructor(props) {
super(props);
this.state = {
settingsInfo: this.props.settingsInfo
}
}

componentDidMount() {
if (!this.state.settingsInfo) {
this.setState({
settingsInfo: {
firstName: '',
lastName: '',
phone: ''
}
})
}
}

render() {
if (!this.state.settingsInfo) {
return null;
}
const phone = this.state.settingsInfo.phone;
let formattedPhoneNum = '';
if (this.state.settingsInfo.phone)
formattedPhoneNum = phone.substr(0, 3) + '-'
+ phone.substr(3, 3)
+ '-' + phone.substr(6, 4);
return (
<div>
<div>
<Formik
initialValues={{
firstName: this.state.settingsInfo.firstName,
lastName: this.state.settingsInfo.lastName,
phone: formattedPhoneNum
}}
onSubmit={this.onSubmit}>
<Form>
<div className={styles.formLabelInputGroup}
style={{marginRight: '20px'}}>
<label className={styles.formLabel}
style={{marginLeft: '12px'}}>First Name</label>
<Field as={FormControl}
className={styles.formInputName} name='firstName'
placeholder='John'/>
</div>
<div className={styles.formLabelInputGroup}>
<label className={styles.formLabel}
style={{marginLeft: '12px'}}>Last Name</label>
<Field as={FormControl}
className={styles.formInputName} name='lastName'
placeholder='Smith'/>
</div>
<br/><br/>
<label className={styles.formLabel}
style={{marginLeft: '12px'}}>Phone Number
</label>
<Field as={FormControl}
className={styles.formInputPhone} name='phone'
placeholder='800-555-1234'/><br/>
<Button type='submit' variant='info'
className={styles.formSubmitBtn}>
Update
</Button>
</Form>
</Formik>
</div>
</div>
);
}

onSubmit = (values) => {
const phoneRegEx = /^\d{3}-\d{3}-\d{4}$/;
if (!phoneRegEx.test(values.phone))
this.props.phoneNumErrorFunc()
else {
values.phone = this.parsePhoneNumber(values.phone)
this.props.submitFunc(values);
}
}

parsePhoneNumber = (phoneNumber) => {
return phoneNumber.split('-').join('');
}
}

export default SettingsBox;
14 changes: 0 additions & 14 deletions src/Components/Dashboard/css/Settings.module.css

This file was deleted.

37 changes: 37 additions & 0 deletions src/Components/Dashboard/css/SettingsBox.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.formLabelInputGroup {
display: inline-block;
width: 48.1%;
}

.formLabel {
font-family: "Roboto", sans-serif;
font-weight: bold;
}

.formInputName {
width: 100%;
}

.formInputPhone {
position: relative;
margin-right: 20px;
width: 100%;
}

.formSubmitBtn {
position: absolute;
font-family: "Roboto", sans-serif;
font-weight: bold;
border-width: 0;
background-color: #30B3CA;
padding: 5px 22px;
right: 30px;
}

.formSubmitBtn:hover {
background-color: #51cbe0;
}

.formSubmitBtn:focus {
background-color: #30B3CA;
}
Loading

0 comments on commit a9fe848

Please sign in to comment.