lbry-desktop/ui/modal/modalSetReferrer/view.jsx

102 lines
2.9 KiB
React
Raw Permalink Normal View History

2020-01-14 21:44:07 +01:00
// @flow
import * as React from 'react';
import { FormField, Form } from 'component/common/form';
import { Modal } from 'modal/modal';
import Button from 'component/button';
import HelpLink from 'component/common/help-link';
2020-01-15 16:25:24 +01:00
import Card from 'component/common/card';
2020-01-14 21:44:07 +01:00
type Props = {
closeModal: () => void,
error: ?string,
rewardIsPending: boolean,
setReferrer: (string, boolean) => void,
referrerSetPending: boolean,
referrerSetError?: string,
resetReferrerError: () => void,
2020-01-14 21:44:07 +01:00
};
type State = {
referrer: string,
};
class ModalSetReferrer extends React.PureComponent<Props, State> {
constructor() {
super();
this.state = {
referrer: '',
};
(this: any).handleSubmit = this.handleSubmit.bind(this);
(this: any).handleClose = this.handleClose.bind(this);
(this: any).handleTextChange = this.handleTextChange.bind(this);
2020-01-14 21:44:07 +01:00
}
handleSubmit() {
const { referrer } = this.state;
const { setReferrer } = this.props;
setReferrer(referrer, true);
}
handleClose() {
const { referrerSetError, resetReferrerError, closeModal } = this.props;
if (referrerSetError) {
resetReferrerError();
}
closeModal();
}
handleTextChange(e: SyntheticInputEvent<*>) {
const { referrerSetError, resetReferrerError } = this.props;
this.setState({ referrer: e.target.value });
if (referrerSetError) {
resetReferrerError();
}
}
2020-01-14 21:44:07 +01:00
render() {
const { closeModal, rewardIsPending, referrerSetError, referrerSetPending } = this.props;
2020-01-14 21:44:07 +01:00
const { referrer } = this.state;
return (
2020-08-26 22:28:33 +02:00
<Modal isOpen contentLabel={__('Enter inviter')} type="card" onAborted={closeModal}>
2020-01-15 16:25:24 +01:00
<Card
2020-08-26 22:28:33 +02:00
title={__('Enter inviter')}
2020-01-15 16:25:24 +01:00
subtitle={
<React.Fragment>
{__('Did someone invite you to use lbry.tv? Tell us who and you both get a reward!')}
<HelpLink href="https://lbry.com/faq/referrals" />
</React.Fragment>
}
actions={
<React.Fragment>
<Form onSubmit={this.handleSubmit}>
<FormField
autoFocus
type="text"
name="referrer-code"
inputButton={
<Button button="primary" type="submit" disabled={!referrer || rewardIsPending} label={__('Set')} />
}
label={__('Code or channel')}
placeholder="0123abc"
value={referrer}
onChange={this.handleTextChange}
error={!referrerSetPending && referrerSetError}
2020-01-15 16:25:24 +01:00
/>
</Form>
<div className="card__actions">
<Button button="primary" label={__('Done')} onClick={this.handleClose} />
2020-01-15 16:25:24 +01:00
</div>
</React.Fragment>
}
/>
2020-01-14 21:44:07 +01:00
</Modal>
);
}
}
export default ModalSetReferrer;