import { useSaveSetting } from '@/hooks/user-setting-hooks'; import { rsaPsw } from '@/utils'; import { Button, Divider, Form, Input, Space } from 'antd'; import SettingTitle from '../components/setting-title'; import { useValidateSubmittable } from '../hooks'; import { useTranslate } from '@/hooks/common-hooks'; import styles from './index.less'; type FieldType = { password?: string; new_password?: string; confirm_password?: string; }; const tailLayout = { wrapperCol: { offset: 20, span: 4 }, }; const UserSettingPassword = () => { const { form, submittable } = useValidateSubmittable(); const { saveSetting, loading } = useSaveSetting(); const { t } = useTranslate('setting'); const onFinish = (values: any) => { const password = rsaPsw(values.password) as string; const new_password = rsaPsw(values.new_password) as string; saveSetting({ password, new_password }); }; const onFinishFailed = (errorInfo: any) => { console.log('Failed:', errorInfo); }; return (
label={t('currentPassword')} name="password" rules={[ { required: true, message: t('currentPasswordMessage'), whitespace: true, }, ]} > noStyle name="new_password" rules={[ { required: true, message: t('newPasswordMessage'), whitespace: true, }, { type: 'string', min: 8, message: t('newPasswordDescription') }, ]} > label={t('confirmPassword')} name="confirm_password" dependencies={['new_password']} rules={[ { required: true, message: t('confirmPasswordMessage'), whitespace: true, }, { type: 'string', min: 8, message: t('newPasswordDescription') }, ({ getFieldValue }) => ({ validator(_, value) { if (!value || getFieldValue('new_password') === value) { return Promise.resolve(); } return Promise.reject( new Error(t('confirmPasswordNonMatchMessage')), ); }, }), ]} > prevValues.additional !== curValues.additional } >
); }; export default UserSettingPassword;