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

119 lines
3.7 KiB
React
Raw Permalink 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-10-03 23:40:54 +02:00
import { INVALID_NAME_ERROR } from 'constants/claim';
import Card from 'component/common/card';
2020-09-03 22:05:38 +02:00
import I18nMessage from 'component/i18nMessage';
import analytics from 'analytics';
export const DEFAULT_BID_FOR_FIRST_CHANNEL = 0.01;
2019-08-27 16:43:42 +02:00
type Props = {
createChannel: (string, number) => Promise<ChannelClaim>,
2019-08-27 16:43:42 +02:00
creatingChannel: boolean,
2019-09-26 18:07:11 +02:00
createChannelError: string,
claimingReward: boolean,
user: User,
doToggleInterestedInYoutubeSync: () => void,
2019-08-27 16:43:42 +02:00
};
function UserFirstChannel(props: Props) {
const {
createChannel,
creatingChannel,
claimingReward,
user,
createChannelError,
doToggleInterestedInYoutubeSync,
} = props;
2019-09-26 18:07:11 +02:00
const { primary_email: primaryEmail } = user;
const initialChannel = primaryEmail ? primaryEmail.split('@')[0] : '';
2019-09-26 18:07:11 +02:00
const [channel, setChannel] = useState(initialChannel);
const [nameError, setNameError] = useState(undefined);
2019-08-27 16:43:42 +02:00
function handleCreateChannel() {
createChannel(`@${channel}`, DEFAULT_BID_FOR_FIRST_CHANNEL).then(channelClaim => {
if (channelClaim) {
analytics.apiLogPublish(channelClaim);
}
});
2019-08-27 16:43:42 +02:00
}
function handleChannelChange(e) {
const { value } = e.target;
setChannel(value);
if (!isNameValid(value, false)) {
2019-10-03 23:40:54 +02:00
setNameError(INVALID_NAME_ERROR);
2019-08-27 16:43:42 +02:00
} else {
setNameError();
}
}
return (
<div className="main__channel-creation">
<Card
2020-08-25 00:23:38 +02:00
title={__('Create a Channel')}
subtitle={
<React.Fragment>
2020-08-25 00:23:38 +02:00
<p>{__('Your channel will be used for publishing and commenting.')}</p>
<p>{__('You can have more than one or remove it later.')}</p>
</React.Fragment>
}
actions={
<Form onSubmit={handleCreateChannel}>
<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>
2019-09-26 18:07:11 +02:00
<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>
2020-09-03 22:05:38 +02:00
<div className="help--card-actions">
<I18nMessage
tokens={{
sync_channel: (
<Button
button="link"
label={__('Sync it and skip this step')}
onClick={() => doToggleInterestedInYoutubeSync()}
2020-09-03 22:05:38 +02:00
/>
),
}}
>
Have a YouTube channel? %sync_channel%.
</I18nMessage>
</div>
</Form>
}
/>
</div>
2019-08-27 16:43:42 +02:00
);
}
export default UserFirstChannel;