This commit is contained in:
insvrgent
2025-02-06 02:38:50 +07:00
parent 556c7337eb
commit e2b0ef1046
6 changed files with 243 additions and 159 deletions

View File

@@ -412,8 +412,13 @@ function App() {
setIsModalOpen(true); setIsModalOpen(true);
setModalContent(content) setModalContent(content)
if (onCloseFunction) setOnModalCloseFunction(onCloseFunction) console.log(onCloseFunction)
else setOnModalCloseFunction(null)
if (onCloseFunction) {
setOnModalCloseFunction(() => onCloseFunction); // Store the close function
} else {
setOnModalCloseFunction(null);
}
}; };
const closeModal = (closeTheseContent = []) => { const closeModal = (closeTheseContent = []) => {

View File

@@ -1,10 +1,10 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import styles from './AccountUpdatePage.module.css'; // Adjust CSS if needed
import { updateUser } from '../helpers/userHelpers'; import { updateUser } from '../helpers/userHelpers';
import styles from '../pages/Join.module.css'; // Import the module.css file
const AccountUpdatePage = ({ user, showEmail, onSubmit }) => { const AccountUpdatePage = ({ user, showEmail, onSubmit }) => {
const [formData, setFormData] = useState({ const [formData, setFormData] = useState({
username: user.username.startsWith('guest') ? '' : user.username || '', username: user.username || '',
email: user.email || '', email: user.email || '',
password: user.password === 'unsetunsetunset' ? '' : user.password || '', password: user.password === 'unsetunsetunset' ? '' : user.password || '',
}); });
@@ -12,6 +12,13 @@ const AccountUpdatePage = ({ user, showEmail, onSubmit }) => {
const [errorMessage, setErrorMessage] = useState(''); const [errorMessage, setErrorMessage] = useState('');
const [successMessage, setSuccessMessage] = useState(''); // New state for success messages 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) => { const handleChange = (e) => {
setFormData({ ...formData, [e.target.name]: e.target.value }); setFormData({ ...formData, [e.target.name]: e.target.value });
}; };
@@ -41,55 +48,122 @@ const AccountUpdatePage = ({ user, showEmail, onSubmit }) => {
}; };
return ( return (
<div className={styles.container}>
<h2>Update Your Account</h2>
<form onSubmit={handleSubmit} className={styles.form}>
<label className={styles.formLabel}>
Username:
<input
type="text"
name="username"
value={formData.username}
onChange={handleChange}
className={styles.formInput}
/>
</label>
{showEmail && ( <div className={styles.linktreePage}>
<label className={styles.formLabel}> <div className={styles.dashboardContainer}>
Email: <div className={styles.mainHeading}>Ubah profil</div>
<input <div className={styles.subHeadingTransparent}>
type="email" Daftarkan kedaimu sekarang dan mulai gunakan semua fitur unggulan kami.
name="email" </div>
value={formData.email}
onChange={handleChange}
className={styles.formInput}
/>
</label>
)}
<label className={styles.formLabel}> <div className={styles.LoginForm}>
Password: <div className={`${styles.FormUsername} ${inputtingPassword ? styles.animateForm : wasInputtingPassword ? styles.reverseForm : ''}`}>
<input <label htmlFor="username" className={styles.usernameLabel}>----------------------------------------------</label>
type="password"
name="password"
value={formData.password}
onChange={handleChange}
className={styles.formInput}
/>
</label>
{/* Display success message */} <input
{successMessage && <div className={styles.successMessage}>{successMessage}</div>} name="username"
type="text"
placeholder="Username"
value={formData.username}
onChange={handleChange}
className={!error ? styles.usernameInput : styles.usernameInputError}
/>
{/* Display error message */} <input
{errorMessage && <div className={styles.errorMessage}>{errorMessage}</div>} name="email"
type="number"
<button type="submit" className={styles.submitButton}> placeholder="Email"
Submit value={formData.email}
</button> onChange={handleChange}
</form> className={!error ? styles.usernameInput : styles.usernameInputError}
/>
<button onClick={() => { setInputtingPassword(true); setWasInputtingPassword(true); }} className={styles.claimButton}>
<span></span>
</button>
</div> </div>
<div className={`${styles.FormPassword} ${inputtingPassword ? styles.animateForm : wasInputtingPassword ? styles.reverseForm : ''}`}>
<span>
<label onClick={() => setInputtingPassword(false)} htmlFor="password" className={styles.usernameLabel}> &lt;--- &lt;-- kembali </label>
<label htmlFor="password" className={styles.usernameLabel}> &nbsp; ------------------------- &nbsp; </label>
</span>
<input
name="password"
type="password"
placeholder="Ganti password"
onChange={handleChange}
maxLength="30"
className={!error ? styles.usernameInput : styles.usernameInputError}
/>
<input
name="password"
type="password"
placeholder="Ulangi password"
onChange={handleChange}
maxLength="30"
className={!error ? styles.usernameInput : styles.usernameInputError}
/>
<button
onClick={handleSubmit}
className={`${styles.claimButton} ${loading ? styles.loading : ''}`}
disabled={loading}
>
<span>{loading ? 'Loading...' : 'Simpan'}</span>
</button>
</div>
</div>
</div>
</div>
// <div className={styles.container}>
// <h2>Update Your Account</h2>
// <form onSubmit={handleSubmit} className={styles.form}>
// <label className={styles.formLabel}>
// Username:
// <input
// type="text"
// name="username"
// value={formData.username}
// onChange={handleChange}
// className={styles.formInput}
// />
// </label>
// {showEmail && (
// <label className={styles.formLabel}>
// Email:
// <input
// type="email"
// name="email"
// value={formData.email}
// onChange={handleChange}
// className={styles.formInput}
// />
// </label>
// )}
// <label className={styles.formLabel}>
// Password:
// <input
// type="password"
// name="password"
// value={formData.password}
// onChange={handleChange}
// className={styles.formInput}
// />
// </label>
// {/* Display success message */}
// {successMessage && <div className={styles.successMessage}>{successMessage}</div>}
// {/* Display error message */}
// {errorMessage && <div className={styles.errorMessage}>{errorMessage}</div>}
// <button type="submit" className={styles.submitButton}>
// Submit
// </button>
// </form>
// </div>
); );
}; };

