Validation error for missing API key label

This commit is contained in:
Jori Lallo
2017-05-01 22:29:39 -07:00
parent c9d6d4bfb2
commit 64f40b61d8

View File

@ -15,8 +15,8 @@ import SettingsStore from './SettingsStore';
@observer class Settings extends React.Component { @observer class Settings extends React.Component {
store = SettingsStore; store = SettingsStore;
constructor(props) { constructor() {
super(props); super();
this.store = new SettingsStore(); this.store = new SettingsStore();
} }
@ -99,15 +99,8 @@ import SettingsStore from './SettingsStore';
} }
} }
const InlineForm = ({ class InlineForm extends React.Component {
placeholder, props: {
buttonLabel,
name,
value,
onChange,
onSubmit,
disabled,
}: {
placeholder: string, placeholder: string,
buttonLabel: string, buttonLabel: string,
name: string, name: string,
@ -115,25 +108,50 @@ const InlineForm = ({
onChange: Function, onChange: Function,
onSubmit: Function, onSubmit: Function,
disabled?: boolean, disabled?: boolean,
}) => {
const handleSubmit = event => {
event.preventDefault();
onSubmit();
}; };
state = {
validationError: false,
};
handleSubmit = event => {
event.preventDefault();
if (this.props.value) {
this.props.onSubmit();
} else {
this.setState({
validationError: true,
});
setTimeout(
() =>
this.setState({
validationError: false,
}),
2500
);
}
};
render() {
const { placeholder, value, onChange, buttonLabel } = this.props;
const { validationError } = this.state;
return ( return (
<form onSubmit={handleSubmit}> <form onSubmit={this.handleSubmit}>
<Flex auto> <Flex auto>
<TextInput <TextInput
type="text" type="text"
placeholder={placeholder} placeholder={validationError ? 'Please add a label' : placeholder}
value={value || ''} value={value || ''}
onChange={onChange} onChange={onChange}
validationError={validationError}
/> />
<Button type="submit" value={buttonLabel} /> <Button type="submit" value={buttonLabel} />
</Flex> </Flex>
</form> </form>
); );
}; }
}
const TextInput = styled.input` const TextInput = styled.input`
display:flex; display:flex;
@ -146,7 +164,7 @@ const TextInput = styled.input`
background-color: rgba(255, 255, 255, .25); background-color: rgba(255, 255, 255, .25);
border-width:1px; border-width:1px;
border-style:solid; border-style:solid;
border-color:rgba(0, 0, 0, .25); border-color: ${props => (props.validationError ? 'red' : 'rgba(0, 0, 0, .25)')};
border-radius:2px 0 0 2px; border-radius:2px 0 0 2px;
`; `;