80d4d8c57c
## Issue 534 prevent new channel creation over x channels ## Notes Also handled from the API call (`doCreateChannel`) in case there are other UI components that create channels.
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
// @flow
|
|
import * as PAGES from 'constants/pages';
|
|
import React from 'react';
|
|
import ChannelEdit from 'component/channelEdit';
|
|
import Page from 'component/page';
|
|
import { useHistory } from 'react-router';
|
|
import YrblWalletEmpty from 'component/yrblWalletEmpty';
|
|
|
|
type Props = {
|
|
balance: number,
|
|
claimConfirmEmailReward: () => void,
|
|
isAuthenticated: boolean,
|
|
channelCountOverLimit: boolean,
|
|
};
|
|
|
|
function ChannelNew(props: Props) {
|
|
const { balance, claimConfirmEmailReward, isAuthenticated, channelCountOverLimit } = props;
|
|
const { push, location } = useHistory();
|
|
const urlSearchParams = new URLSearchParams(location.search);
|
|
const redirectUrl = urlSearchParams.get('redirect');
|
|
const emptyBalance = balance === 0;
|
|
|
|
React.useEffect(() => {
|
|
if (isAuthenticated && emptyBalance) {
|
|
claimConfirmEmailReward();
|
|
}
|
|
}, [isAuthenticated, claimConfirmEmailReward, emptyBalance]);
|
|
|
|
return (
|
|
<Page noSideNavigation noFooter backout={{ title: __('Create a channel'), backLabel: __('Cancel') }}>
|
|
{emptyBalance && <YrblWalletEmpty />}
|
|
|
|
{channelCountOverLimit && (
|
|
<div className="empty empty--centered">{__('Sorry, you have exceeded the channel creation limit.')}</div>
|
|
)}
|
|
|
|
<ChannelEdit
|
|
disabled={emptyBalance || channelCountOverLimit}
|
|
onDone={() => {
|
|
push(redirectUrl || `/$/${PAGES.CHANNELS}`);
|
|
}}
|
|
/>
|
|
</Page>
|
|
);
|
|
}
|
|
|
|
export default ChannelNew;
|