-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
client/src/pages/Settings/pages/Account/dialogs/PasswordChange/PasswordChange.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { DialogProvider } from "@/common/components/Dialog"; | ||
import IconInput from "@/common/components/IconInput"; | ||
import { mdiAccountCircleOutline } from "@mdi/js"; | ||
import Button from "@/common/components/Button"; | ||
import "./styles.sass"; | ||
import { patchRequest } from "@/common/utils/RequestUtil.js"; | ||
import { useState } from "react"; | ||
|
||
export const PasswordChange = ({ open, onClose }) => { | ||
|
||
const [passwordError, setPasswordError] = useState(false); | ||
|
||
const [password, setPassword] = useState(""); | ||
const [confirmPassword, setConfirmPassword] = useState(""); | ||
|
||
const changePassword = () => { | ||
if (password.length < 5) return; | ||
if (password !== confirmPassword) return; | ||
|
||
patchRequest("accounts/password", { password }).then(() => onClose()).catch(err => { | ||
setPasswordError(true); | ||
|
||
setTimeout(() => { | ||
setPasswordError(false); | ||
}, 1500); | ||
}); | ||
}; | ||
|
||
return ( | ||
<DialogProvider open={open} onClose={onClose}> | ||
<div className="password-change"> | ||
<h2>Change password</h2> | ||
<p> | ||
Enter your new password below. Make sure it is at least 5 characters long and | ||
contains at least one number and one special character. | ||
</p> | ||
<div className="form-group"> | ||
<IconInput icon={mdiAccountCircleOutline} type="password" placeholder="New password" | ||
autoComplete="new-password" customClass={passwordError ? "error" : ""} | ||
value={password} setValue={setPassword} /> | ||
</div> | ||
<div className="form-group"> | ||
<IconInput icon={mdiAccountCircleOutline} type="password" placeholder="Confirm new password" | ||
autoComplete="new-password" customClass={passwordError ? "error" : ""} | ||
value={confirmPassword} setValue={setConfirmPassword} /> | ||
</div> | ||
<Button text="Change password" onClick={changePassword} /> | ||
</div> | ||
</DialogProvider> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
client/src/pages/Settings/pages/Account/dialogs/PasswordChange/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {PasswordChange as default} from "./PasswordChange.jsx"; |
17 changes: 17 additions & 0 deletions
17
client/src/pages/Settings/pages/Account/dialogs/PasswordChange/styles.sass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@import "@/common/styles/colors" | ||
|
||
.password-change | ||
display: flex | ||
flex-direction: column | ||
gap: 1rem | ||
width: 20rem | ||
|
||
h2, p | ||
margin: 0 | ||
|
||
p | ||
font-weight: 600 | ||
font-size: 0.9rem | ||
|
||
.error | ||
border: 1px solid $error |