fix advanced section collapsing after changing claim name

This commit is contained in:
Sean Yesmunt 2020-02-11 18:00:29 -05:00
parent 3ad923b4f8
commit f351c9eedf

View file

@ -74,6 +74,12 @@ function ModalRepost(props: Props) {
repostNameError = __('You already have a claim with this name.'); repostNameError = __('You already have a claim with this name.');
} }
React.useEffect(() => {
if ((repostNameError || repostNameError) && !showAdvanced) {
setShowAdvanced(true);
}
}, [repostBidError, repostNameError, showAdvanced, setShowAdvanced]);
const channelStrings = channels && channels.map(channel => channel.permanent_url).join(','); const channelStrings = channels && channels.map(channel => channel.permanent_url).join(',');
React.useEffect(() => { React.useEffect(() => {
if (!repostChannel && channelStrings) { if (!repostChannel && channelStrings) {
@ -111,7 +117,6 @@ function ModalRepost(props: Props) {
doHideModal(); doHideModal();
} }
const showAdvancedSection = showAdvanced || repostNameError || repostBidError;
return ( return (
<Modal isOpen type="card" onAborted={handleCloseModal} onConfirmed={handleCloseModal}> <Modal isOpen type="card" onAborted={handleCloseModal} onConfirmed={handleCloseModal}>
<Card <Card
@ -137,13 +142,15 @@ function ModalRepost(props: Props) {
channel={repostChannel} channel={repostChannel}
onChannelChange={newChannel => setRepostChannel(newChannel)} onChannelChange={newChannel => setRepostChannel(newChannel)}
/> />
{!showAdvanced && (
<div className="section__actions"> <div className="section__actions">
{!showAdvancedSection && (
<Button button="link" label={__('Advanced')} onClick={() => setShowAdvanced(true)} /> <Button button="link" label={__('Advanced')} onClick={() => setShowAdvanced(true)} />
)}
</div> </div>
{showAdvancedSection && ( )}
{showAdvanced && (
<React.Fragment> <React.Fragment>
<fieldset-section>
<fieldset-group class="fieldset-group--smushed fieldset-group--disabled-prefix"> <fieldset-group class="fieldset-group--smushed fieldset-group--disabled-prefix">
<fieldset-section> <fieldset-section>
<label>{__('Name')}</label> <label>{__('Name')}</label>
@ -159,6 +166,8 @@ function ModalRepost(props: Props) {
onChange={event => setRepostName(event.target.value)} onChange={event => setRepostName(event.target.value)}
/> />
</fieldset-group> </fieldset-group>
</fieldset-section>
<div className="form-field__help"> <div className="form-field__help">
<I18nMessage <I18nMessage
tokens={{ tokens={{