Skip to content

Commit 6e25bf6

Browse files
committed
fix subject urls
1 parent 24d7c40 commit 6e25bf6

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/components/contractors/ConModal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const TRANSITION_TIME = 500
99
class ConModal extends Component {
1010
constructor (props) {
1111
super(props)
12+
this.con_id = parseInt(this.props.id, 10)
1213
this.state = {
1314
show_enquiry: false,
1415
transition_class: ''
@@ -19,7 +20,7 @@ class ConModal extends Component {
1920

2021
get_contractor () {
2122
for (let contractor of this.props.contractors) {
22-
if (contractor.link === this.props.con_link) {
23+
if (contractor.id === this.con_id) {
2324
return {contractor, contractor_extra: this.props.get_contractor_details(contractor)}
2425
}
2526
}

src/components/contractors/Contractors.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Contractors extends Component {
3131

3232
subject_change (selected_subject) {
3333
if (selected_subject) {
34-
this.props.history.push(this.props.root.url(`subject/${slugify(selected_subject.name)}`))
34+
this.props.history.push(this.props.root.url(`subject/${selected_subject.id}-${slugify(selected_subject.name)}`))
3535
} else {
3636
this.props.history.push(this.props.root.url(''))
3737
}
@@ -40,10 +40,10 @@ class Contractors extends Component {
4040

4141
async update_contractors (selected_subject) {
4242
if (!selected_subject) {
43-
const m = this.props.history.location.pathname.match(/subject\/([^/]+)/)
44-
const subject_slug = m ? m[1] : null
45-
if (subject_slug && this.state.subjects.length > 0) {
46-
selected_subject = this.state.subjects.find(s => slugify(s.name) === subject_slug)
43+
const m = this.props.history.location.pathname.match(/subject\/(\d+)/)
44+
const subject_id = m ? parseInt(m[1], 10) : null
45+
if (subject_id && this.state.subjects.length > 0) {
46+
selected_subject = this.state.subjects.find(s => s.id === subject_id)
4747
}
4848
}
4949

@@ -84,8 +84,8 @@ class Contractors extends Component {
8484
subject_change={this.subject_change}
8585
root={this.props.root}/>
8686

87-
<Route path={this.props.root.url(':con([0-9]+-.+)')} render={props => (
88-
<ConModal con_link={props.match.params.con}
87+
<Route path={this.props.root.url(':id(\\d+):_extra')} render={props => (
88+
<ConModal id={props.match.params.id}
8989
contractors={this.state.contractors}
9090
got_contractors={this.state.got_contractors}
9191
get_contractor_details={this.get_contractor_details}

src/utils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ export const to_markdown = t => {
1616

1717
export const auto_url_root = path => {
1818
// remove :
19+
// * /subject/.*
1920
// * contractor slug
2021
// * /enquiry
21-
path = path.replace(/\/\d+-[\w-]+$/, '/').replace(/\/enquiry$/, '/')
22+
path = path
23+
.replace(/\/subject\/\d+-[^/]+$/, '/')
24+
.replace(/\/\d+-[^/]+$/, '/')
25+
.replace(/\/enquiry$/, '/')
2226
return path
2327
}
2428

0 commit comments

Comments
 (0)