From b9aed8f3bb035205944ae307a21f879875f8057e Mon Sep 17 00:00:00 2001 From: Damien Ostler Date: Sun, 18 Feb 2024 07:23:34 -0500 Subject: [PATCH] fix: name not being returned --- pages/api/artist/profile.tsx | 31 ++++++++--- pages/dashboard/artist/artistsettings.tsx | 65 ++++++++++++++++++++--- 2 files changed, 80 insertions(+), 16 deletions(-) diff --git a/pages/api/artist/profile.tsx b/pages/api/artist/profile.tsx index af46463..1aa8d76 100644 --- a/pages/api/artist/profile.tsx +++ b/pages/api/artist/profile.tsx @@ -2,13 +2,28 @@ import { getAccessToken, withApiAuthRequired, getSession } from '@auth0/nextjs-a export default withApiAuthRequired(async function sellerProfile(req, res) { const { accessToken } = await getAccessToken(req, res); - const response = await fetch(process.env.NEXT_PUBLIC_API_URL+'/api/SellerProfile', { - headers: { - "Authorization": `Bearer ${accessToken}` - } - }); - - let result = await response.json(); - res.status(200).json(result); + if(req.method !== 'GET') { + const response = await fetch(process.env.NEXT_PUBLIC_API_URL+'/api/SellerProfile', { + headers: { + "Authorization": `Bearer ${accessToken}`, + "Content-Type": "application/json" + }, + method: "PUT", + body: req.body + }); + + let result = await response.json(); + res.status(200).json(result); + } + else{ + const response = await fetch(process.env.NEXT_PUBLIC_API_URL+'/api/SellerProfile', { + headers: { + "Authorization": `Bearer ${accessToken}` + } + }); + + let result = await response.json(); + res.status(200).json(result); + } }); diff --git a/pages/dashboard/artist/artistsettings.tsx b/pages/dashboard/artist/artistsettings.tsx index 94f5215..b086ab1 100644 --- a/pages/dashboard/artist/artistsettings.tsx +++ b/pages/dashboard/artist/artistsettings.tsx @@ -11,10 +11,59 @@ import Divider from '@mui/material/Divider'; const ArtistSettings = () => { const {user, isLoading} = useUser(); + + const [name, setName] = useState(""); + const [description, setDescription] = useState(""); + const [social1, setSocial1] = useState(""); + const [social2, setSocial2] = useState(""); + const [social3, setSocial3] = useState(""); + const [social4, setSocial4] = useState(""); + const [guidelines, setGuidelines] = useState(""); + const [saved, setSaved] = useState(false); + const [profileData, setSellerProfileData] = useState(null); + + const handleDisplayNameChange = (event) => { + setName(event.target.value); + } +const handleBiographyChange = (event) => { + setDescription(event.target.value); +} +const handleSocial1Change = (event) => { + setSocial1(event.target.value); +} +const handleSocial2Change = (event) => { + setSocial2(event.target.value); +} +const handleSocial3Change = (event) => { + setSocial3(event.target.value); +} +const handleSocial4Change = (event) => { + setSocial4(event.target.value); +} +const handleGuidelinesChange = (event) => { + setGuidelines(event.target.value); +} + +const saveChanges = async () => { + var userResponse = await fetch('/api/artist/profile',{ + method: 'PUT', + body: JSON.stringify({name: name, description: description, socialMeidaLink1: social1, socialMeidaLink2: social2, socialMeidaLink3: social3, socialMeidaLink4: social4, requestGuidelines: guidelines}) + }); + var user = await userResponse.json(); + setSaved(true) +} + const getData = async () => { const profileResponse = await fetch('/api/artist/profile'); const sellerProfile = await profileResponse.json(); + setDescription(sellerProfile["description"]); + setName(sellerProfile["name"]); + setSocial1(sellerProfile["socialMeidaLink1"]); + setSocial2(sellerProfile["socialMeidaLink2"]); + setSocial3(sellerProfile["socialMeidaLink3"]); + setSocial4(sellerProfile["socialMeidaLink4"]); + setGuidelines(sellerProfile["requestGuidelines"]); setSellerProfileData(sellerProfile); } @@ -31,34 +80,34 @@ const ArtistSettings = () => { General Settings - + - + - + - + - + - + - + - +