|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
import { useState, useEffect } from 'react'; |
|
|
|
|
import { |
|
|
|
|
Drawer, |
|
|
|
|
Button, |
|
|
|
@ -13,8 +14,23 @@ import { useSnackbar } from '../Contexts/SnackbarContext';
|
|
|
|
|
import CloseIcon from '@mui/icons-material/Close'; |
|
|
|
|
|
|
|
|
|
export const UserProfile = ({ showDrawer, toggleDrawer }) => { |
|
|
|
|
const { user, signOut } = useAuth(); |
|
|
|
|
const { user, signOut, updateUserMetaData } = useAuth(); |
|
|
|
|
const { showSnackBar } = useSnackbar(); |
|
|
|
|
const [profileInputs, setProfileInputs] = useState({ username: '' }); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
setProfileInputs({ username: user.user_metadata.username }); |
|
|
|
|
}, [showDrawer, user]); |
|
|
|
|
|
|
|
|
|
const handleChange = ({ target: { name, value } }) => { |
|
|
|
|
setProfileInputs({ ...profileInputs, [name]: value }); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const handleUpdate = async (e) => { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
const res = await updateUserMetaData({ username: profileInputs.username }); |
|
|
|
|
if (res) showSnackBar('success', 'nickname updated'); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const handleSignOut = (e) => { |
|
|
|
|
e.preventDefault(); |
|
|
|
@ -41,9 +57,21 @@ export const UserProfile = ({ showDrawer, toggleDrawer }) => {
|
|
|
|
|
</IconButton> |
|
|
|
|
</Toolbar> |
|
|
|
|
<Divider /> |
|
|
|
|
<Stack m={2} spacing={1}> |
|
|
|
|
<TextField fullWidth label="email" value={user.email} /> |
|
|
|
|
|
|
|
|
|
<Stack m={2} spacing={2}> |
|
|
|
|
<TextField |
|
|
|
|
name="username" |
|
|
|
|
label="username" |
|
|
|
|
value={profileInputs.username} |
|
|
|
|
type="text" |
|
|
|
|
onChange={handleChange} |
|
|
|
|
required |
|
|
|
|
autoComplete="username" |
|
|
|
|
/> |
|
|
|
|
{/** TODO: add update email fnc*/} |
|
|
|
|
<TextField fullWidth label="email" value={user.email} disabled /> |
|
|
|
|
<Button fullWidth onClick={(e) => handleUpdate(e)}> |
|
|
|
|
update profile |
|
|
|
|
</Button> |
|
|
|
|
<Button fullWidth onClick={(e) => handleSignOut(e)}> |
|
|
|
|
signout |
|
|
|
|
</Button> |
|
|
|
|