import React from 'react' import { useNavigate, useLocation } from 'react-router-dom' import { supabase } from '../utils/supaBase'; import { useState, useEffect } from 'react'; import styles from '../styles'; import Navbar from '../components/Navbar'; import { checkValuesAgainstBoundaries } from 'react-range'; import login_img from '../assets/login_img_png.png' import InputField from '../components/InputField'; import { CartState } from '../context/Context' const EvalOrCompleteProfile = () => { const { userState, userDispatch } = CartState(); const navigate = useNavigate(); const location = useLocation(); const userId = location.state.userId; const [profile, setProfile] = useState(); const [error, setError] = useState(); const [website, setWebsite] = useState(); const [socialmedia, setSocialmedia] = useState(); const [comlocation, setComlocation] = useState(); const [type, setType] = useState(); const handleSignOut = async () => { const { error } = await supabase.auth.signOut() userDispatch({ type: 'LOGOUT' }) navigate('/login') } useEffect(() => { async function fetchProfile() { const { data, error } = await supabase .from('profiles') .select('*') .eq('id', userId) if (error) { setError('Could not fetch data') setProfile(null) } else { // if(!data[0].completed) { // setType(data[0].type) // setProfile(data) // setError(null) // } // else { // navigate('/dashboard', { // state: { // userId: userId, // } // }) // } if(data[0].completed) { if(data[0].admin || data[0].type === 'team') { userDispatch({ type: 'LOGIN', payload : data[0].id }) navigate('/dashboardadmin') } else { if(data[0].type === 'agency') { navigate('/subscribe', { state: { userId: userId, } }) } else { navigate('/dashboard', { state: { userId: userId, } }) } } } else { setType(data[0].type) setProfile(data) setError(null) } } } fetchProfile(); }, [userId]) async function handleSubmit(event) { event.preventDefault() const { error } = await supabase .from('profiles') .update({ completed: true, website: website, social_media: socialmedia, location: comlocation }) .eq('id', userId) if (error) { alert(error.error_description || error.message) } else { console.log(userId) handleSignOut(); } console.log(comlocation, website, socialmedia) } if (type && type === 'agency') { return ( profile &&

COMPLETE ACCOUNT!

SIGNUP TO GET EXCLUSIVE DATA...

setWebsite(e.target.value)} /> setComlocation(e.target.value)} />
setSocialmedia(e.target.value)} />
) } else if (type && type === 'brand' || type && type === 'team'){ return ( <> {profile && (
{profile[0].verified &&

COMPLETE ACCOUNT!

SIGNUP TO GET EXCLUSIVE DATA...

{type === 'brand' &&
setWebsite(e.target.value)} /> setComlocation(e.target.value)} />
setSocialmedia(e.target.value)} />
}
} {!profile[0].verified && ( <>

WE ARE EVALUATING YOUR PROFILE

In order to make sure our brand holds up a standard, Our system does not allow access to any profiles

Pending
)}
)} ) } } export default EvalOrCompleteProfile