/* This is the Dashboard component. If a user is logged in, he/she can update his/her name and website. You can add as many elements as you want. Don't forget to update your getProfile() and updateProfile() function with your new elements. It also show you the current subscription plan */ import { useEffect, useState } from "react"; import Avatar from "./Avatar"; import Image from "next/image"; import PaymentModal from "./PaymentModal"; import Plan from "public/plan.svg"; import { PriceIds } from "utils/priceList"; import { supabase } from "../utils/supabaseClient"; import { toast } from "react-toastify"; import { useRouter } from "next/router"; export default function Dashboard(props) { const router = useRouter(); const [loading, setLoading] = useState(false); const [username, setUsername] = useState(props.profile.username); const [website, setWebsite] = useState(props.profile.website); const [avatar_url, setAvatarUrl] = useState(props.profile.avatar_url); const [payment, setPayment] = useState(false); useEffect(() => { if (router.query.session_id && router.query.session_id !== "canceled") { setPayment(true); } }, []); async function updateProfile({ username, website, avatar_url }) { try { setLoading(true); const user = supabase.auth.user(); const updates = { id: user.id, username, website, avatar_url, updated_at: new Date(), }; let { error } = await supabase.from("profiles").upsert(updates, { returning: "minimal", // Don't return the value after inserting }); if (error) { throw error; } } catch (error) { alert(error.message); } finally { setLoading(false); toast.success("Your profile has been updated"); } } return (
{props.plan ? PriceIds[props.plan] : "Free tier"}