lbry-desktop/src/ui/component/userFirstChannel/view.jsx

82 lines
2.6 KiB
React
Raw Normal View History

2019-08-27 16:43:42 +02:00
// @flow
import React, { useState } from 'react';
import { isNameValid } from 'lbry-redux';
import Button from 'component/button';
import { Form, FormField } from 'component/common/form';
2019-09-26 18:07:11 +02:00
export const DEFAULT_BID_FOR_FIRST_CHANNEL = 0.9;
2019-08-27 16:43:42 +02:00
type Props = {
createChannel: (string, number) => void,
creatingChannel: boolean,
2019-09-26 18:07:11 +02:00
createChannelError: string,
claimingReward: boolean,
user: User,
2019-08-27 16:43:42 +02:00
};
function UserFirstChannel(props: Props) {
2019-09-26 18:07:11 +02:00
const { createChannel, creatingChannel, claimingReward, user, createChannelError } = props;
const { primary_email: primaryEmail } = user;
const initialChannel = primaryEmail.split('@')[0];
const [channel, setChannel] = useState(initialChannel);
const [nameError, setNameError] = useState(undefined);
2019-08-27 16:43:42 +02:00
function handleCreateChannel() {
2019-09-26 18:07:11 +02:00
createChannel(`@${channel}`, DEFAULT_BID_FOR_FIRST_CHANNEL);
2019-08-27 16:43:42 +02:00
}
function handleChannelChange(e) {
const { value } = e.target;
setChannel(value);
if (!isNameValid(value, false)) {
setNameError(__('LBRY names cannot contain spaces or reserved symbols ($#@;/"<>%{}|^~[]`)'));
2019-08-27 16:43:42 +02:00
} else {
setNameError();
}
}
return (
<Form onSubmit={handleCreateChannel}>
2019-09-26 18:07:11 +02:00
<h1 className="section__title--large">{__('Create A Channel')}</h1>
<div className="section__subtitle">
<p>{__('A channel is your identity on the LBRY network.')}</p>
<p>{__('You can have more than one or change this later.')}</p>
2019-08-27 16:43:42 +02:00
</div>
2019-09-26 18:07:11 +02:00
<section className="section__body">
<fieldset-group class="fieldset-group--smushed fieldset-group--disabled-prefix">
<fieldset-section>
<label htmlFor="auth_first_channel">
{createChannelError || nameError ? (
<span className="error-text">{createChannelError || nameError}</span>
) : (
__('Your Channel')
)}
</label>
<div className="form-field__prefix">@</div>
</fieldset-section>
<FormField
autoFocus
placeholder={__('channel')}
type="text"
name="auth_first_channel"
className="form-field--short"
value={channel}
onChange={handleChannelChange}
/>
</fieldset-group>
<div className="section__actions">
<Button
button="primary"
type="submit"
disabled={nameError || !channel || creatingChannel || claimingReward}
label={creatingChannel || claimingReward ? __('Creating') : __('Create')}
/>
</div>
</section>
2019-08-27 16:43:42 +02:00
</Form>
);
}
export default UserFirstChannel;