diff --git a/web/modals/threads/thread-settings-modal.react.js b/web/modals/threads/thread-settings-modal.react.js --- a/web/modals/threads/thread-settings-modal.react.js +++ b/web/modals/threads/thread-settings-modal.react.js @@ -102,6 +102,7 @@ +onChangeThreadType: (event: SyntheticEvent) => void, +onChangeAccountPassword: (event: SyntheticEvent) => void, +hasPermissionForTab: (thread: ThreadInfo, tab: TabType) => boolean, + +deleteThreadAction: () => Promise, }; class ThreadSettingsModal extends React.PureComponent { nameInput: ?HTMLInputElement; @@ -313,30 +314,9 @@ event.preventDefault(); this.props.dispatchActionPromise( deleteThreadActionTypes, - this.deleteThreadAction(), + this.props.deleteThreadAction(), ); }; - - async deleteThreadAction() { - try { - const response = await this.props.deleteThread( - this.props.threadInfo.id, - this.props.accountPassword, - ); - this.props.onClose(); - return response; - } catch (e) { - const errorMessage = - e.message === 'invalid_credentials' - ? 'wrong password' - : 'unknown error'; - this.props.setErrorMessage(errorMessage); - this.props.setAccountPassword(''); - invariant(this.accountPasswordInput, 'accountPasswordInput ref unset'); - this.accountPasswordInput.focus(); - throw e; - } - } } const deleteThreadLoadingStatusSelector = createLoadingStatusSelector( @@ -469,6 +449,25 @@ [], ); + const deleteThreadAction = React.useCallback(async () => { + invariant(threadInfo, 'threadInfo should exist in deleteThreadAction'); + try { + const response = await callDeleteThread(threadInfo.id, accountPassword); + modalContext.clearModal(); + return response; + } catch (e) { + setErrorMessage( + e.message === 'invalid_credentials' + ? 'wrong password' + : 'unknown error', + ); + setAccountPassword(''); + // TODO: accountPasswordInput.focus() + // (once ref is moved up to functional component) + throw e; + } + }, [accountPassword, callDeleteThread, modalContext, threadInfo]); + if (!threadInfo) { return ( @@ -507,6 +506,7 @@ onChangeThreadType={onChangeThreadType} onChangeAccountPassword={onChangeAccountPassword} hasPermissionForTab={hasPermissionForTab} + deleteThreadAction={deleteThreadAction} /> ); },