feat: added portfolio to artist dashboard

This commit is contained in:
Damien Ostler 2024-02-15 02:16:38 -05:00
parent ed48b67e3c
commit c8b1dfb3ba
7 changed files with 94 additions and 24 deletions

View File

@ -13,7 +13,7 @@ const ArtistPortfolio = ({artistId}) => {
setPortfolioData(data); setPortfolioData(data);
setLoading(false); setLoading(false);
} }
//console.log(portfolioData) ////console.log(portfolioData)
getData(); getData();
}, []); }, []);
return ( return (

View File

@ -22,7 +22,7 @@ const EditableArtistPortfolio = ({ artistId }) => {
function handlePortfolioUploadImageChange(event) { function handlePortfolioUploadImageChange(event) {
const file = event.target.files[0]; const file = event.target.files[0];
const formData = new FormData(); const formData = new FormData();
formData.append('file', file); formData.append('newImage', file);
fetch('/api/artist/portfolio', { fetch('/api/artist/portfolio', {
method: 'POST', method: 'POST',
@ -45,7 +45,9 @@ const EditableArtistPortfolio = ({ artistId }) => {
</Box> </Box>
) : ) :
( (
<Grid container spacing={2} sx={{ padding: 4 }}> (portfolioData.length > 0 ?(<>
<Grid container spacing={2} sm={12} sx={{ padding: 4 }}>
<Grid item xs={12} sm={12} sx={{ textAlign: "center" }}> <Grid item xs={12} sm={12} sx={{ textAlign: "center" }}>
<input <input
id="portfolioUploadInput" id="portfolioUploadInput"
@ -60,20 +62,43 @@ const EditableArtistPortfolio = ({ artistId }) => {
variant='outlined' variant='outlined'
component="span" component="span"
size="small" size="small"
sx={{width:"100%"}}
startIcon={<FileOpenIcon />} startIcon={<FileOpenIcon />}
> >
Add Image Add Image
</Button> </Button>
</label> </label>
</Grid> </Grid>
<Grid item xs={12} sm={12} sx={{ textAlign: "center" }}>
<ImageList cols={2} rowHeight={200} sx={{ maxHeight: 400 }}>
{portfolioData.map((item) => (
<EditableArtistPortfolioImage artistId={artistId} itemId={item.id} />
))}
</ImageList>
</Grid>
</Grid> </Grid>
<ImageList cols={2} rowHeight={200} sx={{ height: 400, width:"100%" }}>
{portfolioData.map((item) => (
<EditableArtistPortfolioImage artistId={artistId} itemId={item.id} />
))}
</ImageList>
</>
) : (
<Box sx={{ textAlign: "center" }}>
<input
id="portfolioUploadInput"
style={{ display: 'none' }}
accept="image/*"
type="file"
onChange={handlePortfolioUploadImageChange}
/>
<label htmlFor="portfolioUploadInput">
<Button
fullWidth
variant='outlined'
component="span"
size="small"
sx={{width:"100%"}}
startIcon={<FileOpenIcon />}
>
Upload Your First Portfolio Image
</Button>
</label>
</Box>
))
) )
) )
} }

View File

@ -2,8 +2,9 @@ import * as React from 'react';
import ImageList from '@mui/material/ImageList'; import ImageList from '@mui/material/ImageList';
import ImageListItem from '@mui/material/ImageListItem'; import ImageListItem from '@mui/material/ImageListItem';
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import DeleteIcon from '@mui/icons-material/Delete';
import { CircularProgress } from '@mui/material'; import { CircularProgress, ImageListItemBar } from '@mui/material';
import { IconButton } from '@mui/material'; import { IconButton } from '@mui/material';
@ -13,8 +14,16 @@ const EditableArtistPortfolioImage = ({artistId,itemId}) => {
setLoaded(true); setLoaded(true);
}; };
const deleteButton = () => {
fetch('/api/artist/portfolio/'+itemId+"/delete", {
method: 'DELETE'
}).then(response =>
window.location.reload());
}
return ( return (
<ImageListItem key={itemId }> <ImageListItem key={itemId } sx={{maxWidth:300, maxHeight:300, overflow:"hidden"}}>
<img <img
srcSet={process.env.NEXT_PUBLIC_API_URL+`/api/Discovery/Sellers/${artistId}/Portfolio/${itemId}`} srcSet={process.env.NEXT_PUBLIC_API_URL+`/api/Discovery/Sellers/${artistId}/Portfolio/${itemId}`}
src={process.env.NEXT_PUBLIC_API_URL+`/api/Discovery/Sellers/${artistId}/Portfolio/${itemId}`} src={process.env.NEXT_PUBLIC_API_URL+`/api/Discovery/Sellers/${artistId}/Portfolio/${itemId}`}
@ -23,6 +32,13 @@ const EditableArtistPortfolioImage = ({artistId,itemId}) => {
style={{ filter: loaded ? 'blur(0)' : 'blur(10px)', backgroundColor:'grey' }} style={{ filter: loaded ? 'blur(0)' : 'blur(10px)', backgroundColor:'grey' }}
onLoad={handleImageLoaded} onLoad={handleImageLoaded}
/> />
<ImageListItemBar
actionIcon={
<IconButton onClick={deleteButton} color="error" >
<DeleteIcon />
</IconButton>
}>
</ImageListItemBar>
</ImageListItem>) </ImageListItem>)
} }
export default EditableArtistPortfolioImage export default EditableArtistPortfolioImage

View File

@ -1,11 +1,16 @@
import { getAccessToken, withApiAuthRequired } from '@auth0/nextjs-auth0'; import { getAccessToken, withApiAuthRequired } from '@auth0/nextjs-auth0';
import { IncomingForm } from 'formidable' import { IncomingForm } from 'formidable'
import fs from 'fs/promises';
export const config = { export const config = {
api: { api: {
bodyParser: false, bodyParser: false,
}, },
}; };
async function createBlobFromFile(path: string): Promise<Blob> {
const file = await fs.readFile(path);
return new Blob([file]);
}
export default withApiAuthRequired(async function handler(req, res) { export default withApiAuthRequired(async function handler(req, res) {
const { accessToken } = await getAccessToken(req, res); const { accessToken } = await getAccessToken(req, res);
@ -18,22 +23,19 @@ export default withApiAuthRequired(async function handler(req, res) {
res.status(500).json({ error: 'Error parsing form' }); res.status(500).json({ error: 'Error parsing form' });
return; return;
} }
const file = files["file"]; // Assuming your file input field name is 'file' const file = files["newImage"]; // Assuming your file input field name is 'file'
console.log(file)
const formData = new FormData();
formData.append('file', file); // Append the file to FormData
console.log(formData)
try { try {
const response = await fetch(process.env.NEXT_PUBLIC_API_URL + '/api/SellerProfile/Portfolio', { const response = await fetch(process.env.NEXT_PUBLIC_API_URL + '/api/SellerProfile/Portfolio', {
method: 'POST', method: 'POST',
headers: { headers: {
"Authorization": `Bearer ${accessToken}` "Authorization": `Bearer ${accessToken}`,
"Content-Type": " application/octet-stream"
}, },
body: formData // Don't set Content-Type, FormData will handle it body: await createBlobFromFile(file[0].filepath) // Don't set Content-Type, FormData will handle it
}); });
//console.log(response)
if (!response.ok) { if (!response.ok) {
const errorData = await response.json(); const errorData = await response.json();
throw new Error(errorData.message || 'Failed to upload file'); throw new Error(errorData.message || 'Failed to upload file');

View File

@ -0,0 +1,26 @@
import { getAccessToken, withApiAuthRequired } from '@auth0/nextjs-auth0';
import { IncomingForm } from 'formidable'
import fs from 'fs/promises';
export const config = {
api: {
bodyParser: false,
},
};
async function createBlobFromFile(path: string): Promise<Blob> {
const file = await fs.readFile(path);
return new Blob([file]);
}
export default withApiAuthRequired(async function handler(req, res) {
const { accessToken } = await getAccessToken(req, res);
const { id } = req.query;
const response = await fetch(process.env.NEXT_PUBLIC_API_URL + '/api/SellerProfile/Portfolio/'+id, {
method: 'DELETE',
headers: {
"Authorization": `Bearer ${accessToken}`
},
});
res.status(200).json({status: await response.json()});
});

View File

@ -1,13 +1,14 @@
export default async function handler(req, res ): Promise<any> { export default async function handler(req, res ): Promise<any> {
const { sellerId } = req.query; const { sellerId } = req.query;
var url = process.env.NEXT_PUBLIC_API_URL+`/api/Discovery/Sellers/${sellerId}/Portfolio`; var url = process.env.NEXT_PUBLIC_API_URL+`/api/Discovery/Sellers/${sellerId}/Portfolio`;
//console.log(url) ////console.log(url)
const response = await fetch(url); const response = await fetch(url);
console.log(response)
if (!response.ok) { if (!response.ok) {
throw new Error('Failed to fetch seller portfolio'); throw new Error('Failed to fetch seller portfolio');
} }
var result = await response.json(); var result = await response.json();
//console.log(result) ////console.log(result)
res.status(200).json(result); res.status(200).json(result);
} }

View File

@ -241,7 +241,7 @@ const SellerDashoard = (ctx) => {
sx={{ width: '100%' }} sx={{ width: '100%' }}
/> />
</TabPanel> </TabPanel>
<TabPanel value={tabValue} index={1} dir={theme.direction}> <TabPanel value={tabValue} index={1} dir={theme.direction} >
<EditableArtistPortfolio artistId={sellerData["id"]}></EditableArtistPortfolio> <EditableArtistPortfolio artistId={sellerData["id"]}></EditableArtistPortfolio>
</TabPanel> </TabPanel>
<TabPanel value={tabValue} index={2} dir={theme.direction}> <TabPanel value={tabValue} index={2} dir={theme.direction}>