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 { ...@@ -19,7 +19,7 @@ interface Props {
user: User 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 { function validateEmail(email?: string): string | null {
if (email && email.length > 0) { if (email && email.length > 0) {
......
...@@ -6,11 +6,6 @@ ...@@ -6,11 +6,6 @@
overflow: hidden; overflow: hidden;
img { img {
width: 100%;
height: auto;
}
.standard-image {
width: 100%; width: 100%;
height: 100%; height: 100%;
background: s.$secondary; background: s.$secondary;
......
import { useCallback, useState } from 'react';
import { getUserImageUri, User } from 'adapters/user'; import { getUserImageUri, User } from 'adapters/user';
import './avatar.scss'; import './avatar.scss';
...@@ -10,27 +8,11 @@ interface Props { ...@@ -10,27 +8,11 @@ interface Props {
} }
export default function Avatar({ user }: Props) { export default function Avatar({ user }: Props) {
const [error, setError] = useState(false);
const avatarSrc = user && getUserImageUri(user.id); const avatarSrc = user && getUserImageUri(user.id);
const onError = useCallback(() => {
setError(true);
}, [setError]);
return ( return (
<div className="avatar"> <div className="avatar">
{ <img src={avatarSrc} alt={user?.username.charAt(0) ?? "?"} />
!error && (
<img src={avatarSrc} alt={user?.username} onError={onError} />
)
}
{
error && (
<div className="standard-image">
{user?.username && user.username.charAt(0)}
</div>
)
}
</div> </div>
) )
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { useHistory } from 'react-router'; import { useHistory } from 'react-router';
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import { reload } from 'index';
import { getCurrentUser, updateUser, updateUserImage, User } from 'adapters/user'; import { getCurrentUser, updateUser, updateUserImage, User } from 'adapters/user';
import Callout from 'components/ui/Callout'; import Callout from 'components/ui/Callout';
...@@ -16,21 +17,21 @@ export default function Settings() { ...@@ -16,21 +17,21 @@ export default function Settings() {
const history = useHistory(); const history = useHistory();
useEffect(() => { useEffect(() => {
getCurrentUser().then((user) => setUser(user)) getCurrentUser().then(setUser)
}, []); }, []);
const handleSubmit = useCallback(async (name?: string, email?: string, avatar?: File) => { const handleSubmit = useCallback(async (name?: string, email?: string, avatar?: File) => {
try { try {
if (user && updateUser({ realname: name, email })) { await Promise.all([
if (avatar) { updateUser({ realname: name, email: email }),
updateUserImage(avatar); avatar && updateUserImage(avatar)
} ])
history.push('/tasks'); history.push('/tasks');
} reload();
} catch (e) { } catch (e) {
setError('There was an issue with saving your settings. Please try again!') setError('There was an issue with saving your settings. Please try again!')
} }
}, [history, user]); }, [history]);
return ( return (
user 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