View File

@@ -346,6 +346,14 @@ const Header = ({
<> <>
<Child hasChildren> <Child hasChildren>
{shopName} {shopName}
<Child>
Mode pengembangan &nbsp;
<Switch
borderRadius={0}
checked={isEditMode}
onChange={() => setIsEditMode(!isEditMode)}
/>
</Child>
<Child onClick={() => setModal("reports")}>Lihat laporan</Child> <Child onClick={() => setModal("reports")}>Lihat laporan</Child>
<Child onClick={() => setModal("add_material")}> <Child onClick={() => setModal("add_material")}>
Kelola bahan baku Kelola bahan baku
@@ -384,14 +392,6 @@ const Header = ({
Metode pembayaran Metode pembayaran
</Child> </Child>
</Child> </Child>
<Child>
Mode pengembangan &nbsp;
<Switch
borderRadius={0}
checked={isEditMode}
onChange={() => setIsEditMode(!isEditMode)}
/>
</Child>
</Child> </Child>
</> </>
)} )}

View File

@@ -47,12 +47,16 @@ const Modal = ({ user, shop, isOpen, onClose, modalContent, setModal, handleMove
if (!isOpen) return null; if (!isOpen) return null;
// Function to handle clicks on the overlay // Function to handle clicks on the overlay
const handleOverlayClick = (event) => { const handleOverlayClick = (event) => {
// Close the modal only if the overlay is clicked console.log(onModalCloseFunction)
onModalCloseFunction(); if (onModalCloseFunction) {
onClose(); onModalCloseFunction(); // Execute the passed closure
}
onClose(); // Close the modal
}; };
// Function to handle clicks on the modal content // Function to handle clicks on the modal content
const handleContentClick = (event) => { const handleContentClick = (event) => {
// Prevent click event from propagating to the overlay // Prevent click event from propagating to the overlay

View File

@@ -3,11 +3,11 @@ import styles from './Join.module.css';
import Coupon from '../components/Coupon'; import Coupon from '../components/Coupon';
import CryptoJS from 'crypto-js'; import CryptoJS from 'crypto-js';
import {createCoupon} from "../helpers/couponHelpers.js" import { createCoupon } from "../helpers/couponHelpers.js"
function getAuthToken() { function getAuthToken() {
return localStorage.getItem("auth"); return localStorage.getItem("auth");
} }
const CreateCouponPage = () => { const CreateCouponPage = () => {
const [discountType, setDiscountType] = useState("percentage"); const [discountType, setDiscountType] = useState("percentage");
const [discountValue, setDiscountValue] = useState(""); const [discountValue, setDiscountValue] = useState("");
@@ -15,16 +15,16 @@ const CreateCouponPage = () => {
const [couponDetails, setCouponDetails] = useState(null); const [couponDetails, setCouponDetails] = useState(null);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [error, setError] = useState(false); const [error, setError] = useState(false);
const [wasInputtingPassword, setWasInputtingPassword] = useState(false); const [wasInputtingPassword, setWasInputtingPassword] = useState(false);
const [inputtingPassword, setInputtingPassword] = useState(false); const [inputtingPassword, setInputtingPassword] = useState(false);
const [username, setUsername] = useState(''); const [username, setUsername] = useState('');
const [email, setEmail] = useState(''); const [email, setEmail] = useState('');
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
const [retypePassword, setRetypePassword] = useState(''); const [retypePassword, setRetypePassword] = useState('');
const [codeExpectation, setCodeExpectation] = useState(''); const [codeExpectation, setCodeExpectation] = useState('');
const [couponUrl, setCouponUrl] = useState(''); const [couponUrl, setCouponUrl] = useState('');
const handleSubmit = async (e) => { const handleSubmit = async (e) => {
@@ -57,87 +57,88 @@ const CreateCouponPage = () => {
</div> </div>
{couponDetails != null ? {couponDetails != null ?
<> <>
<Coupon <Coupon
code={couponDetails?.code || null} code={couponDetails?.code || null}
value={couponDetails?.discountValue} value={couponDetails?.discountValue}
period={couponDetails?.discountPeriods} period={couponDetails?.discountPeriods}
type={couponDetails?.type} type={couponDetails?.type}
expiration={couponDetails?.expirationDate} expiration={couponDetails?.expirationDate}
/>
<button
onClick={() => {
navigator.clipboard.writeText('https://dev.coupon.kedaimaster.com/coupon?c=' + couponUrl)
.then(() => {
// Optional: Show a message that the text has been copied
alert("Coupon URL copied to clipboard!");
})
.catch((err) => {
console.error("Failed to copy text: ", err);
});
}}
className={styles.claimButton}
style={{ marginBottom: '10px' }}
>
<span>Salin URL VOUCHER</span>
</button></>
:
<div className={styles.LoginForm}>
<div className={`${styles.FormUsername} ${inputtingPassword ? styles.animateForm : wasInputtingPassword ? styles.reverseForm : ''}`}>
<label htmlFor="username" className={styles.usernameLabel}>----------------------------------------------</label>
<select
className={!error ? styles.usernameInput : styles.usernameInputError}
value={discountType}
onChange={(e) => setDiscountType(e.target.value)}
style={{width: '100%'}}
>
<option value="percentage">Percentage</option>
<option value="fixed">Fixed</option>
</select>
<input
type="number"
placeholder="Nilai voucher"
value={discountValue}
onChange={(e) => setDiscountValue(e.target.value)}
className={!error ? styles.usernameInput : styles.usernameInputError}
/>
<button onClick={() => { setInputtingPassword(true); setWasInputtingPassword(true); }} className={styles.claimButton}>
<span></span>
</button>
</div>
<div className={`${styles.FormPassword} ${inputtingPassword ? styles.animateForm : wasInputtingPassword ? styles.reverseForm : ''}`}>
<span>
<label onClick={() => setInputtingPassword(false)} htmlFor="password" className={styles.usernameLabel}> &lt;--- &lt;-- kembali </label>
<label htmlFor="password" className={styles.usernameLabel}> &nbsp; ----------------- &nbsp; </label>
</span>
<input
type="number"
placeholder="Periode diskon (minggu)"
value={discountPeriods}
onChange={(e) => setDiscountPeriods(e.target.value)}
maxLength="30"
className={!error ? styles.usernameInput : styles.usernameInputError}
/>
<input
type="text"
placeholder="Ekspektasi kode"
value={codeExpectation}
onChange={(e) => setCodeExpectation(e.target.value)}
maxLength="30"
className={!error ? styles.usernameInput : styles.usernameInputError}
/> />
<button <button
onClick={() => { onClick={handleSubmit}
navigator.clipboard.writeText('https://dev.coupon.kedaimaster.com/coupon?c=' + couponUrl) className={`${styles.claimButton} ${loading ? styles.loading : ''}`}
.then(() => { disabled={loading}
// Optional: Show a message that the text has been copied >
alert("Coupon URL copied to clipboard!"); <span>{loading ? 'Loading...' : 'Buat'}</span>
}) </button>
.catch((err) => { </div>
console.error("Failed to copy text: ", err); </div>
});
}}
className={styles.claimButton}
style={{marginBottom: '10px'}}
>
<span>Salin URL VOUCHER</span>
</button></>
:
<div className={styles.LoginForm}>
<div className={`${styles.FormUsername} ${inputtingPassword ? styles.animateForm : wasInputtingPassword ? styles.reverseForm : ''}`}>
<label htmlFor="username" className={styles.usernameLabel}>---- Daftar -------------------------------</label>
<select
className={!error ? styles.usernameInput : styles.usernameInputError}
value={discountType}
onChange={(e) => setDiscountType(e.target.value)}
>
<option value="percentage">Percentage</option>
<option value="fixed">Fixed</option>
</select>
<input
type="number"
placeholder="Nilai voucher"
value={discountValue}
onChange={(e) => setDiscountValue(e.target.value)}
className={!error ? styles.usernameInput : styles.usernameInputError}
/>
<button onClick={() => { setInputtingPassword(true); setWasInputtingPassword(true); }} className={styles.claimButton}>
<span></span>
</button>
</div>
<div className={`${styles.FormPassword} ${inputtingPassword ? styles.animateForm : wasInputtingPassword ? styles.reverseForm : ''}`}>
<span>
<label onClick={() => setInputtingPassword(false)} htmlFor="password" className={styles.usernameLabel}> &lt;--- &lt;-- kembali </label>
<label htmlFor="password" className={styles.usernameLabel}> &nbsp; ----------------- &nbsp; </label>
</span>
<input
type="number"
placeholder="Periode diskon (minggu)"
value={discountPeriods}
onChange={(e) => setDiscountPeriods(e.target.value)}
maxLength="30"
className={!error ? styles.usernameInput : styles.usernameInputError}
/>
<input
type="text"
placeholder="Ekspektasi kode"
value={codeExpectation}
onChange={(e) => setCodeExpectation(e.target.value)}
maxLength="30"
className={!error ? styles.usernameInput : styles.usernameInputError}
/>
<button
onClick={handleSubmit}
className={`${styles.claimButton} ${loading ? styles.loading : ''}`}
disabled={loading}
>
<span>{loading ? 'Loading...' : 'Buat'}</span>
</button>
</div>
</div>
} }
</div> </div>
</div> </div>

View File

@@ -387,7 +387,7 @@ const App = ({ forCafe = true, cafeId = -1,
if (selectedItem) { if (selectedItem) {
setSelectedCafeId(selectedItem[1]); // Get the cafeId (second part of the pair) 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 setResetKey((prevKey) => prevKey + 1); // Increase the key to force re-render
}; };