Skip to content

Commit 40ccea8

Browse files
committed
update get_text and requests
1 parent 6fdc717 commit 40ccea8

File tree

13 files changed

+68
-270
lines changed

13 files changed

+68
-270
lines changed

src/components/App.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from 'react'
22
import {withRouter} from 'react-router-dom'
3-
import {google_analytics, requests, async_start} from '../utils'
3+
import {google_analytics, request, async_start} from '../utils'
44
import Error from './shared/Error'
55
import Contractors from './contractors/Contractors'
66
import PlainEnquiry from './enquiry/PlainEnquiry'
@@ -16,15 +16,24 @@ class App extends Component {
1616
enquiry_form_info: null,
1717
}
1818
this.url = props.url_generator
19-
this.get_text = (...args) => this.props.config.get_text(...args)
2019

2120
this.get_enquiry = this.get_enquiry.bind(this)
2221
this.set_enquiry = this.set_enquiry.bind(this)
2322

2423
this.ga_event = this.ga_event.bind(this)
24+
this.request = request.bind(this)
2525
this.requests = {
26-
get: (...args) => requests.get(this, ...args),
27-
post: (...args) => requests.post(this, ...args),
26+
get: (path, args, config) => {
27+
config = config || {}
28+
config.args = args
29+
return this.request('GET', path, config)
30+
},
31+
post: (path, data, config) => {
32+
config = config || {}
33+
config.send_data = data
34+
config.expected_statuses = config.expected_statuses || [201]
35+
return this.request('POST', path, config)
36+
}
2837
}
2938
}
3039

