// @flow import * as MODALS from 'constants/modal_types'; import * as ICONS from 'constants/icons'; import React from 'react'; import { FormField } from 'component/common/form'; import Button from 'component/button'; import TagsSearch from 'component/tagsSearch'; import { FF_MAX_CHARS_IN_DESCRIPTION } from 'constants/form-field'; import ErrorText from 'component/common/error-text'; import ChannelThumbnail from 'component/channelThumbnail'; import { isNameValid, parseURI } from 'lbry-redux'; import ClaimAbandonButton from 'component/claimAbandonButton'; import { MINIMUM_PUBLISH_BID, INVALID_NAME_ERROR, ESTIMATED_FEE } from 'constants/claim'; import { Tabs, TabList, Tab, TabPanels, TabPanel } from 'component/common/tabs'; import Card from 'component/common/card'; type Props = { claim: ChannelClaim, title: string, amount: string, cover: string, thumbnail: string, location: { search: string }, description: string, website: string, email: string, balance: number, tags: Array, locations: Array, languages: Array, updateChannel: any => Promise, updatingChannel: boolean, updateError: string, createChannel: any => Promise, createError: string, creatingChannel: boolean, onDone: () => void, openModal: ( id: string, { onUpdate: string => void, assetName: string, helpText: string, currentValue: string, title: string } ) => void, uri: string, }; function ChannelForm(props: Props) { const { uri, claim, title, description, website, email, thumbnail, cover, tags, locations, languages, onDone, updateChannel, updateError, updatingChannel, createChannel, creatingChannel, createError, openModal, } = props; const [params, setParams]: [any, (any) => void] = React.useState(getChannelParams()); const [nameError, setNameError] = React.useState(undefined); const [bidError, setBidError] = React.useState(''); const { claim_id: claimId } = claim || {}; const { channelName } = parseURI(uri); const name = params.name; const isNewChannel = !uri; function getChannelParams() { // fill this in with sdk data const channelParams: { website: string, email: string, cover: string, thumbnail: string, description: string, title: string, amount: number, languages: ?Array, locations: ?Array, tags: ?Array<{ name: string }>, claim_id?: string, } = { website, email, cover, thumbnail, description, title, amount: 0.001, languages: languages || [], locations: locations || [], tags: tags ? tags.map(tag => { return { name: tag }; }) : [], }; if (claimId) { channelParams['claim_id'] = claimId; } return channelParams; } function handleBidChange(bid: number) { const { balance, amount } = props; const totalAvailableBidAmount = parseFloat(amount) || 0.0 + parseFloat(balance) || 0.0; setParams({ ...params, amount: bid }); if (bid <= 0.0 || isNaN(bid)) { setBidError(__('Deposit cannot be 0')); } else if (totalAvailableBidAmount - bid < ESTIMATED_FEE) { setBidError(__('Please decrease your deposit to account for transaction fees')); } else if (totalAvailableBidAmount < bid) { setBidError(__('Deposit cannot be higher than your balance')); } else if (bid < MINIMUM_PUBLISH_BID) { setBidError(__('Your deposit must be higher')); } else { setBidError(''); } } function handleThumbnailChange(thumbnailUrl: string) { setParams({ ...params, thumbnail: thumbnailUrl }); } function handleCoverChange(coverUrl: string) { setParams({ ...params, cover: coverUrl }); } function handleSubmit() { if (uri) { updateChannel(params).then(success => { if (success) { onDone(); } }); } else { createChannel(params).then(success => { if (success) { onDone(); } }); } } React.useEffect(() => { let nameError; if (!name && name !== undefined) { nameError = __('A name is required for your url'); } else if (!isNameValid(name, false)) { nameError = INVALID_NAME_ERROR; } setNameError(nameError); }, [name]); // TODO clear and bail after submit return ( <>
{params.cover && }

{params.title || (channelName && '@' + channelName) || (params.name && '@' + params.name)}

{__('General')} {__('LBC Details')} {__('Tags')} {__('Other')}
@
setParams({ ...params, name: e.target.value })} />
{!isNewChannel && {__('This field cannot be changed.')}} setParams({ ...params, title: e.target.value })} /> setParams({ ...params, description: text })} textAreaMaxLength={FF_MAX_CHARS_IN_DESCRIPTION} /> } />
handleBidChange(parseFloat(event.target.value))} placeholder={0.1} helper={__('Increasing your deposit can help your channel be discovered more easily.')} /> } /> { const newTags = params.tags.slice().filter(tag => tag.name !== clickedTag.name); setParams({ ...params, tags: newTags }); }} onSelect={newTags => { newTags.forEach(newTag => { if (!params.tags.map(savedTag => savedTag.name).includes(newTag.name)) { setParams({ ...params, tags: [...params.tags, newTag] }); } else { // If it already exists and the user types it in, remove it setParams({ ...params, tags: params.tags.filter(tag => tag.name !== newTag.name) }); } }); }} /> } /> setParams({ ...params, website: e.target.value })} /> setParams({ ...params, email: e.target.value })} /> } />
{updateError || createError ? ( {updateError || createError} ) : (

{__( 'After submitting, you will not see the changes immediately. Please check back in a few minutes.' )}

)} {!isNewChannel && (
)} } />
); } export default ChannelForm;