Skip to content

Commit 8bccf5a

Browse files
committed
Fix bugs 🐛
1 parent 9590231 commit 8bccf5a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

components/setting.jsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useCurrentUser } from '../lib/hooks';
44

55
const ProfileSection = () => {
66
const [user, { mutate }] = useCurrentUser();
7-
const [isUpdating, setIsUpdating] = useState(false);
7+
const [loading, isLoading] = useState(false);
88
const nameRef = useRef();
99
const bioRef = useRef();
1010
const profilePictureRef = useRef();
@@ -17,19 +17,15 @@ const ProfileSection = () => {
1717

1818
const handleSubmit = async (event) => {
1919
event.preventDefault();
20-
21-
console.log(nameRef.current.value);
22-
20+
isLoading(true);
2321
const formData = new FormData();
24-
2522
if (profilePictureRef.current.files[0]) { formData.append('profilePicture', profilePictureRef.current.files[0]); }
2623
formData.append('name', nameRef.current.value);
2724
formData.append('bio', bioRef.current.value);
2825

29-
3026
const res = await fetch('/api/user', {
3127
method: 'PATCH',
32-
body:formData,
28+
body: formData,
3329
});
3430
if (res.status === 200) {
3531
const userData = await res.json();
@@ -43,9 +39,11 @@ const ProfileSection = () => {
4339
} else {
4440
setMsg({ message: await res.text(), isError: true });
4541
}
42+
isLoading(false);
4643
};
4744

4845
const handleSubmitPasswordChange = async (e) => {
46+
isLoading(true);
4947
e.preventDefault();
5048
const body = {
5149
oldPassword: e.currentTarget.oldPassword.value,
@@ -65,13 +63,17 @@ const ProfileSection = () => {
6563
} else {
6664
setMsg({ message: await res.text(), isError: true });
6765
}
66+
isLoading(false);
6867
};
6968

7069
return (
7170
<>
7271
<Head>
7372
<title>Settings</title>
7473
</Head>
74+
{loading ? <div className="progress" style={{ margin: 0 }}>
75+
<div className="indeterminate"></div>
76+
</div> : null}
7577
<section className="">
7678
<h2>Edit Profile</h2>
7779
{msg.message ? <p style={{ color: msg.isError ? 'red' : '#0070f3', textAlign: 'center' }}>{msg.message}</p> : null}

pages/api/user/password/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ handler.put(async (req, res) => {
99
if (!req.user) { res.json(401).send('you need to be authenticated'); return; }
1010
const { oldPassword, newPassword } = req.body;
1111
if (!(await bcrypt.compare(oldPassword, req.user.password))) {
12-
res.status(401).send('The password you has entered is incorrect.');
12+
res.status(401).send('The old password you have entered is incorrect.');
1313
}
1414
const password = await bcrypt.hash(newPassword, 10);
1515
await req.db

0 commit comments

Comments
 (0)