src/components/appointments/Appointments.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,13 @@ class Appointments extends Component {
183183
to={this.page_url(this.state.page - 1)}
184184
onClick={() => setTimeout(() => this.update(), 0)}
185185
className={'tcs-previous' + (this.state.page > 1 ? '' : ' tcs-disable')}>
186-
‹‹ {this.props.root.get_text('previous')}
186+
‹‹ {this.props.config.get_text('previous')}
187187
</Link>
188188
<Link
189189
to={this.page_url(this.state.page + 1)}
190190
onClick={() => setTimeout(() => this.update(), 0)}
191191
className={'tcs-next' + (this.state.more_pages ? '' : ' tcs-disable')}>
192-
{this.props.root.get_text('next')} &rsaquo;&rsaquo;
192+
{this.props.config.get_text('next')} &rsaquo;&rsaquo;
193193
</Link>
194194
</div>
195195
</If>

src/components/appointments/AptModal.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@ import Modal from '../shared/Modal'
66
const get_attendees = (appointment_attendees, apt_id) => (appointment_attendees && appointment_attendees[apt_id]) || []
77
const NEW_STUDENT_ID = 999999999
88

9+
const AptDetails = ({apt, spaces_available, props}) => (
10+
<div className="tcs-modal-flex">
11+
<div className="tcs-extra">
12+
<div className="tcs-price">
13+
{props.config.format_money(apt.price)}
14+
<div className="tcs-label">Price</div>
15+
</div>
16+
</div>
17+
<div className="tcs-content">
18+
<DetailGrid>
19+
<Detail label="Job">{apt.service_name}</Detail>
20+
{apt.attendees_max && <Detail label="Spaces Available">{spaces_available}</Detail>}
21+
<Detail label="Start" className="tcs-new-line">{props.config.format_datetime(apt.start)}</Detail>
22+
<Detail label="Finish">{props.config.format_datetime(apt.finish)}</Detail>
23+
{apt.location && <Detail label="Location">{apt.location}</Detail>}
24+
</DetailGrid>
25+
</div>
26+
</div>
27+
)
28+
929
const AddExisting = ({students, book, booking_allowed, get_text}) => (
1030
students && students.length > 0 &&
1131
<div className="tcs-book-existing">
@@ -157,24 +177,7 @@ class AptModal extends Component {
157177
const booking_allowed = this.state.booking_allowed && spaces_available > 0
158178
return (
159179
<Modal history={this.props.history} title={title} last_url={this.props.last_url} flex={false}>
160-
<div className="tcs-modal-flex">
161-
<div className="tcs-extra">
162-
<div className="tcs-price">
163-
{this.props.config.format_money(apt.price)}
164-
<div className="tcs-label">Price</div>
165-
</div>
166-
</div>
167-
<div className="tcs-content">
168-
<DetailGrid>
169-
<Detail label="Job">{apt.service_name}</Detail>
170-
{apt.attendees_max && <Detail label="Spaces Available">{spaces_available}</Detail>}
171-
<Detail label="Start" className="tcs-new-line">{this.props.config.format_datetime(apt.start)}</Detail>
172-
<Detail label="Finish">{this.props.config.format_datetime(apt.finish)}</Detail>
173-
{apt.location && <Detail label="Location">{apt.location}</Detail>}
174-
</DetailGrid>
175-
</div>
176-
</div>
177-
180+
<AptDetails apt={apt} spaces_available={spaces_available} props={this.props}/>
178181
<div>
179182
<DisplayExtraAttrs extra_attributes={apt.service_extra_attributes}/>
180183
<div className="tcs-book">
@@ -183,17 +186,17 @@ class AptModal extends Component {
183186
<AddExisting students={students}
184187
book={this.book}
185188
booking_allowed={booking_allowed}
186-
get_text={this.props.root.get_text}/>
189+
get_text={this.props.config.get_text}/>
187190
<AddNew new_student={this.state.new_student}
188191
onChange={e => this.setState({new_student: e.target.value})}
189192
book={this.book}
190193
booking_allowed={booking_allowed}
191-
get_text={this.props.root.get_text}/>
194+
get_text={this.props.config.get_text}/>
192195
</div>
193196
</If>
194197
<If v={!this.state.display_data && booking_allowed}>
195198
<button className="tcs-button tcs-signin" onClick={this.props.signin}>
196-
{this.props.root.get_text('book_appointment_button')}
199+
{this.props.config.get_text('book_appointment_button')}
197200
</button>
198201
</If>
199202
</div>

src/components/appointments/Session.js

Lines changed: 0 additions & 201 deletions
This file was deleted.

src/components/contractors/ConModal.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class ConModal extends Component {
5656
<Modal history={this.props.history} title={contractor.name} last_url={this.props.last_url}>
5757
<div className="tcs-extra">
5858
<Photo contractor={contractor} config={this.props.config}/>
59-
60-
<Stars contractor={contractor} root={this.props.root}/>
59+
<Stars contractor={contractor} config={this.props.config}/>
6160

6261
<div className="tcs-location">
6362
<Location/>
@@ -66,10 +65,10 @@ class ConModal extends Component {
6665

6766
<IfElse v={this.state.show_enquiry}>
6867
<button className="tcs-button" onClick={this.switch_view}>
69-
{this.props.root.get_text('contractor_details_button', {contractor_name: contractor.name})}
68+
{this.props.config.get_text('contractor_details_button', {contractor_name: contractor.name})}
7069
</button>
7170
<button className="tcs-button" onClick={this.switch_view}>
72-
{this.props.root.get_text('contractor_enquiry_button', {contractor_name: contractor.name})}
71+
{this.props.config.get_text('contractor_enquiry_button', {contractor_name: contractor.name})}
7372
</button>
7473
</IfElse>
7574
</div>
@@ -86,7 +85,7 @@ class ConModal extends Component {
8685
{/*else:*/}
8786
<ConDetails contractor={contractor}
8887
contractor_extra={contractor_extra}
89-
get_text={this.props.root.get_text}/>
88+
get_text={this.props.config.get_text}/>
9089
</IfElse>
9190

9291
</div>

0 commit comments

Comments
 (0)