Skip to content

Commit

Permalink
sprint(wk21-23): Signup features
Browse files Browse the repository at this point in the history
* Use autocomplete in location lookup

* new Posts are created in the proper region

* Event themes are a defined list

* Event End Time is the Start Time set until the Start Time is validated

* Events are filtered by start time by default

When signing up a business, the location placeholder should be 'Name and City'

* Employees should have a first name and last name

* If an employee entry is fully defined, then it should be added with clicking next in the 'Add Employees' stage of signup
  • Loading branch information
mrmod committed Jun 25, 2020
1 parent 08b8160 commit 5c07c10
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.5.1'
ruby '2.7.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.2', '>= 6.0.2.1'
Expand Down
4 changes: 1 addition & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
thor (1.0.1)
thread_safe (0.3.6)
tilt (2.0.10)
Expand Down Expand Up @@ -249,15 +248,14 @@ DEPENDENCIES
selenium-webdriver
spring
spring-watcher-listen (~> 2.0.0)
sqlite3 (~> 1.4)
turbolinks (~> 5)
tzinfo-data
web-console (>= 3.3.0)
webdrivers
webpacker (~> 4.0)

RUBY VERSION
ruby 2.5.1p57
ruby 2.7.1p83

BUNDLED WITH
2.1.4
8 changes: 7 additions & 1 deletion app/javascript/components/EditableEvent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
:format='"YYYY-MM-DD h:mm a"'
v-model='start_time'
v-on:input='startTimeChanged'
v-on:validate='unbindStartTime'
/>
<DatetimePicker
:id='"end_time"'
Expand Down Expand Up @@ -89,6 +90,7 @@ export default {
business_id: this.event.business_id,
parent_id: this.event.parent_id,
errors: null,
bindStartToEnd: true, // When true, setting start time sets the end time
}
}
return {
Expand All @@ -103,17 +105,21 @@ export default {
business_id: this.$currentUser.business_id,
showAddEvent: false,
errors: null,
bindStartToEnd: true, // When true, setting start time sets the end time
}
},
created: function() {
this.allBusinesses()
},
methods: {
startTimeChanged: function(v) {
if (!this.end_time) {
if(this.bindStartToEnd) {
this.end_time = this.start_time
}
},
unbindStartTime() {
this.bindStartToEnd = false
},
themeSelected(v) {
this.theme = this.themes[v].name
},
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/components/Events.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default {
components: {EventList},
data() {
return {
comparator: this.orderByCreated,
comparatorName: 'orderByCreated',
comparator: this.orderByStartTime,
comparatorName: 'orderByStartTime',
}
},
computed: {
Expand Down
102 changes: 102 additions & 0 deletions app/javascript/components/LocationAutocomplete.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<template>
<div class="location-autocomplete">
<div id="search-result" ref="searchResult">
</div>
<md-field>
<label>Business Name and City</label>
<md-input @keypress='tryAutocomplete' v-model='address'>
</md-input>
</md-field>
<md-list class="md-double-line">
<md-list-item
v-for="(p, i) in predictions"
:key='`place.${i}`'
@click='() => getPlace(p)'
:class="{selected: place && p.place_id === place.place_id}"
>
<div class="md-list-item-text">
<span>{{p.description}}</span>
</div>
</md-list-item>
</md-list>
</div>
</template>
<script>
import initGoogle from '../services/google'
export default {
name: 'LocationAutocomplete',
data() {
return {
autocomplete: null,
sessionToken: null,
places: null,
place: null,
address: '',
predictions: [],
}
},
mounted() {
initGoogle.then(google => {
this.places = new google.maps.places.PlacesService(this.$refs.searchResult)
this.autocomplete = new google.maps.places.AutocompleteService()
this.sessionToken = new google.maps.places.AutocompleteSessionToken()
})
},
methods: {
tryAutocomplete(event) {
if (this.address.length > 3) {
const request = {
input: this.address,
// https://developers.google.com/places/supported_types#table3
types: ['establishment'],
sessionToken: this.sessionToken,
}
this.autocomplete.getPlacePredictions(request, this.autocompleteResponse)
}
},
autocompleteResponse(predictions, serviceStatus) {
switch (serviceStatus) {
case 'OK':
this.predictions = predictions
break
default:
console.log(`Service status is not OK: ${serviceStatus}`)
}
},
getPlace(prediction) {
const request = {
placeId: prediction.place_id,
sessionToken: this.sessionToken,
fields: [
'formatted_address',
'name',
'place_id',
'photos',
]
}
this.places.getDetails(request, this.detailsResponse)
},
detailsResponse(place, serviceStatus) {
switch (serviceStatus) {
case 'OK':
console.log('Selectd location', place)
this.$emit('locationSelected', place)
console.log('place', place)
// place.photos[].geturl() => https://image.url
this.place = place
break
default:
console.log(`Service status is not OK: ${serviceStatus}`)
}
}
}
}
</script>

<style scoped>
.selected {
background-color: lightgray;
}
</style>
10 changes: 7 additions & 3 deletions app/javascript/components/LocationFinder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
</div>
<md-field>
<label>Business Name and City</label>
<md-input @keypress='addressSearch' v-model='address' />
<md-input @keypress='handleKeypress' v-model='address' />
</md-field>
<md-button class="md-raised" @click='addressSearch'>Verify address</md-button>
</div>
</template>
<script>
import initGoogle from '../services/google'
export default {
name: 'LocationFinder',
Expand All @@ -24,12 +26,14 @@ export default {
})
},
methods: {
addressSearch(e) {
handleKeypress(e) {
if (e.key !== 'Enter') {
return
}
e.preventDefault()
this.addressSearch()
},
addressSearch() {
if (this.address.length > 3 && this.address.indexOf(' ') > 0) {
// https://developers.google.com/maps/documentation/javascript/reference/places-service#FindPlaceFromQueryRequest
// Uses the Basic Data SKU https://developers.google.com/maps/billing/gmp-billing#basic-data
Expand Down
Loading

0 comments on commit 5c07c10

Please sign in to comment.