Skip to content

Commit 762f8e4

Browse files
Merge pull request #78 from Chat-Your-Way/CHAT-161-Recovery-Password-integration-Back-and-Front
Chat 161 recovery password integration back and front
2 parents 3ccb2e8 + a40a7f0 commit 762f8e4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/components/RecoveryPasswordPageComponent/RecoveryPasswordPageComponent.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { LoginButton } from '../LoginPageComponent/LoginPageComponent.styled';
55
import { useMediaQuery } from 'react-responsive';
66
import { useForm } from 'react-hook-form';
77
import { PATH } from '../../constans/routes';
8+
import { useParams } from 'react-router-dom';
9+
import { useResetPasswordMutation } from '../../redux/auth-operations';
810
import {
911
RecoveryPasswordWrapper,
1012
RecoveryPasswordForm,
@@ -17,6 +19,8 @@ import {
1719

1820
function RecoveryPasswordPageComponent() {
1921
const isTablet = useMediaQuery({ query: '(min-width: calc(845px - 0.02px)' });
22+
const { token } = useParams();
23+
const [resetPassword] = useResetPasswordMutation();
2024
const {
2125
formState: { errors, isValid },
2226
handleSubmit,
@@ -30,8 +34,10 @@ function RecoveryPasswordPageComponent() {
3034

3135
const onSubmit = (values) => {
3236
const { password } = values;
33-
// eslint-disable-next-line no-console
34-
console.log(password);
37+
resetPassword({
38+
newPassword: password,
39+
token,
40+
});
3541
};
3642

3743
return (

src/redux/auth-operations.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ const authenticationApi = createApi({
4444
headers: { Authorization: `Bearer ${ajwt}` },
4545
}),
4646
}),
47+
resetPassword: builder.mutation({
48+
query: ({ newPassword, token }) => ({
49+
url: `/change/password/restore?newPassword=${newPassword}&token=${token}`,
50+
method: 'PATCH',
51+
}),
52+
}),
4753
}),
4854
});
4955

@@ -53,6 +59,7 @@ export const {
5359
useLoginMutation,
5460
useActivateMutation,
5561
useLogoutMutation,
62+
useResetPasswordMutation,
5663
} = authenticationApi;
5764

5865
export default authenticationApi;

0 commit comments

Comments
 (0)