ok
This commit is contained in:
@@ -276,7 +276,7 @@ function App() {
|
|||||||
};
|
};
|
||||||
}, [socket, shopId]);
|
}, [socket, shopId]);
|
||||||
|
|
||||||
async function checkIfStillViewingOtherTransaction(){
|
async function checkIfStillViewingOtherTransaction() {
|
||||||
|
|
||||||
console.log("transaction notification");
|
console.log("transaction notification");
|
||||||
console.log(modalContent);
|
console.log(modalContent);
|
||||||
@@ -651,6 +651,7 @@ function App() {
|
|||||||
</Routes>
|
</Routes>
|
||||||
</header>
|
</header>
|
||||||
<Modal
|
<Modal
|
||||||
|
user={user}
|
||||||
shop={shop}
|
shop={shop}
|
||||||
isOpen={isModalOpen}
|
isOpen={isModalOpen}
|
||||||
modalContent={modalContent}
|
modalContent={modalContent}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// src/components/AccountUpdatePage.js
|
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import styles from './AccountUpdatePage.module.css'; // Adjust CSS if needed
|
import styles from './AccountUpdatePage.module.css'; // Adjust CSS if needed
|
||||||
import { updateUser } from '../helpers/userHelpers';
|
import { updateUser } from '../helpers/userHelpers';
|
||||||
@@ -8,21 +7,36 @@ const AccountUpdatePage = ({ user, showEmail, onSubmit }) => {
|
|||||||
username: user.username.startsWith('guest') ? '' : user.username || '',
|
username: user.username.startsWith('guest') ? '' : user.username || '',
|
||||||
email: user.email || '',
|
email: user.email || '',
|
||||||
password: user.password === 'unsetunsetunset' ? '' : user.password || '',
|
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) => {
|
const handleChange = (e) => {
|
||||||
setFormData({ ...formData, [e.target.name]: e.target.value });
|
setFormData({ ...formData, [e.target.name]: e.target.value });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (e) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
// Validate password length on the frontend
|
||||||
|
if (formData.password && formData.password.length < 6) {
|
||||||
|
setErrorMessage('Password is too short');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await updateUser(formData);
|
const response = await updateUser(formData); // Call the updated helper function
|
||||||
console.log('User updated successfully:', response);
|
|
||||||
onSubmit(formData);
|
// 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) {
|
} 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 }) => {
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
{/* Add other fields as needed */}
|
{/* 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}>
|
<button type="submit" className={styles.submitButton}>
|
||||||
Submit
|
Submit
|
||||||
|
|||||||
@@ -1,27 +1,131 @@
|
|||||||
/* src/components/AccountUpdateModal.module.css */
|
/* AccountUpdatePage.module.css */
|
||||||
|
|
||||||
.modalOverlay {
|
/* General container styles */
|
||||||
position: fixed;
|
.container {
|
||||||
top: 0;
|
max-width: 600px;
|
||||||
left: 0;
|
margin: 0 auto;
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background: rgba(0, 0, 0, 0.5);
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
z-index: 101;
|
|
||||||
}
|
|
||||||
|
|
||||||
.modalContent {
|
|
||||||
background: white;
|
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
border-radius: 10px;
|
background-color: #f9f9f9;
|
||||||
max-width: 500px;
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Heading styles */
|
||||||
|
h2 {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 1.8rem;
|
||||||
|
color: #333;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Form styles */
|
||||||
|
.form {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Label and input styles */
|
||||||
|
.formLabel {
|
||||||
|
font-size: 1rem;
|
||||||
|
color: #555;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formInput {
|
||||||
|
padding: 10px;
|
||||||
|
margin-top: 8px;
|
||||||
|
font-size: 1rem;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
box-sizing: border-box;
|
||||||
position: relative;
|
transition: border 0.3s ease;
|
||||||
z-index: 11;
|
}
|
||||||
color: black;
|
|
||||||
|
.formInput:focus {
|
||||||
|
border: 1px solid #007BFF;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Submit button styles */
|
||||||
|
.submitButton {
|
||||||
|
padding: 12px;
|
||||||
|
background-color: #007BFF;
|
||||||
|
color: #fff;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 1rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submitButton:hover {
|
||||||
|
background-color: #0056b3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mobile responsive design */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.container {
|
||||||
|
padding: 15px;
|
||||||
|
width: 90%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 1.6rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formInput {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submitButton {
|
||||||
|
padding: 10px;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tablet and desktop view adjustments */
|
||||||
|
@media (min-width: 769px) {
|
||||||
|
.container {
|
||||||
|
padding: 20px;
|
||||||
|
width: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formInput {
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submitButton {
|
||||||
|
padding: 12px;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Additional Accessibility Enhancements */
|
||||||
|
.formInput:focus {
|
||||||
|
border-color: #007BFF;
|
||||||
|
box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
|
||||||
|
}
|
||||||
|
/* AccountUpdatePage.module.css */
|
||||||
|
|
||||||
|
/* Success message styles */
|
||||||
|
.successMessage {
|
||||||
|
color: green;
|
||||||
|
font-size: 1rem;
|
||||||
|
margin-top: 10px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Error message styles */
|
||||||
|
.errorMessage {
|
||||||
|
color: red;
|
||||||
|
font-size: 1rem;
|
||||||
|
margin-top: 10px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import Login from "../pages/Login";
|
|||||||
import ResetPassword from "../pages/ResetPassword";
|
import ResetPassword from "../pages/ResetPassword";
|
||||||
import { getImageUrl } from "../helpers/itemHelper.js";
|
import { getImageUrl } from "../helpers/itemHelper.js";
|
||||||
|
|
||||||
const Modal = ({ shop, isOpen, onClose, modalContent, setModal, handleMoveToTransaction,welcomePageConfig }) => {
|
const Modal = ({ user, shop, isOpen, onClose, modalContent, setModal, handleMoveToTransaction,welcomePageConfig }) => {
|
||||||
|
|
||||||
const [shopImg, setShopImg] = useState('');
|
const [shopImg, setShopImg] = useState('');
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ const Modal = ({ shop, isOpen, onClose, modalContent, setModal, handleMoveToTran
|
|||||||
<div onClick={handleOverlayClick} className={styles.modalOverlay}>
|
<div onClick={handleOverlayClick} className={styles.modalOverlay}>
|
||||||
<div className={styles.modalContent} onClick={handleContentClick}>
|
<div className={styles.modalContent} onClick={handleContentClick}>
|
||||||
|
|
||||||
{modalContent === "edit_account" && <AccountUpdatePage shop={shop} />}
|
{modalContent === "edit_account" && <AccountUpdatePage user={user} />}
|
||||||
{modalContent === "join" && <Join />}
|
{modalContent === "join" && <Join />}
|
||||||
{modalContent === "reset-password" && <ResetPassword />}
|
{modalContent === "reset-password" && <ResetPassword />}
|
||||||
{modalContent === "req_notification" && <NotificationRequest setModal={setModal} />}
|
{modalContent === "req_notification" && <NotificationRequest setModal={setModal} />}
|
||||||
|
|||||||
@@ -146,10 +146,14 @@ export const loginUser = async (username, password) => {
|
|||||||
return { success: false, token: null };
|
return { success: false, token: null };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateUser = async (formData) => {
|
export const updateUser = async (formData) => {
|
||||||
const token = getLocalStorage("auth");
|
const token = getLocalStorage("auth"); // Retrieve token from local storage
|
||||||
if (token) {
|
|
||||||
|
if (!token) {
|
||||||
|
// Handle missing token scenario
|
||||||
|
throw new Error("User not authenticated. No token found.");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(API_BASE_URL + "/user/update-user", {
|
const response = await fetch(API_BASE_URL + "/user/update-user", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -159,17 +163,27 @@ export const updateUser = async (formData) => {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify(formData),
|
body: JSON.stringify(formData),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Check if response status is not ok (e.g., 400 or 500 errors)
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
const data = await response.json();
|
||||||
|
|
||||||
|
// If the response body has an error, throw it to propagate to the frontend
|
||||||
|
throw new Error(data.error || `Error: ${response.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the response is OK, return the data
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
// Log and rethrow error to be handled in the calling function
|
||||||
console.error("Error updating user:", error);
|
console.error("Error updating user:", error);
|
||||||
}
|
throw error; // Re-throw the error so the calling function can handle it
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//for super
|
//for super
|
||||||
export const getAnalytics = async (formData) => {
|
export const getAnalytics = async (formData) => {
|
||||||
const token = getLocalStorage("auth");
|
const token = getLocalStorage("auth");
|
||||||
|
|||||||
Reference in New Issue
Block a user