diff --git a/src/components/ItemConfig.js b/src/components/ItemConfig.js
index da44dba..4e9ac51 100644
--- a/src/components/ItemConfig.js
+++ b/src/components/ItemConfig.js
@@ -2,14 +2,28 @@ import React, { useState, useEffect, useRef } from "react";
import styles from "./Modal.module.css";
import { getImageUrl } from "../helpers/itemHelper.js";
-const ItemConfig = ({ Item, cancelEdit }) => {
- const [selectedImage, setSelectedImage] = useState(null);
- const [previewUrl, setPreviewUrl] = useState(Item.image);
+const ItemConfig = ({
+ name: initialName,
+ description: initialDescription,
+ price: initialPrice,
+ promoPrice: initialPromoPrice,
+ imageUrl,
+ imageFile,
+ isBeingEdit,
+ cancelEdit,
+ handleCreateItem,
+ handleUpdateItem
+}) => {
+ const [selectedImage, setSelectedImage] = useState(imageFile);
+ const [previewUrl, setPreviewUrl] = useState(imageUrl);
+ const [itemName, setItemName] = useState(initialName);
+ const [itemPrice, setItemPrice] = useState(initialPrice);
+ const [itemPromoPrice, setItemPromoPrice] = useState(initialPromoPrice);
+ const [itemDescription, setItemDescription] = useState(initialDescription);
const fileInputRef = useRef(null);
-
+ const textareaRef = useRef(null);
useEffect(() => {
- console.log(Item.image)
// Prevent scrolling when modal is open
document.body.style.overflow = "hidden";
@@ -21,10 +35,9 @@ const ItemConfig = ({ Item, cancelEdit }) => {
};
reader.readAsDataURL(selectedImage);
} else {
- setPreviewUrl(Item.image);
+ setPreviewUrl(imageUrl);
}
- }, [selectedImage, Item]);
-
+ }, [selectedImage, imageUrl]);
const handleOverlayClick = (event) => {
// Prevent scrolling when modal is open
@@ -32,19 +45,15 @@ const ItemConfig = ({ Item, cancelEdit }) => {
cancelEdit();
};
-
- // Function to handle clicks on the modal content
const handleContentClick = (event) => {
// Prevent click event from propagating to the overlay
event.stopPropagation();
};
-
const handleChangeImage = () => {
fileInputRef.current.click();
};
-
const handleFileChange = (event) => {
const file = event.target.files[0];
if (file) {
@@ -52,13 +61,35 @@ const ItemConfig = ({ Item, cancelEdit }) => {
}
};
- return (
-
-
-
-
-

+ useEffect(() => {
+ const textarea = textareaRef.current;
+ if (textarea) {
+ const handleResize = () => {
+ textarea.style.height = "auto";
+ textarea.style.height = `${textarea.scrollHeight}px`;
+ };
+
+ handleResize(); // Initial resize
+
+ textarea.addEventListener("input", handleResize);
+ return () => textarea.removeEventListener("input", handleResize);
+ }
+ }, [textareaRef.current]);
+
+ const handleCreate = () => {
+ handleCreateItem(itemName, itemPrice, selectedImage, previewUrl);
+ };
+ const handleUpdate = () => {
+ handleUpdateItem(itemName, itemPrice, selectedImage, previewUrl);
+ };
+
+ return (
+
+
+
+
-
handleChangeImage()} style={{ width: '140px', height: '40px', alignContent: 'center', textAlign: 'center', borderRadius: '10px', border: '1px solid #60d37e', color: '#60d37e', backgroundColor: 'white' }}>
- Ganti gambar
+
handleChangeImage()} style={{ width: '140px', height: '40px', alignContent: 'center', textAlign: 'center', borderRadius: '10px', border: '1px solid #60d37e', color: '#60d37e', backgroundColor: 'white', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
+ {isBeingEdit ? 'Ganti gambar' : 'Tambah gambar'}
-
-
Nama item
-
+
+
+
Nama item
+
setItemName(e.target.value)}
+ onFocus={(e) => e.target.style.borderColor = '#60d37e'}
+ onBlur={(e) => e.target.style.borderColor = '#ccc'}
+ />
+
-
-
Harga promo
-
+
+
Harga
+
setItemPrice(e.target.value)}
+ onFocus={(e) => e.target.style.borderColor = '#60d37e'}
+ onBlur={(e) => e.target.style.borderColor = '#ccc'}
+ />
+
+
+
Harga promo
+
setItemPromoPrice(e.target.value)}
+ onFocus={(e) => e.target.style.borderColor = '#60d37e'}
+ onBlur={(e) => e.target.style.borderColor = '#ccc'}
+ />
+
-
Deskripsi
-
+
Deskripsi
+
+
+
+
+
{isBeingEdit ? handleUpdate() : handleCreate()} } style={{ width: '100%', height: '40px', alignContent: 'center', textAlign: 'center', borderRadius: '10px', border: '1px solid #60d37e', color: '#60d37e', backgroundColor: 'white', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
+ {isBeingEdit? 'Simpan' : 'Buat Item'}
+
diff --git a/src/components/ItemConfig.module.css b/src/components/ItemConfig.module.css
new file mode 100644
index 0000000..09ebce5
--- /dev/null
+++ b/src/components/ItemConfig.module.css
@@ -0,0 +1,101 @@
+/* Modal.module.css */
+
+.overlay {
+ position: fixed;
+ width: 100vw;
+ height: 100vh;
+ left: 0;
+ bottom: 0;
+ display: flex;
+ flex-direction: column-reverse;
+ z-index: 200;
+ background-color: rgba(0, 0, 0, 0.38); /* #00000061 */
+}
+
+.content {
+ display: flex;
+ flex-direction: column;
+ padding: 15px;
+ height: 40%;
+ background-color: white;
+ border-radius: 20px 20px 0 0;
+ overflow-y: auto;
+}
+
+.imageContainer {
+ display: flex;
+}
+
+.image {
+ width: 26vw;
+ height: 26vw;
+ margin-right: 10px;
+}
+
+.imagePreview {
+ width: 100%;
+ height: 100%;
+ border-radius: 10px;
+ object-fit: cover;
+}
+
+.changeImageButton {
+ width: 140px;
+ height: 40px;
+ align-content: center;
+ text-align: center;
+ border-radius: 10px;
+ border: 1px solid #60d37e;
+ color: #60d37e;
+ background-color: white;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+}
+
+.inputField {
+ padding: 10px;
+ border-radius: 8px;
+ border: 1px solid #ccc;
+ font-size: 14px;
+ width: 100%;
+ margin-bottom: 15px;
+ outline: none;
+ transition: all 0.3s ease;
+ box-sizing: border-box;
+}
+
+.inputField:focus {
+ border-color: #60d37e;
+}
+
+.inputField:blur {
+ border-color: #ccc;
+}
+
+.textarea {
+ padding: 10px;
+ border-radius: 8px;
+ border: 1px solid #ccc;
+ font-size: 14px;
+ width: 100%;
+ margin-bottom: 15px;
+ outline: none;
+ transition: all 0.3s ease;
+ box-sizing: border-box;
+ resize: none; /* Prevent manual resize that could cause overflow */
+}
+
+.saveButton {
+ width: 100%;
+ height: 40px;
+ align-content: center;
+ text-align: center;
+ border-radius: 10px;
+ border: 1px solid #60d37e;
+ color: #60d37e;
+ background-color: white;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+}
\ No newline at end of file
diff --git a/src/components/ItemLister.js b/src/components/ItemLister.js
index af5d748..89d75ca 100644
--- a/src/components/ItemLister.js
+++ b/src/components/ItemLister.js
@@ -70,6 +70,9 @@ const ItemLister = ({
const [isFirstStep, setIsFirstStep] = useState(true);
+
+ const [randomKey, setRandomKey] = useState(0);
+
const handlePlusClick = (itemId) => {
const updatedItems = items.map((item) => {
if (item.itemId === itemId) {
@@ -220,7 +223,41 @@ const ItemLister = ({
const onUpdateItem = (itemId, name, price, image) => {
if (isEdit)
setItemsToUpdate((prev) => [...prev, { itemId, name, price, image }]);
- else handleUpdateItem(itemId, name, price, image);
+ else {
+ console.log(itemId, name, price, image)
+ handleUpdateItem(itemId, name, price, image);
+
+ const itemIndex = items.findIndex((item) => item.itemId === itemId);
+ if (itemIndex === -1) return; // Item not found
+
+ // Create a copy of the current items array
+ const updatedItems = [...items];
+ const item = updatedItems[itemIndex];
+ console.log(updatedItems)
+ // Toggle the availability locally
+ if(image){
+ const reader = new FileReader();
+ reader.onloadend = () => {
+ updatedItems[itemIndex].image = reader.result;
+ console.log(reader.result)
+ };
+ reader.readAsDataURL(image);
+
+
+ }
+ const newAvailability = !item.availability;
+ updatedItems[itemIndex] = {
+ name,
+ price,
+ availability: item.availability
+ };
+ console.log(updatedItems)
+
+ // Update the state with the local change
+ setItems(updatedItems);
+ setRandomKey(randomKey + 1);
+
+ }
console.log(itemsToUpdate);
};
@@ -779,13 +816,10 @@ const ItemLister = ({
)}
{isAddingNewItem && (
<>
-
+
toggleAddNewItem()}
+ handleCreateItem={onCreateItem}
+ />
>
)}
@@ -796,54 +830,65 @@ const ItemLister = ({
return !forCart || (forCart && item.qty > 0) ? (
<>
{isEditItem == item.itemId && (
-
+ editItem(0)}
+ handleUpdateItem={(name, price, image) => { updateItemInCreate(item.itemId, name, price, image); setRandomKey(randomKey + 1); console.log(image) }
+ }
+ />
)}
{isEditMode && isEditItem != item.itemId && (
+
- {isEditMode && (
-
handleChange(item.itemId)}
- checked={item.availability}
- />
- )}
-
- {item.availability ? "Tersedia" : "Tidak tersedia"}
-
- editItem(item.itemId)}
- >
-
+
+ editItem(item.itemId)} style={{ display: 'flex', alignItems: 'center', height: '40px', marginRight: '7.5vw' }}>
+
-
-
-
-
-
-
-
+
+
+
Edit item
)}
@@ -873,7 +918,8 @@ const ItemLister = ({
{items.map((item) => {
return !forCart || (forCart && item.qty > 0) ? (
- <>
+
{isEditItem == item.itemId && (
//
-
editItem(0)}/>
+ editItem(0)}
+ handleCreateItem={onCreateItem}
+ handleUpdateItem={(name, price, image) => {
+ onUpdateItem(item.itemId, name, price, image);
+ setRandomKey(randomKey + 1); console.log(image);
+ }
+ }
+ />
)}
{isEditMode && isEditItem != item.itemId && (
@@ -953,7 +1015,7 @@ const ItemLister = ({
}
/>
- >
+
) : null;
})}