diff --git a/components/artistPortfolio.tsx b/components/artistPortfolio.tsx index 557dd73..836707b 100644 --- a/components/artistPortfolio.tsx +++ b/components/artistPortfolio.tsx @@ -13,7 +13,7 @@ const ArtistPortfolio = ({artistId}) => { setPortfolioData(data); setLoading(false); } - //console.log(portfolioData) + ////console.log(portfolioData) getData(); }, []); return ( diff --git a/components/editableArtistPortfolio.tsx b/components/editableArtistPortfolio.tsx index 3e26d8c..9523721 100644 --- a/components/editableArtistPortfolio.tsx +++ b/components/editableArtistPortfolio.tsx @@ -22,7 +22,7 @@ const EditableArtistPortfolio = ({ artistId }) => { function handlePortfolioUploadImageChange(event) { const file = event.target.files[0]; const formData = new FormData(); - formData.append('file', file); + formData.append('newImage', file); fetch('/api/artist/portfolio', { method: 'POST', @@ -45,7 +45,9 @@ const EditableArtistPortfolio = ({ artistId }) => { ) : ( - + (portfolioData.length > 0 ?(<> + + { variant='outlined' component="span" size="small" + sx={{width:"100%"}} startIcon={} > Add Image - - - {portfolioData.map((item) => ( - - ))} - - + + {portfolioData.map((item) => ( + + ))} + + + ) : ( + + + + + )) ) ) } diff --git a/components/editableArtistPortfolioImage.tsx b/components/editableArtistPortfolioImage.tsx index 182ec0b..4cf69fe 100644 --- a/components/editableArtistPortfolioImage.tsx +++ b/components/editableArtistPortfolioImage.tsx @@ -2,8 +2,9 @@ import * as React from 'react'; import ImageList from '@mui/material/ImageList'; import ImageListItem from '@mui/material/ImageListItem'; 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'; @@ -13,8 +14,16 @@ const EditableArtistPortfolioImage = ({artistId,itemId}) => { setLoaded(true); }; + + const deleteButton = () => { + fetch('/api/artist/portfolio/'+itemId+"/delete", { + method: 'DELETE' + }).then(response => + window.location.reload()); + } + return ( - + { style={{ filter: loaded ? 'blur(0)' : 'blur(10px)', backgroundColor:'grey' }} onLoad={handleImageLoaded} /> + + + + }> + ) } export default EditableArtistPortfolioImage \ No newline at end of file diff --git a/pages/api/artist/portfolio.tsx b/pages/api/artist/portfolio.tsx index cbbf35a..7454a31 100644 --- a/pages/api/artist/portfolio.tsx +++ b/pages/api/artist/portfolio.tsx @@ -1,11 +1,16 @@ 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 { + const file = await fs.readFile(path); + return new Blob([file]); +} export default withApiAuthRequired(async function handler(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' }); return; } - const file = files["file"]; // 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) + const file = files["newImage"]; // Assuming your file input field name is 'file' try { const response = await fetch(process.env.NEXT_PUBLIC_API_URL + '/api/SellerProfile/Portfolio', { method: 'POST', 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) { const errorData = await response.json(); throw new Error(errorData.message || 'Failed to upload file'); diff --git a/pages/api/artist/portfolio/[id]/delete.tsx b/pages/api/artist/portfolio/[id]/delete.tsx new file mode 100644 index 0000000..25b2981 --- /dev/null +++ b/pages/api/artist/portfolio/[id]/delete.tsx @@ -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 { + 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()}); +}); diff --git a/pages/api/discovery/artist/[sellerId]/portfolio.tsx b/pages/api/discovery/artist/[sellerId]/portfolio.tsx index 7602596..554ea79 100644 --- a/pages/api/discovery/artist/[sellerId]/portfolio.tsx +++ b/pages/api/discovery/artist/[sellerId]/portfolio.tsx @@ -1,13 +1,14 @@ export default async function handler(req, res ): Promise { const { sellerId } = req.query; var url = process.env.NEXT_PUBLIC_API_URL+`/api/Discovery/Sellers/${sellerId}/Portfolio`; - //console.log(url) + ////console.log(url) const response = await fetch(url); + console.log(response) if (!response.ok) { throw new Error('Failed to fetch seller portfolio'); } var result = await response.json(); - //console.log(result) + ////console.log(result) res.status(200).json(result); } diff --git a/pages/artistDashboard.tsx b/pages/artistDashboard.tsx index 8f75efc..89efe2e 100644 --- a/pages/artistDashboard.tsx +++ b/pages/artistDashboard.tsx @@ -241,7 +241,7 @@ const SellerDashoard = (ctx) => { sx={{ width: '100%' }} /> - +