From 68f8be325e54f8c9ff9249dea5b058169c4dfcf0 Mon Sep 17 00:00:00 2001 From: srgooglo Date: Tue, 25 Oct 2022 14:42:46 +0000 Subject: [PATCH] implemented change password component for settings --- .../components/changePassword/index.jsx | 111 +++++++++++++++++- .../components/changePassword/index.less | 18 +++ 2 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 packages/app/constants/settings/security/components/changePassword/index.less diff --git a/packages/app/constants/settings/security/components/changePassword/index.jsx b/packages/app/constants/settings/security/components/changePassword/index.jsx index 8d0a98ab..65f2b4e7 100755 --- a/packages/app/constants/settings/security/components/changePassword/index.jsx +++ b/packages/app/constants/settings/security/components/changePassword/index.jsx @@ -1,16 +1,123 @@ import React from "react" import * as antd from "antd" +import { User } from "models" +import { Icons } from "components/Icons" + +import "./index.less" + const ChangePasswordComponent = (props) => { const [loading, setLoading] = React.useState(false) + const [currentPassword, setCurrentPassword] = React.useState("") + const [newPassword, setNewPassword] = React.useState("") + const [confirmPassword, setConfirmPassword] = React.useState("") + + const [validCurrentPassword, setValidCurrentPassword] = React.useState(false) + const [validNewPassword, setValidNewPassword] = React.useState(false) + const [validConfirmPassword, setValidConfirmPassword] = React.useState(false) + + const [error, setError] = React.useState(null) + + const passwordMatch = newPassword === confirmPassword + + const canSubmit = () => { + return validCurrentPassword && validNewPassword && validConfirmPassword && passwordMatch && !loading + } + + const submit = async () => { + if (!canSubmit()) return + + setError(null) + setLoading(true) + + const result = await User.changePassword({ currentPassword, newPassword }).catch((err) => { + console.error(err) + setError(err.response.data.message) + return null + }) + + setLoading(false) + + if (result) { + app.message.success("Password changed successfully") + props.close() + } + } + + const handleChangeCurrentPassword = (e) => { + const value = e.target.value + + setCurrentPassword(value) + setValidCurrentPassword(value.length > 0) + } + + const handleChangeNewPassword = (e) => { + const value = e.target.value + + setNewPassword(value) + setValidNewPassword(value.length > 0) + } + + const handleChangeConfirmPassword = (e) => { + const value = e.target.value + + setConfirmPassword(value) + setValidConfirmPassword(value.length > 0) + } + return
-

Change Password

+

Change Password

- +
+ +
+ + + +
+ +
+ +
+ +
+ +
+ + Change Password + +
+ +
+ {error} +
} diff --git a/packages/app/constants/settings/security/components/changePassword/index.less b/packages/app/constants/settings/security/components/changePassword/index.less new file mode 100644 index 00000000..7534824a --- /dev/null +++ b/packages/app/constants/settings/security/components/changePassword/index.less @@ -0,0 +1,18 @@ +.changePasswordPrompt { + display: flex; + + flex-direction: column; + + .title { + margin-bottom: 20px; + } + + .form { + display: flex; + flex-direction: column; + + .item { + margin-bottom: 10px; + } + } +} \ No newline at end of file