From dafe4e20187391d971d79e774c851411575824a9 Mon Sep 17 00:00:00 2001 From: Imre Kiss Date: Thu, 27 Jan 2022 21:35:00 +0100 Subject: [PATCH] Hook up the password change action into the component #107 --- .../pages/Account/Security/index.tsx | 29 +++++-------------- src/localization/en/translation.json | 1 - 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/components/pages/Account/Security/index.tsx b/src/components/pages/Account/Security/index.tsx index 169c49e..7a5f402 100644 --- a/src/components/pages/Account/Security/index.tsx +++ b/src/components/pages/Account/Security/index.tsx @@ -6,25 +6,16 @@ import FormText from '../../../core/FormText'; import ButtonContainer from '../../../core/ButtonContainer'; import Button from '../../../core/Button'; import Title from '../../../core/Title'; +import { useDispatch } from '../../../../hooks/redux'; +import { changePassword } from '../../../../store/auth'; import { TEXT_MIN, TEXT_MAX } from '../../../../constants/validation'; -export interface SecurityPasswordChangeForm { - oldPassword: string; +export interface PasswordChangeForm { newPassword: string; confirmPassword: string; } -const schema = (t: (key: string, options?: object) => string): Schema => [ - { - field: 'oldPassword', - value: '', - required: true, - requiredError: t('error:required'), - validators: [ - { rule: TEXT_MIN(6), error: t('error:textMin', { min: 6 }) }, - { rule: TEXT_MAX(255), error: t('error:textMax', { max: 255 }) }, - ], - }, +const schema = (t: (key: string, options?: object) => string): Schema => [ { field: 'newPassword', value: '', @@ -46,23 +37,17 @@ const schema = (t: (key: string, options?: object) => string): Schema { const { t } = useTranslation(['common', 'translation', 'error']); + const dispatch = useDispatch(); - const { fields, handleSubmit, handleChange } = useForm({ + const { fields, handleSubmit, handleChange } = useForm({ schema: schema(t), - onSubmit: data => console.log(data), + onSubmit: data => dispatch(changePassword(data)), }); return (
{t('translation:account.changePassword')} -