-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.jsx
107 lines (95 loc) · 3.35 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import React from 'react'
import ref from 'ssb-ref'
import MDLSpinner from 'patchkit-mdl-spinner'
import { InviteErrorExplanation, InviteErrorHelp } from './help'
import t from 'patchwork-translations'
export default class PubInvite extends React.Component {
static propTypes = {
setIsHighlighted: React.PropTypes.func.isRequired,
setIsValid: React.PropTypes.func.isRequired,
code: React.PropTypes.string
}
static contextTypes = {
ssb: React.PropTypes.object.isRequired
}
constructor(props) {
super(props)
this.state = {
code: this.props.code,
info: false,
error: false,
isProcessing: false
}
}
onChange(e) {
this.setState({ code: e.target.value })
}
componentDidMount() {
this.props.setIsHighlighted(true)
this.props.setIsValid(true)
}
getValues(cb) {
cb({ code: this.state.code })
}
submit(cb) {
this.getValues(values => {
let code = values.code || ''
this.setState({ isProcessing: true, error: false, info: false })
// surrounded by quotes?
// (the scuttlebot cli ouputs invite codes with quotes, so this could happen)
if (code.charAt(0) == '"' && code.charAt(code.length - 1) == '"')
code = code.slice(1, -1) // strip em
// validate
if (!code)
return this.setState({ isProcessing: false, error: { message: t('invite.CodeNotProvided') } })
if (!ref.isInvite(code))
return this.setState({ isProcessing: false, error: { message: t('invite.InvalidCode') } })
// use the invite
this.setState({ info: t('invite.Contacting') })
this.context.ssb.invite.accept(code, err => {
if (err) {
console.error(err)
return this.setState({ isProcessing: false, info: false, error: err })
}
// trigger sync with the pub
this.context.ssb.gossip.connect(code.split('~')[0])
cb()
})
})
}
render() {
const msg = (this.state.error) ?
<InviteErrorExplanation error={this.state.error} /> :
(this.state.info || '')
const helpText = (this.state.error) ? <InviteErrorHelp error={this.state.error} /> : ''
return <div>
<h1>{t('invite.JoinPub')}</h1>
<h3>{t('invite.JoinPubInfo')}</h3>
<form className="fullwidth" onSubmit={e=>e.preventDefault()}>
<fieldset>
<input type="text" value={this.state.code} onChange={this.onChange.bind(this)} placeholder={t('invite.EnterCode')}/>
<div>{msg}</div>
<div>{helpText}</div>
</fieldset>
</form>
{ this.state.isProcessing ? <MDLSpinner /> : '' }
<div className="faq text-center">
{ this.props.gotoNextStep ?
<div><a onClick={this.props.gotoNextStep}>{t('invite.CanSkip')}</a>{t('invite.CanSkip2')}</div>
: '' }
<div className="faq-entry">
<div>{t('invite.q.WhatIs')}</div>
<div>{t('invite.a.WhatIs')}</div>
</div>
<div className="faq-entry">
<div>{t('invite.q.WhereCan')}</div>
<div>{t('invite.a.WhereCan')}</div>
</div>
<div className="faq-entry">
<div>{t('invite.q.CanCreate')}</div>
<div>{t('invite.a.CanCreate1')}<a href="http://ssbc.github.io/docs/scuttlebot/howto-setup-a-pub.html" target="_blank">{t('invite.a.CanCreate2')}</a>{t('invite.a.CanCreate3')}</div>
</div>
</div>
</div>
}
}