diff --git a/components/Dashboard.js b/components/Dashboard.js index 0acebbb..05eb391 100644 --- a/components/Dashboard.js +++ b/components/Dashboard.js @@ -4,49 +4,18 @@ You can add as many elements as you want. Don't forget to update your getProfile function with your new elements. */ -import { useEffect, useState } from "react"; - import Avatar from "./Avatar"; +import { PriceIds } from "utils/priceList"; import { supabase } from "../utils/supabaseClient"; import { toast } from "react-toastify"; +import { useState } from "react"; -export default function Account({ session }) { - const [loading, setLoading] = useState(true); - const [username, setUsername] = useState(null); - const [website, setWebsite] = useState(null); +export default function Account(props) { + const [loading, setLoading] = useState(false); + const [username, setUsername] = useState(props.profile.username); + const [website, setWebsite] = useState(props.profile.website); const [avatar_url, setAvatarUrl] = useState(null); - useEffect(() => { - getProfile(); - }, [session]); - - async function getProfile() { - try { - setLoading(true); - const user = supabase.auth.user(); - - let { data, error, status } = await supabase - .from("profiles") - .select(`username, website, avatar_url`) - .eq("id", user.id) - .single(); - - if (error && status !== 406) { - throw error; - } - - if (data) { - setUsername(data.username); - setWebsite(data.website); - setAvatarUrl(data.avatar_url); - } - } catch (error) { - alert(error.message); - } finally { - setLoading(false); - } - } - async function updateProfile({ username, website, avatar_url }) { try { setLoading(true); @@ -71,64 +40,71 @@ export default function Account({ session }) { alert(error.message); } finally { setLoading(false); - toast.success("Your profile has been updated") + toast.success("Your profile has been updated"); } } return ( -
{props.plan.plan ? PriceIds[props.plan.plan] : "Free tier"}