Skip to content

Commit 90d01f5

Browse files
committed
add isOtherUser prop
1 parent 9e784b9 commit 90d01f5

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ const onSubmit = (name, cb) => { console.log('submit', name); cb() }
1212
<ModalBtn className="fullheight" Form={FormProfileName} formProps={{currentValue: 'bob', className: 'text-center vertical-center', onSubmit: onSubmit}}>
1313
<a className="btn highlighted">Click to open</a>
1414
</ModalBtn>
15-
```
15+
```
16+
17+
If the rename is for another user than the local user, set the `isOtherUser` prop on the form to true.

index.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import React from 'react'
33
export default class FormProfileName extends React.Component {
44
static propTypes = {
55
setIsValid: React.PropTypes.func.isRequired,
6+
setHelpText: React.PropTypes.func.isRequired,
67
onSubmit: React.PropTypes.func.isRequired,
8+
isOtherUser: React.PropTypes.bool,
79
currentValue: React.PropTypes.string,
810
className: React.PropTypes.string
911
}
@@ -15,6 +17,8 @@ export default class FormProfileName extends React.Component {
1517

1618
componentDidMount() {
1719
this.validate(this.state.name) // emit isValid update
20+
if (this.props.isOtherUser)
21+
this.props.setHelpText('You can rename anybody. It will only change for you, but other people will see the name you chose.')
1822
}
1923

2024
onChangeName(e) {
@@ -31,14 +35,14 @@ export default class FormProfileName extends React.Component {
3135
emit(false)
3236
return {
3337
name: name,
34-
error: 'We\'re sorry, your name can only include A-z 0-9 . _ - and cannot have spaces.',
38+
error: 'We\'re sorry, names can only include A-z 0-9 . _ - and cannot have spaces.',
3539
isValid: false
3640
}
3741
} else if (name.slice(-1) == '.') {
3842
emit(false)
3943
return {
4044
name: name,
41-
error: 'We\'re sorry, your name cannot end with a period.',
45+
error: 'We\'re sorry, names cannot end with a period.',
4246
isValid: false
4347
}
4448
} else {
@@ -56,8 +60,11 @@ export default class FormProfileName extends React.Component {
5660
}
5761

5862
render() {
63+
var fallbackCurrentValue = ''
64+
if (this.props.isOtherUser)
65+
fallbackCurrentValue = 'them'
5966
return <div className={this.props.className}>
60-
<h1><span>What would you like to be called?</span></h1>
67+
<h1><span>What would you like {this.props.currentValue||fallbackCurrentValue} to be called?</span></h1>
6168
<form className="block" onSubmit={e=>e.preventDefault()}>
6269
<fieldset>
6370
<div>

0 commit comments

Comments
 (0)