From 42a5d2de33564c060d2d6f3cefdd3cf21c26a996 Mon Sep 17 00:00:00 2001 From: l3wdfut4pwr Date: Mon, 27 Apr 2026 22:43:13 +0300 Subject: add password change --- src/components/settings/ChangePassword.tsx | 91 ++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/components/settings/ChangePassword.tsx (limited to 'src/components/settings/ChangePassword.tsx') diff --git a/src/components/settings/ChangePassword.tsx b/src/components/settings/ChangePassword.tsx new file mode 100644 index 0000000..d437b5e --- /dev/null +++ b/src/components/settings/ChangePassword.tsx @@ -0,0 +1,91 @@ +'use client'; + +import { useState } from 'react'; +import { InputField } from '@/components/ui/inputfield'; +import { Button } from '@/components/ui/button'; +import { Separator } from '@/components/ui/separator'; +import { changePassword } from '@/lib/api/ChangePassword'; + +export const ChangePasswordField = () => { + const [currentPassword, setCurrentPassword] = useState(''); + const [newPassword, setNewPassword] = useState(''); + const [confirmPassword, setConfirmPassword] = useState(''); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + + const handleSubmit = async () => { + setError(null); + + if (newPassword !== confirmPassword) { + setError('Пароли не совпадают'); + return; + } + + if (newPassword.length < 6) { + setError('Пароль должен быть минимум 6 символов'); + return; + } + + setLoading(true); + + const res = await changePassword( + currentPassword, + newPassword, + confirmPassword, + ); + + setLoading(false); + + if (res.error) { + setError(res.error.general); + return; + } + + setCurrentPassword(''); + setNewPassword(''); + setConfirmPassword(''); + }; + + return ( +
+

СМЕНА ПАРОЛЯ

+ +
+ setCurrentPassword(e.target.value)} + /> + + setNewPassword(e.target.value)} + /> + + setConfirmPassword(e.target.value)} + /> +
+ + {error &&

{error}

} + + + + +
+ ); +}; -- cgit v1.3-3-g829e