From dc3dcfba2b6c3ee4b61dd174f6023d0d80ef2b60 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Sat, 26 Mar 2022 15:26:36 +0530 Subject: [PATCH] refactor: DecoratedInput and add DecoratedPasswordInput (#953) --- .../AccountMenu/AdvancedOptions.tsx | 42 +++--- .../AccountMenu/ConfirmPassword.tsx | 29 ++-- .../components/AccountMenu/CreateAccount.tsx | 44 ++---- .../components/AccountMenu/SignIn.tsx | 40 ++--- .../javascripts/components/DecoratedInput.tsx | 140 +++++++++++------- .../components/DecoratedPasswordInput.tsx | 42 ++++++ .../javascripts/components/InputWithIcon.tsx | 91 ------------ .../Preferences/panes/Extensions.tsx | 2 +- .../panes/account/offlineSubscription.tsx | 2 +- .../panes/security-segments/Encryption.tsx | 47 +++--- .../panes/two-factor-auth/SaveSecretKey.tsx | 2 +- .../panes/two-factor-auth/ScanQRCode.tsx | 2 +- .../panes/two-factor-auth/Verification.tsx | 3 +- app/assets/stylesheets/_sn.scss | 4 + 14 files changed, 210 insertions(+), 280 deletions(-) create mode 100644 app/assets/javascripts/components/DecoratedPasswordInput.tsx delete mode 100644 app/assets/javascripts/components/InputWithIcon.tsx diff --git a/app/assets/javascripts/components/AccountMenu/AdvancedOptions.tsx b/app/assets/javascripts/components/AccountMenu/AdvancedOptions.tsx index a09335b36..ec67e0ed3 100644 --- a/app/assets/javascripts/components/AccountMenu/AdvancedOptions.tsx +++ b/app/assets/javascripts/components/AccountMenu/AdvancedOptions.tsx @@ -4,8 +4,8 @@ import { observer } from 'mobx-react-lite'; import { FunctionComponent } from 'preact'; import { useEffect, useState } from 'preact/hooks'; import { Checkbox } from '../Checkbox'; +import { DecoratedInput } from '../DecoratedInput'; import { Icon } from '../Icon'; -import { InputWithIcon } from '../InputWithIcon'; type Props = { application: WebApplication; @@ -63,16 +63,12 @@ export const AdvancedOptions: FunctionComponent = observer( setIsVault(!isVault); }; - const handleVaultNameChange = (e: Event) => { - if (e.target instanceof HTMLInputElement) { - setVaultName(e.target.value); - } + const handleVaultNameChange = (name: string) => { + setVaultName(name); }; - const handleVaultUserphraseChange = (e: Event) => { - if (e.target instanceof HTMLInputElement) { - setVaultUserphrase(e.target.value); - } + const handleVaultUserphraseChange = (userphrase: string) => { + setVaultUserphrase(userphrase); }; const handleServerOptionChange = (e: Event) => { @@ -81,11 +77,9 @@ export const AdvancedOptions: FunctionComponent = observer( } }; - const handleSyncServerChange = (e: Event) => { - if (e.target instanceof HTMLInputElement) { - setServer(e.target.value); - application.setCustomHost(e.target.value); - } + const handleSyncServerChange = (server: string) => { + setServer(server); + application.setCustomHost(server); }; const handleStrictSigninChange = () => { @@ -135,19 +129,19 @@ export const AdvancedOptions: FunctionComponent = observer( {appState.enableUnfinishedFeatures && isVault && ( <> - ]} + type="text" placeholder="Vault name" value={vaultName} onChange={handleVaultNameChange} disabled={disabled} /> - ]} + type="text" placeholder="Vault userphrase" value={vaultUserphrase} onChange={handleVaultUserphraseChange} @@ -183,9 +177,9 @@ export const AdvancedOptions: FunctionComponent = observer( onChange={handleServerOptionChange} disabled={disabled} /> - ]} placeholder="https://api.standardnotes.com" value={server} onChange={handleSyncServerChange} diff --git a/app/assets/javascripts/components/AccountMenu/ConfirmPassword.tsx b/app/assets/javascripts/components/AccountMenu/ConfirmPassword.tsx index 0a5575cb6..2aad0c0b1 100644 --- a/app/assets/javascripts/components/AccountMenu/ConfirmPassword.tsx +++ b/app/assets/javascripts/components/AccountMenu/ConfirmPassword.tsx @@ -7,9 +7,9 @@ import { useEffect, useRef, useState } from 'preact/hooks'; import { AccountMenuPane } from '.'; import { Button } from '../Button'; import { Checkbox } from '../Checkbox'; +import { DecoratedPasswordInput } from '../DecoratedPasswordInput'; +import { Icon } from '../Icon'; import { IconButton } from '../IconButton'; -import { InputWithIcon } from '../InputWithIcon'; -import { AdvancedOptions } from './AdvancedOptions'; type Props = { appState: AppState; @@ -23,7 +23,6 @@ export const ConfirmPassword: FunctionComponent = observer( ({ application, appState, setMenuPane, email, password }) => { const { notesAndTagsCount } = appState.accountMenu; const [confirmPassword, setConfirmPassword] = useState(''); - const [showPassword, setShowPassword] = useState(false); const [isRegistering, setIsRegistering] = useState(false); const [isEphemeral, setIsEphemeral] = useState(false); const [shouldMergeLocal, setShouldMergeLocal] = useState(true); @@ -35,10 +34,8 @@ export const ConfirmPassword: FunctionComponent = observer( passwordInputRef.current?.focus(); }, []); - const handlePasswordChange = (e: Event) => { - if (e.target instanceof HTMLInputElement) { - setConfirmPassword(e.target.value); - } + const handlePasswordChange = (text: string) => { + setConfirmPassword(text); }; const handleEphemeralChange = () => { @@ -117,23 +114,15 @@ export const ConfirmPassword: FunctionComponent = observer( your data.
- ]} onChange={handlePasswordChange} onKeyDown={handleKeyDown} - toggle={{ - toggleOnIcon: 'eye-off', - toggleOffIcon: 'eye', - title: 'Show password', - toggled: showPassword, - onClick: setShowPassword, - }} + placeholder="Confirm password" ref={passwordInputRef} - disabled={isRegistering} + value={confirmPassword} /> {error ?
{error}
: null}