// @flow import React, { useState } from 'react'; import { FormField, Form } from 'component/common/form'; import Button from 'component/button'; import ErrorText from 'component/common/error-text'; import Card from 'component/common/card'; import * as PAGES from 'constants/pages'; type Props = { user: ?User, doToast: ({ message: string }) => void, doUserPasswordSet: (string, ?string) => void, doClearPasswordEntry: () => void, passwordSetSuccess: boolean, passwordSetError: ?string, }; export default function SettingAccountPassword(props: Props) { const { user, doToast, doUserPasswordSet, passwordSetSuccess, passwordSetError, doClearPasswordEntry } = props; const [oldPassword, setOldPassword] = useState(''); const [newPassword, setNewPassword] = useState(''); const [isAddingPassword, setIsAddingPassword] = useState(false); const hasPassword = user && user.password_set; function handleSubmit() { doUserPasswordSet(newPassword, oldPassword); } React.useEffect(() => { if (passwordSetSuccess) { setIsAddingPassword(false); doToast({ message: __('Password updated successfully.'), }); doClearPasswordEntry(); setOldPassword(''); setNewPassword(''); } }, [passwordSetSuccess, setOldPassword, setNewPassword, doClearPasswordEntry, doToast]); return (
{hasPassword && ( setOldPassword(e.target.value)} /> )} setNewPassword(e.target.value)} />
{passwordSetError && (
{passwordSetError}
)} ) : (