import { useUser } from "@auth0/nextjs-auth0/client"; import { useTheme } from '@mui/material/styles'; import AppBar from '@mui/material/AppBar'; import Tabs from '@mui/material/Tabs'; import Tab from '@mui/material/Tab'; import Layout from "../components/layout"; import { Grid, Button, Typography, TextField, Box, CircularProgress } from "@mui/material"; import { useState, useEffect } from "react"; import Card from '@mui/material/Card'; import CardContent from '@mui/material/CardContent'; import CardActions from '@mui/material/CardActions'; import { styled } from '@mui/material/styles'; import SwipeableViews from '../components/swipableView'; import { DataGrid, GridColDef, GridValueGetterParams } from '@mui/x-data-grid'; const SellerDashoard = (ctx) => { const { user, isLoading } = useUser(); const [sellerRequestData, setSellerRequestData] = useState([]); const [sellerData, setSellerData] = useState([]); const [loading, setLoading] = useState(true); // State for loading indicator const [isOnboarded, setIsOnboarded] = useState(false); const [onBoardUrl, setOnBoardUrl] = useState(""); const [tabValue, setTabValue] = useState(1); const getData = async () => { const response = await fetch('/api/artist/profile'); const sellerProfile = await response.json(); setSellerData(sellerProfile); const requestResponse = await fetch('/api/artist/request', { method: "GET" }); const sellerRequest = await requestResponse.json(); setSellerRequestData(sellerRequest); const onboardCheckRequest = await fetch('/api/artist/onboarded', { method: "GET" }); const onboardCheckResponse = await onboardCheckRequest.json(); setIsOnboarded(onboardCheckResponse["onboarded"]); const onboardUrlRequest = await fetch('/api/artist/onboardurl', { method: "GET" }); const onboardUrlResponse = await onboardUrlRequest.json(); setOnBoardUrl(onboardUrlResponse["onboardUrl"]); setLoading(false); // Once data is fetched, set loading to false } const handleChange = (event: React.SyntheticEvent, newValue: number) => { setTabValue(newValue); }; const handleChangeIndex = (index: number) => { setTabValue(index); }; interface TabPanelProps { children?: React.ReactNode; dir?: string; index: number; value: number; } function TabPanel(props: TabPanelProps) { const { children, value, index, ...other } = props; return ( ); } function a11yProps(index: number) { return { id: `full-width-tab-${index}`, 'aria-controls': `full-width-tabpanel-${index}`, }; } useEffect(() => { getData(); }, []); const theme = useTheme(); const columns: GridColDef[] = [ { field: 'requestor', headerName: 'User', width: 150 }, { field: 'message', headerName: 'Message', width: 280 }, { field: 'amount', headerName: 'Amount', width: 125 }, ]; const rows = [ { id: 1, requestor: 'Snow', message: 'This is a test message!', amount: 35.00 }, { id: 2, requestor: 'Lannister', message: 'This is a test message!', amount: 42.00 }, { id: 3, requestor: 'Lannister', message: 'This is a test message!', amount: 45.00 }, { id: 4, requestor: 'Stark', message: 'This is a test message!', amount: 16.00 }, { id: 5, requestor: 'Targaryen', message: 'This is a test message!', amount: 150.00 }, { id: 6, requestor: 'Melisandre', message: "This is a test message!", amount: 150.00 }, { id: 7, requestor: 'Clifford', message: 'This is a test message!', amount: 44.00 }, { id: 8, requestor: 'Frances', message: 'This is a test message!', amount: 36.00 }, { id: 9, requestor: 'Roxie', message: 'This is a test message!', amount: 65.00 }, ]; let formattedTime = "" if (sellerRequestData) { const date = new Date(sellerRequestData["requestDate"]); formattedTime = date.toLocaleTimeString('en-US', { month: 'long', day: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit' }); // Example format } const payoutButton = () =>{ fetch('/api/artist/payout').then((response) => { if (response.ok) { fetch('/api/artist/request').then((requestResponse) => { requestResponse.json().then((sellerRequest) => { setSellerRequestData(sellerRequest); }); }); } }); } const requestButton = () => { fetch('/api/artist/newRequest').then((response) => { if (response.ok) { fetch('/api/artist/request').then((requestResponse) => { requestResponse.json().then((sellerRequest) => { setSellerRequestData(sellerRequest); getData(); }); }); } }); } return ( <> {loading ? ( // Render loading indicator if loading is true Loading... ) : ( {(Object.keys(sellerData).length > 0 ? ( <> Artist Dashboard {(Object.keys(sellerRequestData).length > 0 ? ( <> Request Status {(sellerRequestData["accepted"] ? ( Accepted ) : ( Pending ))} Request submitted on {formattedTime ?? ''} {(sellerRequestData["accepted"] ? ( <> {(isOnboarded ? (<> ) : ( <> ))} Item Two Item Three ) : ( <> ))} ) : ( <> {(Object.keys(sellerRequestData).length==0 || sellerRequestData["accepted"]==false ? (<>):(<>))} ))} ) : ( <> Item Two Item Three ))} )} ); }; export default SellerDashoard;