From e2b0ef1046dd3d4b54e8ed24c96a5513533f3676 Mon Sep 17 00:00:00 2001 From: insvrgent Date: Thu, 6 Feb 2025 02:38:50 +0700 Subject: [PATCH] ok --- src/App.js | 9 +- src/components/AccountUpdatePage.js | 170 +++++++++++++++++------- src/components/Header.js | 16 +-- src/components/Modal.js | 10 +- src/pages/CreateCoupon.js | 195 ++++++++++++++-------------- src/pages/Reports.js | 2 +- 6 files changed, 243 insertions(+), 159 deletions(-) diff --git a/src/App.js b/src/App.js index 5d1e947..37de452 100644 --- a/src/App.js +++ b/src/App.js @@ -412,8 +412,13 @@ function App() { setIsModalOpen(true); setModalContent(content) - if (onCloseFunction) setOnModalCloseFunction(onCloseFunction) - else setOnModalCloseFunction(null) + console.log(onCloseFunction) + + if (onCloseFunction) { + setOnModalCloseFunction(() => onCloseFunction); // Store the close function + } else { + setOnModalCloseFunction(null); + } }; const closeModal = (closeTheseContent = []) => { diff --git a/src/components/AccountUpdatePage.js b/src/components/AccountUpdatePage.js index d4ff45d..f93e9d7 100644 --- a/src/components/AccountUpdatePage.js +++ b/src/components/AccountUpdatePage.js @@ -1,10 +1,10 @@ import React, { useState } from 'react'; -import styles from './AccountUpdatePage.module.css'; // Adjust CSS if needed import { updateUser } from '../helpers/userHelpers'; +import styles from '../pages/Join.module.css'; // Import the module.css file const AccountUpdatePage = ({ user, showEmail, onSubmit }) => { const [formData, setFormData] = useState({ - username: user.username.startsWith('guest') ? '' : user.username || '', + username: user.username || '', email: user.email || '', password: user.password === 'unsetunsetunset' ? '' : user.password || '', }); @@ -12,6 +12,13 @@ const AccountUpdatePage = ({ user, showEmail, onSubmit }) => { const [errorMessage, setErrorMessage] = useState(''); const [successMessage, setSuccessMessage] = useState(''); // New state for success messages + + + const [loading, setLoading] = useState(false); + const [error, setError] = useState(false); + const [wasInputtingPassword, setWasInputtingPassword] = useState(false); + const [inputtingPassword, setInputtingPassword] = useState(false); + const handleChange = (e) => { setFormData({ ...formData, [e.target.name]: e.target.value }); }; @@ -41,55 +48,122 @@ const AccountUpdatePage = ({ user, showEmail, onSubmit }) => { }; return ( -
-

Update Your Account

-
- + +
+
+
Ubah profil
+
+ Daftarkan kedaimu sekarang dan mulai gunakan semua fitur unggulan kami. +
- {showEmail && ( - - )} +
+
+ + + - - - {/* Display success message */} - {successMessage &&
{successMessage}
} - - {/* Display error message */} - {errorMessage &&
{errorMessage}
} - - - + +
+ +
+ + + + + + + + +
+
+
+
+ //
+ //

Update Your Account

+ //
+ // + + // {showEmail && ( + // + // )} + + // + + // {/* Display success message */} + // {successMessage &&
{successMessage}
} + + // {/* Display error message */} + // {errorMessage &&
{errorMessage}
} + + // + //
+ //
); }; diff --git a/src/components/Header.js b/src/components/Header.js index dff8c18..2ba31c0 100644 --- a/src/components/Header.js +++ b/src/components/Header.js @@ -346,6 +346,14 @@ const Header = ({ <> {shopName} + + Mode pengembangan   + setIsEditMode(!isEditMode)} + /> + setModal("reports")}>Lihat laporan setModal("add_material")}> Kelola bahan baku @@ -384,14 +392,6 @@ const Header = ({ Metode pembayaran - - Mode pengembangan   - setIsEditMode(!isEditMode)} - /> - )} diff --git a/src/components/Modal.js b/src/components/Modal.js index 6655c0e..e5d749a 100644 --- a/src/components/Modal.js +++ b/src/components/Modal.js @@ -47,12 +47,16 @@ const Modal = ({ user, shop, isOpen, onClose, modalContent, setModal, handleMove if (!isOpen) return null; // Function to handle clicks on the overlay + const handleOverlayClick = (event) => { - // Close the modal only if the overlay is clicked - onModalCloseFunction(); - onClose(); + console.log(onModalCloseFunction) + if (onModalCloseFunction) { + onModalCloseFunction(); // Execute the passed closure + } + onClose(); // Close the modal }; + // Function to handle clicks on the modal content const handleContentClick = (event) => { // Prevent click event from propagating to the overlay diff --git a/src/pages/CreateCoupon.js b/src/pages/CreateCoupon.js index a21f12b..6dfd5a6 100644 --- a/src/pages/CreateCoupon.js +++ b/src/pages/CreateCoupon.js @@ -3,37 +3,37 @@ import styles from './Join.module.css'; import Coupon from '../components/Coupon'; import CryptoJS from 'crypto-js'; -import {createCoupon} from "../helpers/couponHelpers.js" +import { createCoupon } from "../helpers/couponHelpers.js" function getAuthToken() { - return localStorage.getItem("auth"); - } + return localStorage.getItem("auth"); +} const CreateCouponPage = () => { const [discountType, setDiscountType] = useState("percentage"); const [discountValue, setDiscountValue] = useState(""); const [discountPeriods, setDiscountPeriods] = useState(""); const [couponDetails, setCouponDetails] = useState(null); - - const [loading, setLoading] = useState(false); - const [error, setError] = useState(false); - const [wasInputtingPassword, setWasInputtingPassword] = useState(false); - const [inputtingPassword, setInputtingPassword] = useState(false); - const [username, setUsername] = useState(''); - const [email, setEmail] = useState(''); - const [password, setPassword] = useState(''); - const [retypePassword, setRetypePassword] = useState(''); - const [codeExpectation, setCodeExpectation] = useState(''); - const [couponUrl, setCouponUrl] = useState(''); - + + const [loading, setLoading] = useState(false); + const [error, setError] = useState(false); + const [wasInputtingPassword, setWasInputtingPassword] = useState(false); + const [inputtingPassword, setInputtingPassword] = useState(false); + const [username, setUsername] = useState(''); + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + const [retypePassword, setRetypePassword] = useState(''); + const [codeExpectation, setCodeExpectation] = useState(''); + const [couponUrl, setCouponUrl] = useState(''); + const handleSubmit = async (e) => { e.preventDefault(); setLoading(true); - + // Call the helper function to create the coupon const result = await createCoupon(discountType, discountValue, discountPeriods, codeExpectation); - + if (result.success) { setCouponDetails(result.coupon); const secretKey = 'xixixi666'; // Your AES-256 key (32 characters) @@ -57,87 +57,88 @@ const CreateCouponPage = () => {
{couponDetails != null ? - <> - - + <> + + - : -
-
- - - - setDiscountValue(e.target.value)} - className={!error ? styles.usernameInput : styles.usernameInputError} - /> - -
- -
- - - - - - setDiscountPeriods(e.target.value)} - maxLength="30" - className={!error ? styles.usernameInput : styles.usernameInputError} - /> - setCodeExpectation(e.target.value)} - maxLength="30" - className={!error ? styles.usernameInput : styles.usernameInputError} - /> - -
-
+ : +
+
+ + + + setDiscountValue(e.target.value)} + className={!error ? styles.usernameInput : styles.usernameInputError} + /> + +
+ +
+ + + + + + setDiscountPeriods(e.target.value)} + maxLength="30" + className={!error ? styles.usernameInput : styles.usernameInputError} + /> + setCodeExpectation(e.target.value)} + maxLength="30" + className={!error ? styles.usernameInput : styles.usernameInputError} + /> + +
+
} diff --git a/src/pages/Reports.js b/src/pages/Reports.js index 09bec47..3613dd4 100644 --- a/src/pages/Reports.js +++ b/src/pages/Reports.js @@ -387,7 +387,7 @@ const App = ({ forCafe = true, cafeId = -1, if (selectedItem) { setSelectedCafeId(selectedItem[1]); // Get the cafeId (second part of the pair) } - if(selectedItem[1] == -1 && user.roleId == 0) setModal('create_coupon',{},setSelectedCafeId(0)); + if(selectedItem[1] == -1 && user.roleId == 0) setModal('create_coupon', {}, () => {setSelectedSwitch(0);setSelectedCafeId(0)}); setResetKey((prevKey) => prevKey + 1); // Increase the key to force re-render };