Skip to content

Commit 02e4c7d

Browse files
committed
standalone enquiry forms
1 parent ff72d7f commit 02e4c7d

File tree

5 files changed

+79
-39
lines changed

5 files changed

+79
-39
lines changed

index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
</main>
2525
</body>
2626
<script>
27-
socket('f8d88b6562b3434ba4ef')
27+
socket('f8d88b6562b3434ba4ef', {
28+
mode: 'enquiry',
29+
})
2830
</script>
2931
</html>

src/components/con-modal.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ export default {
7878
}
7979
}
8080
},
81+
created: function () {
82+
this.$root.get_enquiry()
83+
},
8184
}
8285
</script>
8386

@@ -103,6 +106,7 @@ export default {
103106
}
104107
105108
.tcs-content {
109+
flex-grow: 1;
106110
padding-right: 10px;
107111
color: #444;
108112
margin-right: 5px;

src/components/enquiry.vue

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
<div>
33
<div class="tcs-submitted" v-if="submitted" v-html="$root.get_text('enquiry_submitted_thanks', {}, true)"></div>
44
<div v-else>
5-
<p class="tcs">
6-
{{ $root.get_text('contractor_enquiry_message', {contractor_name: contractor.name}) }}
7-
</p>
5+
<div v-if="contractor" class="tcs-centre" v-html="$root.get_text('contractor_enquiry_message', {contractor_name: contractor.name}, true)">
6+
</div>
7+
<div v-else class="tcs-centre" v-html="$root.get_text('enquiry_message', {}, true)">
8+
</div>
89
<form class="tcs" @submit.prevent="submit">
910
<div v-for="field in visible_fields">
1011
<tcs-input :field="field"></tcs-input>
@@ -26,7 +27,12 @@
2627
import input from './input.vue'
2728
2829
export default {
29-
props: ['contractor'],
30+
props: {
31+
contractor: {
32+
type: Object,
33+
default: null,
34+
},
35+
},
3036
components: {
3137
'tcs-input': input
3238
},
@@ -50,6 +56,9 @@ export default {
5056
this.submitted = true
5157
}
5258
},
59+
created: function () {
60+
this.$root.get_enquiry()
61+
},
5362
}
5463
</script>
5564

