Skip to content
Snippets Groups Projects
Commit 6addde3f authored by Bernard Roland (Student Com20)'s avatar Bernard Roland (Student Com20)
Browse files

Fixed some bugs concerning the user settings

parent 1504c57f
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,7 @@ interface Props {
user: User
}
const validTypes = ['image/jpg', 'image/png', 'image/gif', 'image/svg']
const validTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/svg']
function validateEmail(email?: string): string | null {
if (email && email.length > 0) {
......
......@@ -6,11 +6,6 @@
overflow: hidden;
img {
width: 100%;
height: auto;
}
.standard-image {
width: 100%;
height: 100%;
background: s.$secondary;
......
import { useCallback, useState } from 'react';
import { getUserImageUri, User } from 'adapters/user';
import './avatar.scss';
......@@ -10,27 +8,11 @@ interface Props {
}
export default function Avatar({ user }: Props) {
const [error, setError] = useState(false);
const avatarSrc = user && getUserImageUri(user.id);
const onError = useCallback(() => {
setError(true);
}, [setError]);
return (
<div className="avatar">
{
!error && (
<img src={avatarSrc} alt={user?.username} onError={onError} />
)
}
{
error && (
<div className="standard-image">
{user?.username && user.username.charAt(0)}
</div>
)
}
<img src={avatarSrc} alt={user?.username.charAt(0) ?? "?"} />
</div>
)
}
......
......@@ -2,6 +2,7 @@
import { useHistory } from 'react-router';
import { useCallback, useEffect, useState } from 'react';
import { reload } from 'index';
import { getCurrentUser, updateUser, updateUserImage, User } from 'adapters/user';
import Callout from 'components/ui/Callout';
......@@ -16,21 +17,21 @@ export default function Settings() {
const history = useHistory();
useEffect(() => {
getCurrentUser().then((user) => setUser(user))
getCurrentUser().then(setUser)
}, []);
const handleSubmit = useCallback(async (name?: string, email?: string, avatar?: File) => {
try {
if (user && updateUser({ realname: name, email })) {
if (avatar) {
updateUserImage(avatar);
}
history.push('/tasks');
}
await Promise.all([
updateUser({ realname: name, email: email }),
avatar && updateUserImage(avatar)
])
history.push('/tasks');
reload();
} catch (e) {
setError('There was an issue with saving your settings. Please try again!')
}
}, [history, user]);
}, [history]);
return (
user
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment