2024-02-18 01:44:48 -05:00
// ** MUI Imports
import Grid from '@mui/material/Grid'
// ** Icons Imports
import Poll from 'mdi-material-ui/Poll'
import CurrencyUsd from 'mdi-material-ui/CurrencyUsd'
import HelpCircleOutline from 'mdi-material-ui/HelpCircleOutline'
import BriefcaseVariantOutline from 'mdi-material-ui/BriefcaseVariantOutline'
// ** Custom Components Imports
import CardStatisticsVerticalComponent from '../../core/components/card-statistics/card-stats-vertical'
// ** Styled Component Import
import ApexChartWrapper from '../../core/styles/libs/react-apexcharts'
2024-02-18 06:59:55 -05:00
import { Card , TextField , Typography } from '@mui/material'
2024-02-18 01:44:48 -05:00
import { withApiAuthRequired } from "@auth0/nextjs-auth0" ;
import { withPageAuthRequired } from '@auth0/nextjs-auth0/client'
import Button from '@mui/material/Button'
import { CardContent } from '@mui/material'
import Onboarding from '../../components/Onboarding'
import { useState } from 'react'
import { useEffect } from 'react'
2024-02-18 06:59:55 -05:00
import router from 'next/router'
2024-02-18 01:44:48 -05:00
import { isObject } from 'util'
import Orders from '../../components/Orders'
2024-02-18 06:59:55 -05:00
import StatisticsCard from '../../views/dashboard/StatisticsCard'
import SellerStats from '../../components/SellerStats'
import { Clipboard } from 'mdi-material-ui'
2024-02-18 01:44:48 -05:00
const Dashboard = ( ) = > {
const [ profileData , setSellerProfileData ] = useState ( null ) ;
const [ requestData , setSellerRequestData ] = useState ( null ) ;
2024-02-18 02:31:54 -05:00
const [ onboardData , setOnboardedData ] = useState ( false ) ;
2024-02-18 01:44:48 -05:00
const [ onboarding , setOnboarding ] = useState ( false ) ;
const [ onboarded , setOnboarded ] = useState ( false ) ;
const setOnboardingTrue = ( ) = > {
setOnboarding ( true ) ;
}
const getData = async ( ) = > {
const profileResponse = await fetch ( '/api/artist/profile' ) ;
const sellerProfile = await profileResponse . json ( ) ;
setSellerProfileData ( sellerProfile ) ;
const requestResponse = await fetch ( '/api/artist/request' ) ;
const sellerRequest = await requestResponse . json ( ) ;
setSellerRequestData ( sellerRequest ) ;
2024-02-18 02:31:54 -05:00
const onboardedResponse = await fetch ( '/api/artist/onboarded' ) ;
const onboardedData = await onboardedResponse . json ( ) ;
setOnboardedData ( onboardedData [ "onboarded" ] ) ;
2024-02-18 01:44:48 -05:00
setTimeout ( getData , 5000 ) ; // Poll every 5 seconds (adjust as needed)
if ( sellerRequest != null && Object . keys ( sellerRequest ) . length > 0 ) {
setOnboarding ( true )
}
if ( sellerProfile != null && Object . keys ( sellerProfile ) . length > 0 && sellerRequest [ "accepted" ] ) {
setOnboarded ( true )
}
}
useEffect ( ( ) = > {
getData ( ) ;
} , [ ] ) ;
return (
< ApexChartWrapper >
< Grid container spacing = { 6 } >
< Grid item xs = { 12 } md = { 6 } >
< Card >
< CardContent >
< Grid container >
2024-02-18 06:59:55 -05:00
< Grid item xs = { 12 } md = { 3 } sx = { { textAlign : "center" } } >
2024-02-18 01:44:48 -05:00
< Typography variant = "h5" gutterBottom >
My Orders
< / Typography >
< / Grid >
2024-02-18 06:59:55 -05:00
< Grid item xs = { 12 } md = { 4 } sx = { { textAlign : "center" } } >
< / Grid >
< Grid item xs = { 12 } md = { 5 } sx = { { textAlign : "center" } } >
< Button color = "info" onClick = { ( ) = > { router . push ( "/dashboard/orders" ) } } fullWidth variant = "contained" > View All Orders < / Button >
< / Grid >
< Grid item xs = { 12 } md = { 12 } sx = { { paddingTop : "2%" } } >
2024-02-18 01:44:48 -05:00
< Orders / >
< / Grid >
< / Grid >
< / CardContent >
< / Card >
< / Grid >
2024-02-18 02:31:54 -05:00
{ ( onboarding == true && onboardData == false ) ? (
2024-02-18 01:44:48 -05:00
< Grid item xs = { 12 } md = { 6 } >
< Onboarding / >
< / Grid >
) : (
2024-02-18 02:31:54 -05:00
( onboarding ) ? (
2024-02-18 06:59:55 -05:00
< Grid item xs = { 12 } md = { 6 } >
2024-02-18 01:44:48 -05:00
< Card sx = { { textAlign : "center" , width : "100%" } } >
< CardContent >
2024-02-18 06:59:55 -05:00
< Grid spacing = { 3 } container >
< Grid item xs = { 12 } md = { 12 } >
< SellerStats / >
< / Grid >
< Grid item xs = { 12 } md = { 8 } >
< TextField size = "small" label = "Your Public URL" variant = "outlined" disabled fullWidth defaultValue = { "http://localhost:3000/shops/neroshi" } > "http://localhost:3000/shops/neroshi" < / TextField >
< / Grid >
< Grid item xs = { 12 } md = { 2 } >
< Button color = "info" startIcon = { < Clipboard / > } onClick = { ( ) = > { router . push ( "/dashboard/artist/artistsettings#portfolio" ) } } fullWidth variant = "outlined" > Copy < / Button >
< / Grid >
< Grid item xs = { 12 } md = { 2 } >
< Button color = "secondary" onClick = { ( ) = > { router . push ( "/dashboard/artist/artistsettings#portfolio" ) } } fullWidth variant = "outlined" > Preview < / Button >
< / Grid >
< Grid item xs = { 12 } md = { 6 } >
< Button color = "secondary" onClick = { ( ) = > { router . push ( "/dashboard/artist/artistsettings#portfolio" ) } } fullWidth variant = "contained" > Manage Portfolio < / Button >
< / Grid >
< Grid item xs = { 12 } md = { 6 } >
< Button color = "secondary" onClick = { ( ) = > { router . push ( "/dashboard/artist/pagesettings" ) } } fullWidth variant = "contained" > Design Store Page < / Button >
< / Grid >
2024-02-18 02:31:54 -05:00
< Grid item xs = { 12 } md = { 6 } >
2024-02-18 06:59:55 -05:00
< Button color = "secondary" onClick = { ( ) = > { router . push ( "/dashboard/artist/pagesettings" ) } } fullWidth variant = "contained" > Payment Portal < / Button >
2024-02-18 02:31:54 -05:00
< / Grid >
< Grid item xs = { 12 } md = { 6 } >
2024-02-18 06:59:55 -05:00
< Button color = "secondary" onClick = { ( ) = > { router . push ( "/dashboard/artist/pagesettings" ) } } fullWidth variant = "contained" > Configure Your Shop < / Button >
2024-02-18 01:44:48 -05:00
< / Grid >
< / Grid >
< / CardContent >
< / Card >
< / Grid >
) : (
< Grid item xs = { 12 } md = { 6 } >
< Card sx = { { textAlign : "center" , width : "100%" } } >
< CardContent >
< Grid container >
< Grid item xs = { 12 } md = { 12 } >
< Button color = "primary" fullWidth variant = "contained" onClick = { setOnboardingTrue } > Become An Artist < / Button >
< / Grid >
< / Grid >
< / CardContent >
< / Card >
< / Grid >
)
) }
< / Grid >
< / ApexChartWrapper >
)
}
export default withPageAuthRequired ( Dashboard )