@@ -61,8 +70,9 @@ form.tcs {
6170
max-width: 450px;
6271
}
6372
64-
p.tcs {
73+
.tcs-centre {
6574
margin: 0 0 10px;
75+
text-align: center;
6676
}
6777
6878
.tcs-submitted {
@@ -77,7 +87,7 @@ p.tcs {
7787
font-size: 17px;
7888
padding: 10px 12px;
7989
border: none;
80-
border-radius: 4px;
90+
border-radius: 5px;
8191
8292
background-color: $button-colour;
8393
color: white;

src/components/modal.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export default {
4343
title: String,
4444
},
4545
created: function () {
46-
this.$root.get_enquiry()
4746
// TODO could do something less ugly here like hide the scroll bar at all times
4847
this.body_overflow_before = document.body.style.overflow
4948
document.body.style.overflow = 'hidden'

src/main.js

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import RavenVue from 'raven-js/plugins/vue'
33
import Vue from 'vue'
44
import VueRouter from 'vue-router'
55
import app from './app'
6+
import enquiry from './components/enquiry'
67
import grid from './components/grid'
78
import con_modal from './components/con-modal'
89
import {to_markdown, clean} from './utils'
@@ -12,37 +13,61 @@ Raven.config(dsn, {release: process.env.RELEASE}).addPlugin(RavenVue, Vue).insta
1213

1314
Vue.use(VueRouter)
1415

15-
const ConfiguredVueRouter = config => new VueRouter({
16-
mode: config.router_mode,
17-
routes: [
18-
{
19-
path: config.url_root,
20-
name: 'index',
21-
component: grid,
22-
children: [
23-
{
24-
path: config.url_root + ':link',
25-
name: 'modal',
26-
component: con_modal,
27-
}
28-
]
29-
},
30-
]
31-
})
16+
const ConfiguredVueRouter = config => {
17+
let routes
18+
if (config.mode === 'grid') {
19+
routes = [
20+
{
21+
path: config.url_root,
22+
name: 'index',
23+
component: grid,
24+
children: [
25+
{
26+
path: config.url_root + ':link',
27+
name: 'modal',
28+
component: con_modal,
29+
}
30+
]
31+
},
32+
]
33+
} else if (config.mode === 'enquiry') {
34+
routes = [
35+
{
36+
path: config.url_root,
37+
name: 'index',
38+
component: enquiry,
39+
},
40+
]
41+
}
42+
return new VueRouter({
43+
mode: config.router_mode,
44+
routes: routes
45+
})
46+
}
3247

3348
const STRINGS = {
3449
skills_label: 'Skills',
3550
contractor_enquiry_message: 'Please enter your details below to enquire about tutoring with {contractor_name}.',
51+
enquiry_message: 'Please enter your details below and we will get in touch with you directly.',
3652
contractor_enquiry_button: 'Contact {contractor_name}',
3753
contractor_details_button: 'Show Profile',
3854
submit_enquiry: 'Submit Enquiry',
3955
enquiry_submitted_thanks: 'Enquiry submitted, thank you.\n\nYou can now close this window.'
4056
}
4157

58+
const MODES = ['grid', 'enquiry']
59+
4260
module.exports = function (public_key, config) {
4361
config = config || {}
4462
let error = null
4563

64+
if (config.mode === undefined) {
65+
config.mode = 'grid'
66+
} else if (!MODES.includes(config.mode)) {
67+
error = `invalid mode "${config.mode}", options are: ${MODES.join(', ')}`
68+
config.mode = 'grid'
69+
}
70+
4671
if (config.api_root === undefined) {
4772
config.api_root = process.env.SOCKET_API_URL
4873
}
@@ -82,7 +107,7 @@ module.exports = function (public_key, config) {
82107
config: config,
83108
error: null,
84109
public_key: public_key,
85-
enquiry_form_info: null,
110+
enquiry_form_info: {},
86111
enquiry_data: {},
87112
},
88113
components: {
@@ -150,7 +175,7 @@ response text: "${xhr.responseText}"`)
150175
return true
151176
},
152177
get_enquiry: function () {
153-
if (this.enquiry_form_info !== null) {
178+
if (Object.keys(this.enquiry_form_info).length !== 0) {
154179
return
155180
}
156181
let xhr = new window.XMLHttpRequest()
@@ -160,22 +185,11 @@ response text: "${xhr.responseText}"`)
160185
if (xhr.status !== 200) {
161186
throw new Error(`bad response ${xhr.status} at "${url}"`)
162187
} else {
163-
this.enquiry_form_info = JSON.parse(xhr.responseText)
188+
this.enquiry_form_info = Object.assign({}, this.enquiry_form_info, JSON.parse(xhr.responseText))
164189
}
165190
}
166191
xhr.send()
167192
},
168-
get_text: function (name, replacements, is_markdown) {
169-
let s = this.config[name]
170-
for (let [k, v] of Object.entries(replacements || {})) {
171-
s = s.replace('{' + k + '}', v)
172-
}
173-
if (is_markdown === true) {
174-
return to_markdown(s)
175-
} else {
176-
return s
177-
}
178-
},
179193
submit_enquiry: function (callback) {
180194
let data = JSON.stringify(clean(this.enquiry_data))
181195
let xhr = new window.XMLHttpRequest()
@@ -195,6 +209,17 @@ response text: "${xhr.responseText}"`)
195209
}
196210
xhr.send(data)
197211
},
212+
get_text: function (name, replacements, is_markdown) {
213+
let s = this.config[name]
214+
for (let [k, v] of Object.entries(replacements || {})) {
215+
s = s.replace('{' + k + '}', v)
216+
}
217+
if (is_markdown === true) {
218+
return to_markdown(s)
219+
} else {
220+
return s
221+
}
222+
},
198223
}
199224
})
200225
}

0 commit comments

Comments
 (0)