diff --git a/src/App.js b/src/App.js
index 74cb1eb..63490b2 100644
--- a/src/App.js
+++ b/src/App.js
@@ -211,7 +211,7 @@ function App() {
// Check current permission
const searchParams = new URLSearchParams(location.search);
let searchModal = searchParams.get("modal") || ''; // Get transactionId or set it to empty string
-
+
if (permission !== "granted" && searchModal == '') {
setModal("req_notification");
}
@@ -275,9 +275,9 @@ function App() {
socket.off("signout-guest-session");
};
}, [socket, shopId]);
-
- async function checkIfStillViewingOtherTransaction(){
-
+
+ async function checkIfStillViewingOtherTransaction() {
+
console.log("transaction notification");
console.log(modalContent);
@@ -285,7 +285,7 @@ function App() {
response = await getTransactionsFromCafe(shopId, 0, true);
transactionList.current = response;
console.log(response);
-
+
// Get current URL's search parameters inside the socket event handler
const searchParams = new URLSearchParams(location.search);
let transaction_info = searchParams.get("transactionId") || ''; // Get transactionId or set it to empty string
@@ -305,7 +305,7 @@ function App() {
if (!isViewingOtherTransaction) {
setModal("new_transaction", data);
}
-
+
// Show browser notification
let permission = Notification.permission;
if (permission !== "granted") return;
@@ -316,14 +316,14 @@ function App() {
});
});
});
-
+
socket.on("transaction_canceled", async (data) => {
console.log("transaction notification");
-
+
const isViewingOtherTransaction = await checkIfStillViewingOtherTransaction();
// If transaction_info is an empty string, set the modal
if (!isViewingOtherTransaction) {
- setModal("new_transaction", data);
+ setModal("new_transaction", data);
}
});
@@ -333,7 +333,7 @@ function App() {
socket.off("transaction_canceled");
};
}, [socket, shopId, location]); // Ensure location is in the dependencies to respond to changes in the URL
-
+
useEffect(() => {
if (user.cafeId != null && user.cafeId !== shopId) {
// Preserve existing query parameters
@@ -344,14 +344,14 @@ function App() {
}
}, [user, shopId]);
-
+
function handleMoveToTransaction(direction, from) {
console.log(direction);
console.log(from);
// Find the current index based on the 'from' transactionId
const currentIndex = transactionList.current.findIndex(item => item.transactionId == from);
-
+
// Determine the new transactionId based on the direction
let newTransactionId;
if (direction === 'next') {
@@ -365,18 +365,18 @@ function App() {
? transactionList.current[currentIndex - 1].transactionId
: from; // If already at the beginning, stay on the current transactionId
}
-
+
// Log the new transactionId
console.log('New Transaction ID:', newTransactionId);
-
+
// Update the URL with the new transactionId using navigate
navigate(`?transactionId=${newTransactionId}`, { replace: true });
-
+
// Optionally, update state or perform further actions based on the new transactionId
// Example:
// setModalContent({ cafeId: shopId, transactionId: newTransactionId });
}
-
+
const handleModalFromURL = () => {
const queryParams = new URLSearchParams(location.search);
@@ -651,11 +651,12 @@ function App() {
diff --git a/src/components/AccountUpdatePage.js b/src/components/AccountUpdatePage.js
index 5b30a7c..d4ff45d 100644
--- a/src/components/AccountUpdatePage.js
+++ b/src/components/AccountUpdatePage.js
@@ -1,4 +1,3 @@
-// src/components/AccountUpdatePage.js
import React, { useState } from 'react';
import styles from './AccountUpdatePage.module.css'; // Adjust CSS if needed
import { updateUser } from '../helpers/userHelpers';
@@ -8,21 +7,36 @@ const AccountUpdatePage = ({ user, showEmail, onSubmit }) => {
username: user.username.startsWith('guest') ? '' : user.username || '',
email: user.email || '',
password: user.password === 'unsetunsetunset' ? '' : user.password || '',
- // Add other fields as needed
});
+ const [errorMessage, setErrorMessage] = useState('');
+ const [successMessage, setSuccessMessage] = useState(''); // New state for success messages
+
const handleChange = (e) => {
setFormData({ ...formData, [e.target.name]: e.target.value });
};
const handleSubmit = async (e) => {
e.preventDefault();
+
+ // Validate password length on the frontend
+ if (formData.password && formData.password.length < 6) {
+ setErrorMessage('Password is too short');
+ return;
+ }
+
try {
- const response = await updateUser(formData);
- console.log('User updated successfully:', response);
- onSubmit(formData);
+ const response = await updateUser(formData); // Call the updated helper function
+
+ // If there's a success message, display it
+ if (response.message) {
+ setSuccessMessage(response.message); // Set the success message from the response
+ setErrorMessage(''); // Clear any previous error messages
+ }
} catch (error) {
- console.error('Failed to update user:', error);
+ // Handle the error by displaying the error message
+ setErrorMessage(error.message || 'Failed to update user. Please try again.');
+ setSuccessMessage(''); // Clear success message if there's an error
}
};
@@ -65,7 +79,11 @@ const AccountUpdatePage = ({ user, showEmail, onSubmit }) => {
/>
- {/* Add other fields as needed */}
+ {/* Display success message */}
+ {successMessage &&
{successMessage}
}
+
+ {/* Display error message */}
+ {errorMessage && {errorMessage}
}