From c2dfbaad88b3e5296e1750483cb89a3bca8fc8b6 Mon Sep 17 00:00:00 2001 From: Bailey Pumfleet Date: Thu, 29 Apr 2021 13:36:37 +0100 Subject: [PATCH] Set avatar through URL --- pages/api/user/profile.ts | 2 ++ pages/settings/profile.tsx | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pages/api/user/profile.ts b/pages/api/user/profile.ts index 9ddbe984e6..c471b0a315 100644 --- a/pages/api/user/profile.ts +++ b/pages/api/user/profile.ts @@ -26,6 +26,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const username = req.body.username; const name = req.body.name; const description = req.body.description; + const avatar = req.body.avatar; const timeZone = req.body.timeZone; const updateUser = await prisma.user.update({ @@ -35,6 +36,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) data: { username, name, + avatar, bio: description, timeZone: timeZone, }, diff --git a/pages/settings/profile.tsx b/pages/settings/profile.tsx index e80d5e8738..0749fd46b7 100644 --- a/pages/settings/profile.tsx +++ b/pages/settings/profile.tsx @@ -1,6 +1,7 @@ import Head from 'next/head'; import Link from 'next/link'; import { useRef, useState } from 'react'; +import { useRouter } from 'next/router'; import prisma from '../../lib/prisma'; import Modal from '../../components/Modal'; import Shell from '../../components/Shell'; @@ -10,10 +11,12 @@ import TimezoneSelect from 'react-timezone-select'; export default function Settings(props) { const [ session, loading ] = useSession(); + const router = useRouter(); const [successModalOpen, setSuccessModalOpen] = useState(false); const usernameRef = useRef(); const nameRef = useRef(); const descriptionRef = useRef(); + const avatarRef = useRef(); const [ selectedTimeZone, setSelectedTimeZone ] = useState({ value: props.user.timeZone }); @@ -33,18 +36,20 @@ export default function Settings(props) { const enteredUsername = usernameRef.current.value; const enteredName = nameRef.current.value; const enteredDescription = descriptionRef.current.value; + const enteredAvatar = avatarRef.current.value; const enteredTimeZone = selectedTimeZone.value; // TODO: Add validation const response = await fetch('/api/user/profile', { method: 'PATCH', - body: JSON.stringify({username: enteredUsername, name: enteredName, description: enteredDescription, timeZone: enteredTimeZone}), + body: JSON.stringify({username: enteredUsername, name: enteredName, description: enteredDescription, avatar: enteredAvatar, timeZone: enteredTimeZone}), headers: { 'Content-Type': 'application/json' } }); + router.replace(router.asPath); setSuccessModalOpen(true); } @@ -111,7 +116,7 @@ export default function Settings(props) { -
+ {/*
-
+
*/}
{props.user.avatar && } {!props.user.avatar &&
} - */} +
+
+ +