bug fixed
This commit is contained in:
parent
346790205a
commit
234f6c4794
@ -279,11 +279,11 @@ function App() {
|
||||
}
|
||||
/>
|
||||
</Route> */}
|
||||
<Route path="/profile/edit/:id" element={
|
||||
{/* <Route path="/profile/edit/:id" element={
|
||||
<RequireRole allowedRoles={['EstablishmentUser']}>
|
||||
<EditCompanyProfile />
|
||||
</RequireRole>
|
||||
} />
|
||||
} /> */}
|
||||
{/* <Route
|
||||
path="/admin/configuration/profile/:id?"
|
||||
element={
|
||||
@ -292,6 +292,14 @@ function App() {
|
||||
</RequireRole>
|
||||
}
|
||||
/> */}
|
||||
<Route
|
||||
path="/edit-profile/:id"
|
||||
element={
|
||||
<RequireRole allowedRoles={['EstablishmentUser']}>
|
||||
<EditCompanyProfile />
|
||||
</RequireRole>
|
||||
}
|
||||
/>
|
||||
<Route path="/change-password" element={<ChangePassword />} />
|
||||
<Route path="/forgot-password" element={<ForgotPassword />} />
|
||||
<Route path="/reset-password" element={<PublicContactForm />} />
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { NavLink, useNavigate } from 'react-router-dom';
|
||||
|
||||
|
||||
const logoSrc = '/assets/images/FCSCLogo.svg';
|
||||
const surveyIconActiveSrc = '/assets/images/Vector.svg';
|
||||
const surveyIconInactiveSrc = '/assets/images/Vectorblack.svg';
|
||||
@ -10,7 +10,7 @@ const historyIconActiveSrc = '/assets/images/mdi_history.svg';
|
||||
const historyIconInactiveSrc = '/assets/images/history.svg';
|
||||
const overviewIconActiveSrc = '/assets/images/mdi_file-find-outline.svg';
|
||||
const overviewIconInactiveSrc = '/assets/images/mdi_file-find-outline-active.svg';
|
||||
|
||||
|
||||
const HeaderBar = () => {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [userName, setUserName] = React.useState('User');
|
||||
@ -18,7 +18,8 @@ const HeaderBar = () => {
|
||||
const [userOpen, setUserOpen] = React.useState(false);
|
||||
const profileRef = React.useRef(null);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const establishmentId = sessionStorage.getItem("establishment_id") || "";
|
||||
|
||||
// Close dropdown when clicking outside
|
||||
React.useEffect(() => {
|
||||
const handleClickOutside = (event) => {
|
||||
@ -26,13 +27,13 @@ const HeaderBar = () => {
|
||||
setUserOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', handleClickOutside);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
React.useEffect(() => {
|
||||
let parsed;
|
||||
try {
|
||||
@ -52,7 +53,7 @@ const HeaderBar = () => {
|
||||
setUserEmail(email);
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
const onLogout = () => {
|
||||
try {
|
||||
sessionStorage.removeItem('auth_token');
|
||||
@ -63,12 +64,12 @@ const HeaderBar = () => {
|
||||
setUserOpen(false);
|
||||
navigate('/index');
|
||||
};
|
||||
|
||||
|
||||
const onChangePassword = () => {
|
||||
setUserOpen(false);
|
||||
navigate('/reset-password');
|
||||
};
|
||||
|
||||
|
||||
const initials = React.useMemo(() => {
|
||||
const source = userName || userEmail;
|
||||
if (!source) return 'U';
|
||||
@ -97,10 +98,10 @@ const HeaderBar = () => {
|
||||
<NavLink
|
||||
to="/survey"
|
||||
className={({ isActive, isPending }) => `inline-flex items-center gap-2 pb-1 border-b-2 ${
|
||||
isActive
|
||||
? 'text-[#92722A] font-medium border-[#92722A]'
|
||||
isActive
|
||||
? 'text-[#92722A] font-medium border-[#92722A]'
|
||||
: (window.location.pathname === '/dashboard' || window.location.pathname === '/overview')
|
||||
? 'text-gray-400 cursor-not-allowed'
|
||||
? 'text-gray-400 cursor-not-allowed'
|
||||
: 'text-[#232528] hover:text-gray-900 border-transparent'
|
||||
}`}
|
||||
onClick={(e) => {
|
||||
@ -111,10 +112,10 @@ const HeaderBar = () => {
|
||||
>
|
||||
{({ isActive }) => (
|
||||
<>
|
||||
<img
|
||||
src={isActive ? surveyIconActiveSrc : surveyIconInactiveSrc}
|
||||
alt="Survey"
|
||||
className={`h-[18px] w-[18px] ${(window.location.pathname === '/dashboard' || window.location.pathname === '/overview') ? 'opacity-50' : ''}`}
|
||||
<img
|
||||
src={isActive ? surveyIconActiveSrc : surveyIconInactiveSrc}
|
||||
alt="Survey"
|
||||
className={`h-[18px] w-[18px] ${(window.location.pathname === '/dashboard' || window.location.pathname === '/overview') ? 'opacity-50' : ''}`}
|
||||
/>
|
||||
<span>Survey</span>
|
||||
</>
|
||||
@ -131,6 +132,37 @@ const HeaderBar = () => {
|
||||
</>
|
||||
)}
|
||||
</NavLink>
|
||||
<NavLink
|
||||
to={`/edit-profile/${establishmentId}`}
|
||||
className={({ isActive }) =>
|
||||
`inline-flex items-center gap-2 pb-1 border-b-2 ${
|
||||
isActive
|
||||
? "text-[#92722A] font-medium border-[#92722A]"
|
||||
: "text-[#232528] hover:text-gray-900 border-transparent"
|
||||
}`
|
||||
}
|
||||
>
|
||||
{({ isActive }) => (
|
||||
<>
|
||||
<svg
|
||||
className={`h-[16px] w-[18px] ${
|
||||
isActive ? "text-[#92722A]" : "text-[#232528]"
|
||||
}`}
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"
|
||||
/>
|
||||
</svg>
|
||||
<span>Profile</span>
|
||||
</>
|
||||
)}
|
||||
</NavLink>
|
||||
{/* <NavLink
|
||||
to="/history"
|
||||
className={({ isActive }) => `inline-flex items-center gap-2 pb-1 border-b-2 ${isActive ? 'text-[#92722A] font-medium border-[#92722A]' : 'text-[#232528] hover:text-gray-900 border-transparent'}`}
|
||||
@ -199,27 +231,27 @@ const HeaderBar = () => {
|
||||
<img src={dashboardIconInactiveSrc} alt="Dashboard" className="h-[18px] w-[18px]" />
|
||||
<span>Dashboard</span>
|
||||
</NavLink>
|
||||
<NavLink
|
||||
to="/survey"
|
||||
<NavLink
|
||||
to="/survey"
|
||||
onClick={(e) => {
|
||||
if (window.location.pathname === '/dashboard') {
|
||||
e.preventDefault();
|
||||
} else {
|
||||
setOpen(false);
|
||||
}
|
||||
}}
|
||||
}}
|
||||
className={({ isActive }) => `inline-flex items-center gap-2 px-2 py-2 rounded border-b-2 ${
|
||||
isActive
|
||||
? 'text-[#92722A] bg-[#F2ECCF] border-[#92722A]'
|
||||
isActive
|
||||
? 'text-[#92722A] bg-[#F2ECCF] border-[#92722A]'
|
||||
: window.location.pathname === '/dashboard'
|
||||
? 'text-gray-400 cursor-not-allowed bg-gray-100'
|
||||
? 'text-gray-400 cursor-not-allowed bg-gray-100'
|
||||
: 'text-[#232528] hover:bg-gray-100 border-transparent'
|
||||
}`}
|
||||
>
|
||||
<img
|
||||
src={surveyIconInactiveSrc}
|
||||
alt="Survey"
|
||||
className={`h-[18px] w-[18px] ${window.location.pathname === '/dashboard' ? 'opacity-50' : ''}`}
|
||||
<img
|
||||
src={surveyIconInactiveSrc}
|
||||
alt="Survey"
|
||||
className={`h-[18px] w-[18px] ${window.location.pathname === '/dashboard' ? 'opacity-50' : ''}`}
|
||||
/>
|
||||
<span>Survey</span>
|
||||
</NavLink>
|
||||
@ -265,5 +297,5 @@ const HeaderBar = () => {
|
||||
</header>
|
||||
);
|
||||
};
|
||||
|
||||
export default HeaderBar;
|
||||
|
||||
export default HeaderBar;
|
||||
@ -236,19 +236,33 @@ const EstablishmentInfo = ({
|
||||
});
|
||||
};
|
||||
|
||||
// const handleEditProfile = (e) => {
|
||||
// e.preventDefault();
|
||||
|
||||
// const establishmentId = sessionStorage.getItem('establishment_id');
|
||||
// if (!establishmentId) {
|
||||
// alert('No establishment ID found in session');
|
||||
// return;
|
||||
// }
|
||||
|
||||
// localStorage.setItem('returnTo', window.location.pathname);
|
||||
// sessionStorage.setItem('edit_profile_from', 'EstablishmentUser');
|
||||
// // navigate(`/profile/edit/${establishmentId}`);
|
||||
// };
|
||||
const handleEditProfile = (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const establishmentId = sessionStorage.getItem('establishment_id');
|
||||
if (!establishmentId) {
|
||||
alert('No establishment ID found in session');
|
||||
return;
|
||||
}
|
||||
|
||||
localStorage.setItem('returnTo', window.location.pathname);
|
||||
sessionStorage.setItem('edit_profile_from', 'EstablishmentUser');
|
||||
navigate(`/profile/edit/${establishmentId}`);
|
||||
e.preventDefault();
|
||||
|
||||
const establishmentId = sessionStorage.getItem('establishment_id');
|
||||
if (!establishmentId) {
|
||||
alert('No establishment ID found in session');
|
||||
return;
|
||||
}
|
||||
|
||||
localStorage.setItem('returnTo', window.location.pathname);
|
||||
sessionStorage.setItem('edit_profile_from', 'EstablishmentUser');
|
||||
navigate(`/edit-profile/${establishmentId}`);
|
||||
};
|
||||
|
||||
const handleEmployeeChange = (field) => (event) => {
|
||||
onChange({
|
||||
...info,
|
||||
@ -375,7 +389,7 @@ const EstablishmentInfo = ({
|
||||
here
|
||||
</a>.
|
||||
</p> */}
|
||||
<p className="text-sm text-[#043DFF] bg-[#E7F5FF]">
|
||||
{/* <p className="text-sm text-[#043DFF] bg-[#E7F5FF]">
|
||||
<span className="font-medium">Need to update details?</span> Go to Profile →{' '}
|
||||
<a
|
||||
href={`/admin/configuration/profile/edit=${sessionStorage.getItem('establishment_id') || ''}`}
|
||||
@ -386,7 +400,17 @@ const EstablishmentInfo = ({
|
||||
Edit Profile
|
||||
</a>
|
||||
. Changes saved there will appear here.
|
||||
</p>
|
||||
</p> */}
|
||||
<p className="text-sm text-[#043DFF] bg-[#E7F5FF]">
|
||||
<span className="font-medium">Need to update details?</span> Go to Profile →{' '}
|
||||
<a
|
||||
href={`/admin/configuration/edit-profile/${sessionStorage.getItem('establishment_id') || ''}`}
|
||||
className="underline font-medium text-[#043DFF] hover:text-[#063B82]"
|
||||
onClick={handleEditProfile}
|
||||
>
|
||||
Edit Profile
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<h2 className="text-lg font-semibold text-[#232528]">Step 1: Review Establishment Information</h2>
|
||||
|
||||
@ -15,6 +15,8 @@ const AddAdminUsers = ({ isOpen, onClose, onSave }) => {
|
||||
});
|
||||
|
||||
const [errors, setErrors] = useState({});
|
||||
const [passwordError, setPasswordError] = useState('');
|
||||
const [passwordTouched, setPasswordTouched] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [toastData, setToastData] = useState(null); // 👈 for custom toast
|
||||
|
||||
@ -41,16 +43,14 @@ const AddAdminUsers = ({ isOpen, onClose, onSave }) => {
|
||||
|
||||
if (!formData.status) newErrors.status = 'Status is required';
|
||||
|
||||
if (!formData.password) {
|
||||
newErrors.password = 'Password is required';
|
||||
} else if (formData.password.length < 8) {
|
||||
newErrors.password = 'Password must be at least 8 characters';
|
||||
} else if (formData.password.length > 12) {
|
||||
newErrors.password = 'Password cannot exceed 12 characters';
|
||||
const passwordValidation = validatePassword(formData.password);
|
||||
if (passwordValidation) {
|
||||
newErrors.password = passwordValidation;
|
||||
}
|
||||
|
||||
if (formData.password !== formData.confirmPassword)
|
||||
if (formData.password !== formData.confirmPassword) {
|
||||
newErrors.confirmPassword = 'Passwords do not match';
|
||||
}
|
||||
|
||||
return newErrors;
|
||||
};
|
||||
@ -70,10 +70,38 @@ const AddAdminUsers = ({ isOpen, onClose, onSave }) => {
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
const validatePassword = (password) => {
|
||||
if (!password) return 'Password is required';
|
||||
if (password.length < 8) return 'Password must be at least 8 characters';
|
||||
if (!/[A-Z]/.test(password)) return 'Must contain at least one uppercase letter';
|
||||
if (!/[a-z]/.test(password)) return 'Must contain at least one lowercase letter';
|
||||
if (!/\d/.test(password)) return 'Must contain at least one number';
|
||||
if (!/[!@#$%^&*]/.test(password)) return 'Must contain at least one special character (!@#$%^&*)';
|
||||
return '';
|
||||
};
|
||||
|
||||
const handleChange = (e) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData((prev) => ({ ...prev, [name]: value }));
|
||||
|
||||
// Clear any existing error for this field
|
||||
if (errors[name]) setErrors((prev) => ({ ...prev, [name]: '' }));
|
||||
|
||||
// Real-time password validation
|
||||
if (name === 'password') {
|
||||
setPasswordTouched(true);
|
||||
const error = validatePassword(value);
|
||||
setPasswordError(error);
|
||||
}
|
||||
|
||||
// Clear confirm password error when either password changes
|
||||
if ((name === 'password' || name === 'confirmPassword') && formData.password && formData.confirmPassword) {
|
||||
if (formData.password !== formData.confirmPassword) {
|
||||
setErrors(prev => ({ ...prev, confirmPassword: 'Passwords do not match' }));
|
||||
} else {
|
||||
setErrors(prev => ({ ...prev, confirmPassword: '' }));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = async (e) => {
|
||||
@ -156,29 +184,37 @@ const AddAdminUsers = ({ isOpen, onClose, onSave }) => {
|
||||
placeholder="Enter email"
|
||||
/>
|
||||
|
||||
<TextField
|
||||
label="Password"
|
||||
name="password"
|
||||
type="password"
|
||||
value={formData.password}
|
||||
onChange={handleChange}
|
||||
error={errors.password}
|
||||
required
|
||||
placeholder="Enter password"
|
||||
showToggle
|
||||
/>
|
||||
<div className="relative">
|
||||
<TextField
|
||||
label="Password"
|
||||
name="password"
|
||||
type="password"
|
||||
value={formData.password}
|
||||
onChange={handleChange}
|
||||
onBlur={() => setPasswordTouched(true)}
|
||||
error={passwordTouched && passwordError ? passwordError : ''}
|
||||
required
|
||||
placeholder="Enter password"
|
||||
showToggle
|
||||
/>
|
||||
</div>
|
||||
|
||||
<TextField
|
||||
label="Confirm Password"
|
||||
name="confirmPassword"
|
||||
type="password"
|
||||
value={formData.confirmPassword}
|
||||
onChange={handleChange}
|
||||
error={errors.confirmPassword}
|
||||
required
|
||||
placeholder="Confirm password"
|
||||
showToggle
|
||||
/>
|
||||
<div className="relative">
|
||||
<TextField
|
||||
label="Confirm Password"
|
||||
name="confirmPassword"
|
||||
type="password"
|
||||
value={formData.confirmPassword}
|
||||
onChange={handleChange}
|
||||
error={errors.confirmPassword}
|
||||
required
|
||||
placeholder="Confirm password"
|
||||
showToggle
|
||||
/>
|
||||
{formData.confirmPassword && !errors.confirmPassword && (
|
||||
<p className="mt-1 text-xs text-green-600">Passwords match</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="md:col-span-2 space-y-2">
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -15,20 +15,33 @@ export const getUnits = async () => {
|
||||
|
||||
export const createUnit = async (unitData) => {
|
||||
try {
|
||||
// Log the data being sent for debugging
|
||||
console.log('Creating unit with data:', unitData);
|
||||
|
||||
const response = await postRequest(UNIT_MASTER_ENDPOINT, unitData);
|
||||
console.log('Unit created successfully:', response.data);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error creating unit:', error);
|
||||
console.error('Error details:', {
|
||||
status: error.response?.status,
|
||||
data: error.response?.data,
|
||||
headers: error.response?.headers
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const updateUnit = async (id, unitData) => {
|
||||
try {
|
||||
console.log('Updating unit with data:', unitData);
|
||||
|
||||
const response = await putRequest(`${UNIT_MASTER_ENDPOINT}/${id}`, unitData);
|
||||
console.log('Unit updated successfully:', response.data);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error updating unit:', error);
|
||||
console.error('Error details:', error.response?.data);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@ -36,9 +49,25 @@ export const updateUnit = async (id, unitData) => {
|
||||
export const deleteUnit = async (id) => {
|
||||
try {
|
||||
const response = await deleteRequest(`${UNIT_MASTER_ENDPOINT}/${id}`);
|
||||
console.log('Unit deleted successfully:', response.data);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error deleting unit:', error);
|
||||
console.error('Error details:', error.response?.data);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const uploadUnitCSV = async (formData) => {
|
||||
try {
|
||||
const response = await postRequest(`${UNIT_MASTER_ENDPOINT}/uploadCSV`, formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Error uploading unit CSV:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user