Skip to content

Commit

Permalink
image preview okay, still need to figure out displaying seller's name…
Browse files Browse the repository at this point in the history
… and duplicate id 'error'
  • Loading branch information
Six5pAdes committed Oct 11, 2024
1 parent c3b70af commit 7d84429
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
33 changes: 27 additions & 6 deletions react-vite/src/components/ProductPages/ProductForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,48 @@
margin-bottom: 20px;
}

.product-inputs {
.product-inputs {
width: 100%;
margin: 10px;
margin-bottom: 20px;
padding: 10px;
border: 1px #ccc solid;
}
}

input[type="file"],
textarea {
input[type="file"],
textarea {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px;
}
}

.product-image::-webkit-file-upload-button {
.image-input-contain {
display: flex;
align-items: center;
}

.product-image {
/* height: 100px;
color: transparent;
text-indent: 10px;
background-color: rgba(255, 255, 255, 0.8); */
flex: 1;
margin-right: 10px;
}

.product-image::-webkit-file-upload-button {
cursor: pointer;
}

.image-preview {
width: fit-content;
height: 100px;
object-fit: cover;
border-radius: 50px;
}

#button-contain {
display: flex;
justify-content: space-evenly;
Expand Down
28 changes: 21 additions & 7 deletions react-vite/src/components/ProductPages/ProductForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const CreateProduct = () => {
const [submit, setSubmit] = useState(false)
const user = useSelector(state => state.session.user)

const [imagePreview, setImagePreview] = useState("")

const handleSubmit = async e => {
e.preventDefault()
setSubmit(true)
Expand Down Expand Up @@ -78,6 +80,14 @@ const CreateProduct = () => {
navigate(-1)
}

const handleImageChange = (e) => {
const file = e.target.files[0]
setImage(file)
if (file) {
setImagePreview(URL.createObjectURL(file))
}
}

return (
<div id="product-new">
<h1>Create a New Product</h1>
Expand All @@ -99,12 +109,16 @@ const CreateProduct = () => {
{submit && errors.name && <p className="err-msg">{errors.name}</p>}
<label className="product-label">
Image
<input
type="file"
className="product-inputs product-image"
accept="image/*"
onChange={(e) => setImage(e.target.files[0])}
/>
<div className="image-input-contain">
<input
type="file"
className="product-inputs product-image"
accept="image/*"
onChange={handleImageChange}
// style={{ backgroundImage: imagePreview ? `url(${imagePreview})` : 'none', backgroundSize: 'contain', backgroundRepeat: 'no-repeat' }}
/>
{imagePreview && <img src={imagePreview} className="image-preview" />}
</div>
</label>
{submit && errors.image && <p className="err-msg">{errors.image}</p>}
<label className="product-label">
Expand Down Expand Up @@ -138,7 +152,7 @@ const CreateProduct = () => {
Description
<textarea
className="product-inputs"
placeholder="Please describe what the item is"
placeholder="Please describe what the item is..."
value={description}
onChange={(e) => setDescription(e.target.value)}
/>
Expand Down
10 changes: 5 additions & 5 deletions react-vite/src/components/ProductPages/SingleProduct.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ const ProductDetails = () => {
}
}, [wishlists, product])

const allSellers = session.users
const seller = allSellers?.find(user => user.id === product?.user_id)
// const allSellers = session.users
// const seller = allSellers?.find(user => user.id === product?.user_id)

const handleAddToCart = (prodId) => {
const orderIds = allCarts.map(ele => ele.product_id)
Expand Down Expand Up @@ -131,9 +131,9 @@ const ProductDetails = () => {
<p className="price">
Price: ${parseFloat(product?.price).toFixed(2)}
</p>
<p className="seller">
Seller: {seller?.first_name} {seller?.last_name}
</p>
{/* <p className="seller">
Seller: {seller ? `${seller.first_name} ${seller.last_name}` : "Unknown Seller"}
</p> */}
<div className="actions">
{session.user && product.user_id !== session.user.id && (
<>
Expand Down

0 comments on commit 7d84429

Please sign in to comment.