import React, { useState } from 'react' import { Link, useHistory } from 'react-router-dom' import useAuth from '@wasp/auth/useAuth.js' import logout from '@wasp/auth/logout.js' import updateUser from '@wasp/actions/updateUser' import Navbar from './Navbar' const UserSettingsPage = () => { const { data: user, isError } = useAuth({ keepPreviousData: true }) // TODO: Instead of this logic here, I wish I could use ACL via Wasp and just // receive user via props instead of useAuth(). if (!user || isError) { return Please log in. } return (
) } const UserSettings = (props) => { const user = props.user const history = useHistory() const [profilePictureUrl, setProfilePictureUrl] = useState(user.profilePictureUrl || '') const [username, setUsername] = useState(user.username || '') const [bio, setBio] = useState(user.bio || '') const [email, setEmail] = useState(user.email || '') const [newPassword, setNewPassword] = useState('') const [submitError, setSubmitError] = useState(null) const handleSubmit = async (event) => { event.preventDefault() setSubmitError(null) try { await updateUser({ profilePictureUrl, username, bio, email, newPassword }) // TODO: If update was successful, send user to his profile (/@). history.push(`/@${username}`) } catch (err) { setSubmitError(err) } } const handleLogout = async () => { await logout() history.push('/') } return (
{ submitError && (

{ submitError.message || submitError }

) }

URL of profile picture

setProfilePictureUrl(e.target.value)} />

Username

setUsername(e.target.value)} />

Short bio