bug fixed
This commit is contained in:
parent
346790205a
commit
234f6c4794
@ -279,11 +279,11 @@ function App() {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</Route> */}
|
</Route> */}
|
||||||
<Route path="/profile/edit/:id" element={
|
{/* <Route path="/profile/edit/:id" element={
|
||||||
<RequireRole allowedRoles={['EstablishmentUser']}>
|
<RequireRole allowedRoles={['EstablishmentUser']}>
|
||||||
<EditCompanyProfile />
|
<EditCompanyProfile />
|
||||||
</RequireRole>
|
</RequireRole>
|
||||||
} />
|
} /> */}
|
||||||
{/* <Route
|
{/* <Route
|
||||||
path="/admin/configuration/profile/:id?"
|
path="/admin/configuration/profile/:id?"
|
||||||
element={
|
element={
|
||||||
@ -292,6 +292,14 @@ function App() {
|
|||||||
</RequireRole>
|
</RequireRole>
|
||||||
}
|
}
|
||||||
/> */}
|
/> */}
|
||||||
|
<Route
|
||||||
|
path="/edit-profile/:id"
|
||||||
|
element={
|
||||||
|
<RequireRole allowedRoles={['EstablishmentUser']}>
|
||||||
|
<EditCompanyProfile />
|
||||||
|
</RequireRole>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<Route path="/change-password" element={<ChangePassword />} />
|
<Route path="/change-password" element={<ChangePassword />} />
|
||||||
<Route path="/forgot-password" element={<ForgotPassword />} />
|
<Route path="/forgot-password" element={<ForgotPassword />} />
|
||||||
<Route path="/reset-password" element={<PublicContactForm />} />
|
<Route path="/reset-password" element={<PublicContactForm />} />
|
||||||
|
|||||||
@ -18,6 +18,7 @@ const HeaderBar = () => {
|
|||||||
const [userOpen, setUserOpen] = React.useState(false);
|
const [userOpen, setUserOpen] = React.useState(false);
|
||||||
const profileRef = React.useRef(null);
|
const profileRef = React.useRef(null);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const establishmentId = sessionStorage.getItem("establishment_id") || "";
|
||||||
|
|
||||||
// Close dropdown when clicking outside
|
// Close dropdown when clicking outside
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@ -131,6 +132,37 @@ const HeaderBar = () => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</NavLink>
|
</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
|
{/* <NavLink
|
||||||
to="/history"
|
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'}`}
|
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'}`}
|
||||||
|
|||||||
@ -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) => {
|
const handleEditProfile = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const establishmentId = sessionStorage.getItem('establishment_id');
|
const establishmentId = sessionStorage.getItem('establishment_id');
|
||||||
if (!establishmentId) {
|
if (!establishmentId) {
|
||||||
alert('No establishment ID found in session');
|
alert('No establishment ID found in session');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
localStorage.setItem('returnTo', window.location.pathname);
|
localStorage.setItem('returnTo', window.location.pathname);
|
||||||
sessionStorage.setItem('edit_profile_from', 'EstablishmentUser');
|
sessionStorage.setItem('edit_profile_from', 'EstablishmentUser');
|
||||||
navigate(`/profile/edit/${establishmentId}`);
|
navigate(`/edit-profile/${establishmentId}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEmployeeChange = (field) => (event) => {
|
const handleEmployeeChange = (field) => (event) => {
|
||||||
onChange({
|
onChange({
|
||||||
...info,
|
...info,
|
||||||
@ -375,7 +389,7 @@ const EstablishmentInfo = ({
|
|||||||
here
|
here
|
||||||
</a>.
|
</a>.
|
||||||
</p> */}
|
</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 →{' '}
|
<span className="font-medium">Need to update details?</span> Go to Profile →{' '}
|
||||||
<a
|
<a
|
||||||
href={`/admin/configuration/profile/edit=${sessionStorage.getItem('establishment_id') || ''}`}
|
href={`/admin/configuration/profile/edit=${sessionStorage.getItem('establishment_id') || ''}`}
|
||||||
@ -386,7 +400,17 @@ const EstablishmentInfo = ({
|
|||||||
Edit Profile
|
Edit Profile
|
||||||
</a>
|
</a>
|
||||||
. Changes saved there will appear here.
|
. 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>
|
||||||
<div className="flex items-center gap-2 mb-2">
|
<div className="flex items-center gap-2 mb-2">
|
||||||
<h2 className="text-lg font-semibold text-[#232528]">Step 1: Review Establishment Information</h2>
|
<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 [errors, setErrors] = useState({});
|
||||||
|
const [passwordError, setPasswordError] = useState('');
|
||||||
|
const [passwordTouched, setPasswordTouched] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [toastData, setToastData] = useState(null); // 👈 for custom toast
|
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.status) newErrors.status = 'Status is required';
|
||||||
|
|
||||||
if (!formData.password) {
|
const passwordValidation = validatePassword(formData.password);
|
||||||
newErrors.password = 'Password is required';
|
if (passwordValidation) {
|
||||||
} else if (formData.password.length < 8) {
|
newErrors.password = passwordValidation;
|
||||||
newErrors.password = 'Password must be at least 8 characters';
|
|
||||||
} else if (formData.password.length > 12) {
|
|
||||||
newErrors.password = 'Password cannot exceed 12 characters';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formData.password !== formData.confirmPassword)
|
if (formData.password !== formData.confirmPassword) {
|
||||||
newErrors.confirmPassword = 'Passwords do not match';
|
newErrors.confirmPassword = 'Passwords do not match';
|
||||||
|
}
|
||||||
|
|
||||||
return newErrors;
|
return newErrors;
|
||||||
};
|
};
|
||||||
@ -70,10 +70,38 @@ const AddAdminUsers = ({ isOpen, onClose, onSave }) => {
|
|||||||
}
|
}
|
||||||
}, [isOpen]);
|
}, [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 handleChange = (e) => {
|
||||||
const { name, value } = e.target;
|
const { name, value } = e.target;
|
||||||
setFormData((prev) => ({ ...prev, [name]: value }));
|
setFormData((prev) => ({ ...prev, [name]: value }));
|
||||||
|
|
||||||
|
// Clear any existing error for this field
|
||||||
if (errors[name]) setErrors((prev) => ({ ...prev, [name]: '' }));
|
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) => {
|
const handleSubmit = async (e) => {
|
||||||
@ -156,29 +184,37 @@ const AddAdminUsers = ({ isOpen, onClose, onSave }) => {
|
|||||||
placeholder="Enter email"
|
placeholder="Enter email"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextField
|
<div className="relative">
|
||||||
label="Password"
|
<TextField
|
||||||
name="password"
|
label="Password"
|
||||||
type="password"
|
name="password"
|
||||||
value={formData.password}
|
type="password"
|
||||||
onChange={handleChange}
|
value={formData.password}
|
||||||
error={errors.password}
|
onChange={handleChange}
|
||||||
required
|
onBlur={() => setPasswordTouched(true)}
|
||||||
placeholder="Enter password"
|
error={passwordTouched && passwordError ? passwordError : ''}
|
||||||
showToggle
|
required
|
||||||
/>
|
placeholder="Enter password"
|
||||||
|
showToggle
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<TextField
|
<div className="relative">
|
||||||
label="Confirm Password"
|
<TextField
|
||||||
name="confirmPassword"
|
label="Confirm Password"
|
||||||
type="password"
|
name="confirmPassword"
|
||||||
value={formData.confirmPassword}
|
type="password"
|
||||||
onChange={handleChange}
|
value={formData.confirmPassword}
|
||||||
error={errors.confirmPassword}
|
onChange={handleChange}
|
||||||
required
|
error={errors.confirmPassword}
|
||||||
placeholder="Confirm password"
|
required
|
||||||
showToggle
|
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">
|
<div className="md:col-span-2 space-y-2">
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
|
|||||||
@ -3,7 +3,8 @@ import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
|||||||
import { TextField, SelectField, PhoneField } from "@/components/common/FormControls";
|
import { TextField, SelectField, PhoneField } from "@/components/common/FormControls";
|
||||||
import Loader from "@/components/common/Loader";
|
import Loader from "@/components/common/Loader";
|
||||||
import { fetchEstablishmentDetail, updateEstablishment } from '@/services/establishments/establishmentService';
|
import { fetchEstablishmentDetail, updateEstablishment } from '@/services/establishments/establishmentService';
|
||||||
import { fetchEmirates, fetchCityTowns } from '@/services/masters/masterService';
|
import { fetchEmirates, fetchCityTowns, fetchProducts } from '@/services/masters/masterService';
|
||||||
|
import HeaderBar from "@/components/layout/HeaderBar";
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
const createEmptyProfile = () => ({
|
const createEmptyProfile = () => ({
|
||||||
@ -26,20 +27,6 @@ const createEmptyProfile = () => ({
|
|||||||
contactPostalCode: '',
|
contactPostalCode: '',
|
||||||
contactPoBox: '',
|
contactPoBox: '',
|
||||||
contactWebsite: '',
|
contactWebsite: '',
|
||||||
corporateName: '',
|
|
||||||
corporateAddress: '',
|
|
||||||
corporateCityTown: '',
|
|
||||||
corporateCityTownId: '',
|
|
||||||
corporateEmirate: '',
|
|
||||||
corporateEmirateId: '',
|
|
||||||
corporateMakaniNumber: '',
|
|
||||||
corporateContactPersonName: '',
|
|
||||||
corporateMobileNumber: '',
|
|
||||||
corporateEmail: '',
|
|
||||||
corporatePostalCode: '',
|
|
||||||
corporatePoBox: '',
|
|
||||||
corporateWebsite: '',
|
|
||||||
corporateSameAs: false,
|
|
||||||
employmentEmiratiMale: 0,
|
employmentEmiratiMale: 0,
|
||||||
employmentEmiratiFemale: 0,
|
employmentEmiratiFemale: 0,
|
||||||
employmentNonEmiratiMale: 0,
|
employmentNonEmiratiMale: 0,
|
||||||
@ -69,20 +56,6 @@ const mapApiEstablishmentToProfile = (apiData) => {
|
|||||||
contactPostalCode: data.establishment_postal_code || '',
|
contactPostalCode: data.establishment_postal_code || '',
|
||||||
contactPoBox: data.establishment_po_box || '',
|
contactPoBox: data.establishment_po_box || '',
|
||||||
contactWebsite: data.establishment_website || '',
|
contactWebsite: data.establishment_website || '',
|
||||||
corporateName: data.corporate_name || '',
|
|
||||||
corporateAddress: data.corporate_address || '',
|
|
||||||
corporateCityTown: data.corporate_city?.name || '',
|
|
||||||
corporateCityTownId: data.corporate_city?.id || '',
|
|
||||||
corporateEmirate: data.corporate_emirate?.name || '',
|
|
||||||
corporateEmirateId: data.corporate_emirate?.id || '',
|
|
||||||
corporateMakaniNumber: data.corporate_makani_number || '',
|
|
||||||
corporateContactPersonName: data.corporate_contact_person_name || '',
|
|
||||||
corporateMobileNumber: data.corporate_mobile_number || '',
|
|
||||||
corporateEmail: data.corporate_email || '',
|
|
||||||
corporatePostalCode: data.corporate_postal_code || '',
|
|
||||||
corporatePoBox: data.corporate_po_box || '',
|
|
||||||
corporateWebsite: data.corporate_website || '',
|
|
||||||
corporateSameAs: data.corporate_same_as_establishment || false,
|
|
||||||
employmentEmiratiMale: data.emirati_male || 0,
|
employmentEmiratiMale: data.emirati_male || 0,
|
||||||
employmentEmiratiFemale: data.emirati_female || 0,
|
employmentEmiratiFemale: data.emirati_female || 0,
|
||||||
employmentNonEmiratiMale: data.non_emirati_male || 0,
|
employmentNonEmiratiMale: data.non_emirati_male || 0,
|
||||||
@ -90,22 +63,6 @@ const mapApiEstablishmentToProfile = (apiData) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const contactToCorporateMap = {
|
|
||||||
contactName: 'corporateName',
|
|
||||||
contactAddress: 'corporateAddress',
|
|
||||||
contactCityTown: 'corporateCityTown',
|
|
||||||
contactEmirate: 'corporateEmirate',
|
|
||||||
contactCityTownId: 'corporateCityTownId',
|
|
||||||
contactEmirateId: 'corporateEmirateId',
|
|
||||||
contactMakaniNumber: 'corporateMakaniNumber',
|
|
||||||
contactPersonName: 'corporateContactPersonName',
|
|
||||||
contactMobileNumber: 'corporateMobileNumber',
|
|
||||||
contactEmail: 'corporateEmail',
|
|
||||||
contactPostalCode: 'corporatePostalCode',
|
|
||||||
contactPoBox: 'corporatePoBox',
|
|
||||||
contactWebsite: 'corporateWebsite',
|
|
||||||
};
|
|
||||||
|
|
||||||
const computeEmploymentTotals = (data) => {
|
const computeEmploymentTotals = (data) => {
|
||||||
const emiratiMale = parseInt(data.employmentEmiratiMale) || 0;
|
const emiratiMale = parseInt(data.employmentEmiratiMale) || 0;
|
||||||
const nonEmiratiMale = parseInt(data.employmentNonEmiratiMale) || 0;
|
const nonEmiratiMale = parseInt(data.employmentNonEmiratiMale) || 0;
|
||||||
@ -121,18 +78,11 @@ const computeEmploymentTotals = (data) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const captureCorporateValues = (data) => {
|
const EditCompanyProfile = () => {
|
||||||
const corporateData = {};
|
|
||||||
Object.values(contactToCorporateMap).forEach(key => {
|
|
||||||
corporateData[key] = data[key];
|
|
||||||
});
|
|
||||||
return corporateData;
|
|
||||||
};
|
|
||||||
|
|
||||||
const EditCompanyProfile = ({ onClose: propOnClose }) => {
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { id: establishmentId } = useParams();
|
const { id: establishmentId } = useParams();
|
||||||
const onClose = propOnClose || (() => navigate('/survey'));
|
console.log('EditCompanyProfile mounted, establishmentId from params:', establishmentId);
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [form, setForm] = useState(createEmptyProfile());
|
const [form, setForm] = useState(createEmptyProfile());
|
||||||
const [activeStep, setActiveStep] = useState(0);
|
const [activeStep, setActiveStep] = useState(0);
|
||||||
@ -144,16 +94,18 @@ const EditCompanyProfile = ({ onClose: propOnClose }) => {
|
|||||||
const [emirateOptions, setEmirateOptions] = useState([]);
|
const [emirateOptions, setEmirateOptions] = useState([]);
|
||||||
const [emirateLookup, setEmirateLookup] = useState({});
|
const [emirateLookup, setEmirateLookup] = useState({});
|
||||||
const [contactCityOptions, setContactCityOptions] = useState([]);
|
const [contactCityOptions, setContactCityOptions] = useState([]);
|
||||||
const [corporateCityOptions, setCorporateCityOptions] = useState([]);
|
const [availableProducts, setAvailableProducts] = useState([]);
|
||||||
|
const [selectedProducts, setSelectedProducts] = useState([]);
|
||||||
|
const [productSearchTerm, setProductSearchTerm] = useState('');
|
||||||
|
const [isLoadingProducts, setIsLoadingProducts] = useState(false);
|
||||||
const initialSnapshotRef = useRef(null);
|
const initialSnapshotRef = useRef(null);
|
||||||
const corporateBackupRef = useRef(null);
|
|
||||||
|
|
||||||
const formSteps = React.useMemo(
|
const formSteps = React.useMemo(
|
||||||
() => [
|
() => [
|
||||||
{ label: 'User Profile' },
|
{ label: 'User Profile' },
|
||||||
{ label: 'Identification Particulars' },
|
{ label: 'Identification Particulars' },
|
||||||
{ label: 'Establishment Contact Details' },
|
{ label: 'Establishment Contact Details' },
|
||||||
{ label: 'Corporate / Head Office Contact' },
|
{ label: 'Products' },
|
||||||
{ label: 'Employment in Establishment' },
|
{ label: 'Employment in Establishment' },
|
||||||
],
|
],
|
||||||
[]
|
[]
|
||||||
@ -182,14 +134,7 @@ const EditCompanyProfile = ({ onClose: propOnClose }) => {
|
|||||||
{ field: 'contactEmail', label: 'Email' },
|
{ field: 'contactEmail', label: 'Email' },
|
||||||
],
|
],
|
||||||
3: [
|
3: [
|
||||||
{ field: 'corporateName', label: 'Name' },
|
// Products are optional, no required fields
|
||||||
{ field: 'corporateAddress', label: 'Address' },
|
|
||||||
{ field: 'corporateCityTown', label: 'City/Town' },
|
|
||||||
{ field: 'corporateEmirate', label: 'Emirate' },
|
|
||||||
{ field: 'corporateMakaniNumber', label: 'Makani Number' },
|
|
||||||
{ field: 'corporateContactPersonName', label: 'Contact Person Name' },
|
|
||||||
{ field: 'corporateMobileNumber', label: 'Mobile Number' },
|
|
||||||
{ field: 'corporateEmail', label: 'Email' },
|
|
||||||
],
|
],
|
||||||
4: [
|
4: [
|
||||||
{ field: 'employmentEmiratiMale', label: 'Number of Emirati Male' },
|
{ field: 'employmentEmiratiMale', label: 'Number of Emirati Male' },
|
||||||
@ -231,16 +176,6 @@ const EditCompanyProfile = ({ onClose: propOnClose }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field === 'corporateCityTown') {
|
|
||||||
const foundCity = corporateCityOptions.find(option => option.value === value || option.label === value);
|
|
||||||
setForm(prev => ({
|
|
||||||
...prev,
|
|
||||||
corporateCityTown: foundCity?.name || '',
|
|
||||||
corporateCityTownId: foundCity?.id || ''
|
|
||||||
}));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setForm((prev) => ({ ...prev, [field]: value }));
|
setForm((prev) => ({ ...prev, [field]: value }));
|
||||||
setFieldErrors((prev) => ({ ...prev, [field]: "" }));
|
setFieldErrors((prev) => ({ ...prev, [field]: "" }));
|
||||||
|
|
||||||
@ -251,7 +186,7 @@ const EditCompanyProfile = ({ onClose: propOnClose }) => {
|
|||||||
if (field === 'userProfileConfirmPassword') {
|
if (field === 'userProfileConfirmPassword') {
|
||||||
setConfirmError("");
|
setConfirmError("");
|
||||||
}
|
}
|
||||||
}, [contactCityOptions, corporateCityOptions]);
|
}, [contactCityOptions]);
|
||||||
|
|
||||||
const handleNext = useCallback(() => {
|
const handleNext = useCallback(() => {
|
||||||
if (validateStepFields(activeStep)) {
|
if (validateStepFields(activeStep)) {
|
||||||
@ -292,53 +227,169 @@ const EditCompanyProfile = ({ onClose: propOnClose }) => {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
// Load products
|
||||||
const fetchData = async () => {
|
const loadProducts = useCallback(async () => {
|
||||||
if (!establishmentId) {
|
try {
|
||||||
|
setIsLoadingProducts(true);
|
||||||
|
const response = await fetchProducts();
|
||||||
|
|
||||||
|
let productsData = [];
|
||||||
|
|
||||||
|
if (Array.isArray(response)) {
|
||||||
|
productsData = response;
|
||||||
|
} else if (response?.data) {
|
||||||
|
productsData = Array.isArray(response.data) ? response.data : response.data.products || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Processed products data:', productsData);
|
||||||
|
|
||||||
|
// Format products data
|
||||||
|
const formattedProducts = productsData.map(p => ({
|
||||||
|
id: p.id || p.value,
|
||||||
|
product_id: p.id || p.value,
|
||||||
|
hs_code: p.hs_code || p.hsCode || '',
|
||||||
|
hsCode: p.hs_code || p.hsCode || '',
|
||||||
|
product_name: p.product_name || p.productName || p.label || '',
|
||||||
|
productName: p.product_name || p.productName || p.label || '',
|
||||||
|
label: p.product_name || p.productName || p.label || '',
|
||||||
|
value: p.id || p.value
|
||||||
|
}));
|
||||||
|
|
||||||
|
setAvailableProducts(formattedProducts);
|
||||||
|
return formattedProducts;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error loading products:', error);
|
||||||
|
return [];
|
||||||
|
} finally {
|
||||||
|
setIsLoadingProducts(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Product search handler
|
||||||
|
const handleProductSearch = (e) => {
|
||||||
|
const searchTerm = e.target.value.toLowerCase();
|
||||||
|
setProductSearchTerm(searchTerm);
|
||||||
|
|
||||||
|
if (!searchTerm) {
|
||||||
|
setAvailableProducts(prev => prev.filter(p =>
|
||||||
|
!selectedProducts.some(sp => sp.id === p.id)
|
||||||
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const filtered = availableProducts.filter(product =>
|
||||||
setLoading(true);
|
(product.label?.toLowerCase().includes(searchTerm) ||
|
||||||
const response = await fetchEstablishmentDetail(establishmentId);
|
product.hs_code?.toLowerCase().includes(searchTerm)) &&
|
||||||
|
!selectedProducts.some(sp => sp.id === product.id)
|
||||||
|
);
|
||||||
|
|
||||||
if (!response) {
|
setAvailableProducts(filtered);
|
||||||
console.error('Empty response received');
|
};
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mappedProfile = mapApiEstablishmentToProfile(response);
|
// Add product handler
|
||||||
|
const handleAddProduct = (product) => {
|
||||||
|
setSelectedProducts(prev => {
|
||||||
|
const updated = [...prev, product];
|
||||||
|
return updated;
|
||||||
|
});
|
||||||
|
|
||||||
const formData = {
|
// Remove from available products
|
||||||
...createEmptyProfile(),
|
setAvailableProducts(prev => prev.filter(p => p.id !== product.id));
|
||||||
...mappedProfile,
|
};
|
||||||
apiId: establishmentId,
|
|
||||||
corporateSameAs: Boolean(mappedProfile.corporateSameAs)
|
|
||||||
};
|
|
||||||
|
|
||||||
if (formData.corporateSameAs) {
|
// Remove product handler
|
||||||
Object.entries(contactToCorporateMap).forEach(([source, target]) => {
|
const handleRemoveProduct = (product) => {
|
||||||
formData[target] = formData[source];
|
setSelectedProducts(prev => prev.filter(p => p.id !== product.id));
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const totals = computeEmploymentTotals(formData);
|
// Add back to available products if not already there and matches search
|
||||||
Object.assign(formData, totals);
|
if (!productSearchTerm ||
|
||||||
|
(product.hs_code && product.hs_code.toLowerCase().includes(productSearchTerm)) ||
|
||||||
setForm(formData);
|
(product.product_name && product.product_name.toLowerCase().includes(productSearchTerm))) {
|
||||||
initialSnapshotRef.current = formData;
|
setAvailableProducts(prev => {
|
||||||
corporateBackupRef.current = captureCorporateValues(formData);
|
if (!prev.some(p => p.id === product.id)) {
|
||||||
|
return [...prev, product];
|
||||||
} catch (error) {
|
}
|
||||||
console.error('Failed to load establishment details:', error);
|
return prev;
|
||||||
alert('Failed to load company details. Please try again.');
|
});
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchData();
|
useEffect(() => {
|
||||||
}, [establishmentId]);
|
console.log('useEffect triggered, establishmentId:', establishmentId);
|
||||||
|
|
||||||
|
const fetchData = async () => {
|
||||||
|
if (!establishmentId) {
|
||||||
|
console.log('No establishmentId found, skipping fetch');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
console.log('Starting API call to fetch establishment details for ID:', establishmentId);
|
||||||
|
|
||||||
|
const response = await fetchEstablishmentDetail(establishmentId);
|
||||||
|
console.log('API Response received:', response);
|
||||||
|
|
||||||
|
if (!response) {
|
||||||
|
console.error('Empty response received');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mappedProfile = mapApiEstablishmentToProfile(response);
|
||||||
|
console.log('Mapped Profile:', mappedProfile);
|
||||||
|
|
||||||
|
const formData = {
|
||||||
|
...createEmptyProfile(),
|
||||||
|
...mappedProfile,
|
||||||
|
apiId: establishmentId
|
||||||
|
};
|
||||||
|
|
||||||
|
const totals = computeEmploymentTotals(formData);
|
||||||
|
Object.assign(formData, totals);
|
||||||
|
|
||||||
|
console.log('Final Form Data:', formData);
|
||||||
|
|
||||||
|
setForm(formData);
|
||||||
|
initialSnapshotRef.current = formData;
|
||||||
|
|
||||||
|
// Load products and set selected products
|
||||||
|
const allProducts = await loadProducts();
|
||||||
|
|
||||||
|
// Set selected products from API response
|
||||||
|
const establishmentProducts = response.data?.establishment_products || response.establishment_products || [];
|
||||||
|
if (Array.isArray(establishmentProducts) && establishmentProducts.length > 0) {
|
||||||
|
const formattedSelectedProducts = establishmentProducts.map(ep => {
|
||||||
|
const productData = ep.product || {};
|
||||||
|
return {
|
||||||
|
id: ep.id || 0,
|
||||||
|
product_id: ep.product_id || 0,
|
||||||
|
hs_code: productData.hs_code || ep.hs_code || '',
|
||||||
|
hsCode: productData.hs_code || ep.hs_code || '',
|
||||||
|
product_name: productData.product_name || ep.product_name || 'Unnamed Product',
|
||||||
|
productName: productData.product_name || ep.product_name || 'Unnamed Product',
|
||||||
|
label: `${productData.product_name || ep.product_name || 'Unnamed Product'}${productData.hs_code ? ` (${productData.hs_code})` : ''}`,
|
||||||
|
value: ep.product_id ? String(ep.product_id) : '',
|
||||||
|
...productData
|
||||||
|
};
|
||||||
|
});
|
||||||
|
setSelectedProducts(formattedSelectedProducts);
|
||||||
|
|
||||||
|
// Remove selected products from available products
|
||||||
|
setAvailableProducts(prev =>
|
||||||
|
prev.filter(p => !formattedSelectedProducts.some(sp => sp.id === p.id))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to load establishment details:', error);
|
||||||
|
alert('Failed to load company details. Please try again.');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchData();
|
||||||
|
}, [establishmentId, loadProducts]);
|
||||||
|
|
||||||
// Load emirates on component mount
|
// Load emirates on component mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -391,19 +442,6 @@ useEffect(() => {
|
|||||||
loadContactCities();
|
loadContactCities();
|
||||||
}, [form.contactEmirateId, loadCities]);
|
}, [form.contactEmirateId, loadCities]);
|
||||||
|
|
||||||
// Load corporate cities when emirate ID changes
|
|
||||||
useEffect(() => {
|
|
||||||
const loadCorporateCities = async () => {
|
|
||||||
if (form.corporateEmirateId) {
|
|
||||||
await loadCities(form.corporateEmirateId, setCorporateCityOptions);
|
|
||||||
} else {
|
|
||||||
setCorporateCityOptions([]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
loadCorporateCities();
|
|
||||||
}, [form.corporateEmirateId, loadCities]);
|
|
||||||
|
|
||||||
// Calculate totals when employment numbers change
|
// Calculate totals when employment numbers change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const totals = computeEmploymentTotals(form);
|
const totals = computeEmploymentTotals(form);
|
||||||
@ -418,34 +456,9 @@ useEffect(() => {
|
|||||||
form.employmentNonEmiratiFemale
|
form.employmentNonEmiratiFemale
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Handle corporate same as establishment checkbox
|
|
||||||
const handleCorporateSameAsChange = useCallback((checked) => {
|
|
||||||
if (checked) {
|
|
||||||
// Save current corporate values before overwriting
|
|
||||||
corporateBackupRef.current = captureCorporateValues(form);
|
|
||||||
|
|
||||||
// Copy contact details to corporate
|
|
||||||
const corporateUpdates = { corporateSameAs: true };
|
|
||||||
Object.entries(contactToCorporateMap).forEach(([source, target]) => {
|
|
||||||
corporateUpdates[target] = form[source];
|
|
||||||
});
|
|
||||||
|
|
||||||
setForm(prev => ({
|
|
||||||
...prev,
|
|
||||||
...corporateUpdates
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
// Restore original corporate values
|
|
||||||
setForm(prev => ({
|
|
||||||
...prev,
|
|
||||||
corporateSameAs: false,
|
|
||||||
...(corporateBackupRef.current || {})
|
|
||||||
}));
|
|
||||||
corporateBackupRef.current = null;
|
|
||||||
}
|
|
||||||
}, [form]);
|
|
||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
|
console.log("Submitted data:", form);
|
||||||
|
console.log("Selected products:", selectedProducts);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@ -461,8 +474,6 @@ useEffect(() => {
|
|||||||
establishment_address: form.contactAddress || "",
|
establishment_address: form.contactAddress || "",
|
||||||
establishment_city_town_id: form.contactCityTownId ? Number(form.contactCityTownId) : null,
|
establishment_city_town_id: form.contactCityTownId ? Number(form.contactCityTownId) : null,
|
||||||
establishment_emirate_id: form.contactEmirateId ? Number(form.contactEmirateId) : null,
|
establishment_emirate_id: form.contactEmirateId ? Number(form.contactEmirateId) : null,
|
||||||
corporate_city_town_id: form.corporateCityTownId ? Number(form.corporateCityTownId) : null,
|
|
||||||
corporate_emirate_id: form.corporateEmirateId ? Number(form.corporateEmirateId) : null,
|
|
||||||
establishment_postal_code: form.contactPostalCode || "",
|
establishment_postal_code: form.contactPostalCode || "",
|
||||||
establishment_po_box: form.contactPoBox || "",
|
establishment_po_box: form.contactPoBox || "",
|
||||||
establishment_makani_number: form.contactMakaniNumber || "",
|
establishment_makani_number: form.contactMakaniNumber || "",
|
||||||
@ -471,17 +482,6 @@ useEffect(() => {
|
|||||||
establishment_mobile_number: form.contactMobileNumber || "",
|
establishment_mobile_number: form.contactMobileNumber || "",
|
||||||
establishment_contact_email: form.contactEmail || "",
|
establishment_contact_email: form.contactEmail || "",
|
||||||
establishment_website: form.contactWebsite || "",
|
establishment_website: form.contactWebsite || "",
|
||||||
corporate_same_as_establishment: Boolean(form.corporateSameAs),
|
|
||||||
corporate_name: form.corporateName || "",
|
|
||||||
corporate_address: form.corporateAddress || "",
|
|
||||||
corporate_postal_code: form.corporatePostalCode || "",
|
|
||||||
corporate_po_box: form.corporatePoBox || "",
|
|
||||||
corporate_makani_number: form.corporateMakaniNumber || "",
|
|
||||||
corporate_contact_person_name: form.corporateContactPersonName || "",
|
|
||||||
corporate_contact_person_designation: form.corporateContactPersonDesignation || "",
|
|
||||||
corporate_mobile_number: form.corporateMobileNumber || "",
|
|
||||||
corporate_email: form.corporateEmail || "",
|
|
||||||
corporate_website: form.corporateWebsite || "",
|
|
||||||
emirati_male: Number(form.employmentEmiratiMale) || 0,
|
emirati_male: Number(form.employmentEmiratiMale) || 0,
|
||||||
emirati_female: Number(form.employmentEmiratiFemale) || 0,
|
emirati_female: Number(form.employmentEmiratiFemale) || 0,
|
||||||
non_emirati_male: Number(form.employmentNonEmiratiMale) || 0,
|
non_emirati_male: Number(form.employmentNonEmiratiMale) || 0,
|
||||||
@ -495,12 +495,20 @@ useEffect(() => {
|
|||||||
(Number(form.employmentNonEmiratiMale) || 0) +
|
(Number(form.employmentNonEmiratiMale) || 0) +
|
||||||
(Number(form.employmentNonEmiratiFemale) || 0),
|
(Number(form.employmentNonEmiratiFemale) || 0),
|
||||||
updated_by: 1,
|
updated_by: 1,
|
||||||
|
establishment_products: Array.isArray(selectedProducts) && selectedProducts.length > 0
|
||||||
|
? selectedProducts.map(p => ({
|
||||||
|
product_id: p.product_id || p.id || 0
|
||||||
|
}))
|
||||||
|
: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log("Payload sent:", establishmentData);
|
||||||
|
|
||||||
if (establishmentId) {
|
if (establishmentId) {
|
||||||
|
console.log("Updating establishment with ID:", establishmentId);
|
||||||
await updateEstablishment(establishmentId, establishmentData);
|
await updateEstablishment(establishmentId, establishmentData);
|
||||||
onClose();
|
console.log("Profile updated successfully!");
|
||||||
|
navigate('/survey');
|
||||||
} else {
|
} else {
|
||||||
console.error("No establishment ID provided for update");
|
console.error("No establishment ID provided for update");
|
||||||
alert("Error: No establishment ID provided for update");
|
alert("Error: No establishment ID provided for update");
|
||||||
@ -760,184 +768,106 @@ useEffect(() => {
|
|||||||
);
|
);
|
||||||
case 3:
|
case 3:
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-6">
|
||||||
<div className="flex flex-col gap-2 md:flex-row md:items-center md:justify-between">
|
<h4 className="text-[16px] font-semibold text-[#232528]">Products</h4>
|
||||||
<div>
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||||
<h4 className="text-[16px] font-semibold text-[#232528]">Corporate/Head Office Contact</h4>
|
{/* Available Products Panel */}
|
||||||
|
<div className="bg-white rounded-lg border border-[#E5E7EB] overflow-hidden">
|
||||||
|
<div className="bg-[#F9FAFB] px-4 py-3 border-b border-[#E5E7EB]">
|
||||||
|
<h5 className="text-sm font-medium text-[#111827]">Available Products</h5>
|
||||||
|
</div>
|
||||||
|
<div className="p-4">
|
||||||
|
<div className="relative mb-4">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Search products..."
|
||||||
|
value={productSearchTerm}
|
||||||
|
onChange={handleProductSearch}
|
||||||
|
className="w-full px-3 py-2 border border-[#D1D5DB] rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-[#92722A] focus:border-transparent"
|
||||||
|
/>
|
||||||
|
<svg
|
||||||
|
className="absolute right-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div className="border border-[#E5E7EB] rounded-md overflow-hidden">
|
||||||
|
{isLoadingProducts ? (
|
||||||
|
<div className="flex justify-center items-center p-4">
|
||||||
|
<div className="animate-spin rounded-full h-6 w-6 border-b-2 border-[#92722A]"></div>
|
||||||
|
</div>
|
||||||
|
) : availableProducts.length > 0 ? (
|
||||||
|
<ul className="divide-y divide-[#E5E7EB] max-h-96 overflow-y-auto">
|
||||||
|
{availableProducts.map((product) => (
|
||||||
|
<li key={product.id} className="p-3 hover:bg-[#F9FAFB] flex justify-between items-center">
|
||||||
|
<div>
|
||||||
|
<div className="text-sm font-medium text-[#111827]">
|
||||||
|
{product.hsCode || ''}
|
||||||
|
{product.hsCode && (product.productName || product.label || product.product_name) ? ' - ' : ''}
|
||||||
|
{product.productName || product.label || product.product_name || ''}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => handleAddProduct(product)}
|
||||||
|
className="text-[#92722A] hover:text-[#7A5F1E] text-sm font-medium"
|
||||||
|
>
|
||||||
|
Add
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
) : (
|
||||||
|
<div className="p-4 text-center text-sm text-[#6B7280]">
|
||||||
|
{productSearchTerm ? 'No matching products found' : 'No products available'}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<label className="inline-flex items-center gap-2 text-sm text-[#232528]">
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
checked={form.corporateSameAs}
|
|
||||||
onChange={(e) => handleCorporateSameAsChange(e.target.checked)}
|
|
||||||
className="h-4 w-4 rounded border-2 border-[#CBA344] text-[#92722A] focus:ring-[#92722A]"
|
|
||||||
/>
|
|
||||||
Same as Establishment Contact
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
|
|
||||||
<TextField
|
|
||||||
label="Name"
|
|
||||||
value={form.corporateName || ""}
|
|
||||||
onChange={(e) => handleFormChange("corporateName", e.target.value)}
|
|
||||||
placeholder="Enter Name"
|
|
||||||
width="100%"
|
|
||||||
required
|
|
||||||
disabled={form.corporateSameAs}
|
|
||||||
error={fieldErrors.corporateName}
|
|
||||||
/>
|
|
||||||
<TextField
|
|
||||||
label="Address"
|
|
||||||
value={form.corporateAddress || ""}
|
|
||||||
onChange={(e) => handleFormChange("corporateAddress", e.target.value)}
|
|
||||||
placeholder="Enter Address"
|
|
||||||
width="100%"
|
|
||||||
required
|
|
||||||
disabled={form.corporateSameAs}
|
|
||||||
error={fieldErrors.corporateAddress}
|
|
||||||
/>
|
|
||||||
{form.corporateSameAs ? (
|
|
||||||
<>
|
|
||||||
<TextField
|
|
||||||
label="Emirate"
|
|
||||||
value={form.contactEmirate || ""}
|
|
||||||
disabled={true}
|
|
||||||
width="100%"
|
|
||||||
/>
|
|
||||||
<TextField
|
|
||||||
label="City/Town"
|
|
||||||
value={form.contactCityTown || ""}
|
|
||||||
disabled={true}
|
|
||||||
width="100%"
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<SelectField
|
|
||||||
label="Emirate"
|
|
||||||
name="corporateEmirate"
|
|
||||||
value={form.corporateEmirateId || ""}
|
|
||||||
onChange={async (e) => {
|
|
||||||
const selectedValue = e.target.value;
|
|
||||||
const selectedEmirate = emirateOptions.find(opt => opt.value === selectedValue);
|
|
||||||
|
|
||||||
handleFormChange("corporateEmirate", selectedEmirate?.name || '');
|
{/* Selected Products Panel */}
|
||||||
handleFormChange("corporateEmirateId", selectedEmirate?.id || '');
|
<div className="bg-white rounded-lg border border-[#E5E7EB] overflow-hidden">
|
||||||
handleFormChange("corporateCityTown", '');
|
<div className="bg-[#F9FAFB] px-4 py-3 border-b border-[#E5E7EB] flex justify-between items-center">
|
||||||
handleFormChange("corporateCityTownId", '');
|
<h5 className="text-sm font-medium text-[#111827]">Selected Products</h5>
|
||||||
|
{selectedProducts.length > 0 && (
|
||||||
if (selectedEmirate?.id) {
|
<span className="bg-[#FEF3C7] text-[#92400E] text-xs font-medium px-2 py-0.5 rounded-full">
|
||||||
const cities = await loadCities(selectedEmirate.id, setCorporateCityOptions);
|
{selectedProducts.length} selected
|
||||||
setCorporateCityOptions(cities);
|
</span>
|
||||||
} else {
|
)}
|
||||||
setCorporateCityOptions([]);
|
</div>
|
||||||
}
|
<div className="p-4">
|
||||||
}}
|
{selectedProducts.length > 0 ? (
|
||||||
options={emirateOptions.map(opt => ({
|
<ul className="divide-y divide-[#E5E7EB] max-h-96 overflow-y-auto">
|
||||||
value: opt.value,
|
{selectedProducts.map((product) => (
|
||||||
label: opt.label
|
<li key={product.id} className="p-3 hover:bg-[#F9FAFB] flex justify-between items-center">
|
||||||
}))}
|
<div>
|
||||||
placeholder="Select Emirate"
|
<div className="text-sm font-medium text-[#111827]">
|
||||||
width="100%"
|
{product.hs_code || product.hsCode || ''}
|
||||||
required
|
{product.hs_code || product.hsCode ? ' - ' : ''}
|
||||||
error={fieldErrors.corporateEmirate}
|
{product.product_name || product.productName || product.label || 'Unnamed Product'}
|
||||||
/>
|
</div>
|
||||||
<SelectField
|
</div>
|
||||||
label="City/Town"
|
<button
|
||||||
name="corporateCityTown"
|
type="button"
|
||||||
value={form.corporateCityTownId || ''}
|
onClick={() => handleRemoveProduct(product)}
|
||||||
onChange={(e) => {
|
className="text-[#EF4444] hover:text-[#DC2626] text-sm font-medium"
|
||||||
const selectedValue = e.target.value;
|
>
|
||||||
const selectedCity = corporateCityOptions.find(opt => opt.value === selectedValue);
|
Remove
|
||||||
if (selectedCity) {
|
</button>
|
||||||
handleFormChange("corporateCityTown", selectedCity.value);
|
</li>
|
||||||
}
|
))}
|
||||||
}}
|
</ul>
|
||||||
options={corporateCityOptions.map(opt => ({
|
) : (
|
||||||
value: opt.value,
|
<div className="p-4 text-center text-sm text-[#6B7280] border border-[#E5E7EB] rounded-md">
|
||||||
label: opt.label
|
No products selected
|
||||||
}))}
|
</div>
|
||||||
placeholder={form.corporateEmirateId ? "Select City/Town" : "Select emirate first"}
|
)}
|
||||||
width="100%"
|
</div>
|
||||||
required
|
</div>
|
||||||
disabled={!form.corporateEmirateId}
|
|
||||||
error={fieldErrors.corporateCityTown}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<TextField
|
|
||||||
label="Postal Code"
|
|
||||||
value={form.corporatePostalCode || ""}
|
|
||||||
onChange={(e) => handleFormChange("corporatePostalCode", e.target.value)}
|
|
||||||
placeholder="Enter Postal Code"
|
|
||||||
width="100%"
|
|
||||||
disabled={form.corporateSameAs}
|
|
||||||
/>
|
|
||||||
<TextField
|
|
||||||
label="PO Box"
|
|
||||||
value={form.corporatePoBox || ""}
|
|
||||||
onChange={(e) => handleFormChange("corporatePoBox", e.target.value)}
|
|
||||||
placeholder="Enter P.O. Box"
|
|
||||||
width="100%"
|
|
||||||
disabled={form.corporateSameAs}
|
|
||||||
/>
|
|
||||||
<TextField
|
|
||||||
label="Makani Number"
|
|
||||||
value={form.corporateMakaniNumber || ""}
|
|
||||||
onChange={(e) => handleFormChange("corporateMakaniNumber", e.target.value)}
|
|
||||||
placeholder="Enter Makani Number"
|
|
||||||
width="100%"
|
|
||||||
required
|
|
||||||
disabled={form.corporateSameAs}
|
|
||||||
error={fieldErrors.corporateMakaniNumber}
|
|
||||||
/>
|
|
||||||
<TextField
|
|
||||||
label="Contact Person Name"
|
|
||||||
value={form.corporateContactPersonName || ""}
|
|
||||||
onChange={(e) => handleFormChange("corporateContactPersonName", e.target.value)}
|
|
||||||
placeholder="Enter Contact Person Name"
|
|
||||||
width="100%"
|
|
||||||
required
|
|
||||||
disabled={form.corporateSameAs}
|
|
||||||
error={fieldErrors.corporateContactPersonName}
|
|
||||||
/>
|
|
||||||
<TextField
|
|
||||||
label="Contact Person Designation"
|
|
||||||
value={form.corporateContactPersonDesignation || ""}
|
|
||||||
onChange={(e) => handleFormChange("corporateContactPersonDesignation", e.target.value)}
|
|
||||||
placeholder="Enter contact person designation"
|
|
||||||
width="100%"
|
|
||||||
disabled={form.corporateSameAs}
|
|
||||||
/>
|
|
||||||
<PhoneField
|
|
||||||
label="Mobile Number"
|
|
||||||
value={form.corporateMobileNumber || ""}
|
|
||||||
onChange={(value) => handleFormChange("corporateMobileNumber", value)}
|
|
||||||
placeholder="Enter Mobile Number"
|
|
||||||
width="100%"
|
|
||||||
required
|
|
||||||
disabled={form.corporateSameAs}
|
|
||||||
error={fieldErrors.corporateMobileNumber}
|
|
||||||
/>
|
|
||||||
<TextField
|
|
||||||
label="Email"
|
|
||||||
value={form.corporateEmail || ""}
|
|
||||||
onChange={(e) => handleFormChange("corporateEmail", e.target.value)}
|
|
||||||
placeholder="Enter Email"
|
|
||||||
width="100%"
|
|
||||||
type="email"
|
|
||||||
required
|
|
||||||
disabled={form.corporateSameAs}
|
|
||||||
error={fieldErrors.corporateEmail}
|
|
||||||
/>
|
|
||||||
<TextField
|
|
||||||
label="Website"
|
|
||||||
value={form.corporateWebsite || ""}
|
|
||||||
onChange={(e) => handleFormChange("corporateWebsite", e.target.value)}
|
|
||||||
placeholder="Enter Website"
|
|
||||||
width="100%"
|
|
||||||
disabled={form.corporateSameAs}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -1013,118 +943,128 @@ useEffect(() => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
|
<div className="min-h-screen bg-[#F8FAFC]">
|
||||||
<div className="bg-white w-full max-w-7xl rounded-xl shadow-2xl overflow-hidden flex flex-col h-[75vh]">
|
<HeaderBar />
|
||||||
{loading && <Loader />}
|
|
||||||
|
|
||||||
{/* Header */}
|
<div className="container mx-auto px-4 py-8">
|
||||||
<div className="flex justify-between items-center border-b border-[#F1F2F4] px-8 py-5 bg-white sticky top-0 z-10">
|
<div className="bg-white rounded-xl shadow-lg overflow-hidden">
|
||||||
<div>
|
{loading && <Loader />}
|
||||||
<h2 className="text-xl font-bold text-gray-900">Edit Company Profile</h2>
|
|
||||||
|
{/* Header */}
|
||||||
|
<div className="flex justify-between items-center border-b border-[#F1F2F4] px-8 py-5 bg-white">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-xl font-bold text-gray-900">Edit Company Profile</h2>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button
|
|
||||||
onClick={onClose}
|
|
||||||
className="flex h-7 w-7 text-lg items-center justify-center rounded hover:bg-gray-100 hover:bg-opacity-10 text-[#92722A] hover:text-[#92722A] transition-colors"
|
|
||||||
aria-label="Close"
|
|
||||||
>
|
|
||||||
×
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Body */}
|
{/* Body */}
|
||||||
<div className="flex flex-1 overflow-hidden">
|
<div className="flex flex-1">
|
||||||
<aside className="w-64 bg-[#F9FAFB] border-r border-[#E5E7EB] overflow-y-auto" style={{ maxHeight: 'calc(75vh - 120px)' }}>
|
<aside className="w-64 bg-[#F9FAFB] border-r border-[#E5E7EB]">
|
||||||
<ol className="py-6 px-4 space-y-2">
|
<ol className="py-6 px-4 space-y-2">
|
||||||
{formSteps.map((step, index) => {
|
{formSteps.map((step, index) => {
|
||||||
const isActive = index === activeStep;
|
const isActive = index === activeStep;
|
||||||
const isCompleted = index < activeStep;
|
const isCompleted = index < activeStep;
|
||||||
return (
|
return (
|
||||||
<li key={step.label}>
|
<li key={step.label}>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setActiveStep(index)}
|
onClick={() => setActiveStep(index)}
|
||||||
className={`w-full flex items-center gap-3 rounded-md px-3 py-3 text-left transition-colors ${
|
className={`w-full flex items-center gap-3 rounded-md px-3 py-3 text-left transition-colors ${
|
||||||
isActive
|
|
||||||
? 'bg-[#92722A] text-white shadow-[0_8px_18px_rgba(146,114,42,0.22)]'
|
|
||||||
: 'bg-transparent text-[#1F2937] hover:bg-[#F3F4F6]'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className={`flex h-8 w-8 shrink-0 items-center justify-center rounded-full border text-sm font-semibold ${
|
|
||||||
isActive
|
isActive
|
||||||
? 'border-[#FDF7E7] bg-[#FDF7E7] text-[#92722A]'
|
? 'bg-[#92722A] text-white shadow-[0_8px_18px_rgba(146,114,42,0.22)]'
|
||||||
: isCompleted
|
: 'bg-transparent text-[#1F2937] hover:bg-[#F3F4F6]'
|
||||||
? 'border-[#92722A] bg-[#FDF7E7] text-[#92722A]'
|
|
||||||
: 'border-[#D1D5DB] text-[#6B7280]'
|
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{index + 1}
|
<span
|
||||||
</span>
|
className={`flex h-8 w-8 shrink-0 items-center justify-center rounded-full border text-sm font-semibold ${
|
||||||
<span className="flex-1">
|
isActive
|
||||||
<span className={`block text-[15px] font-semibold ${isActive ? 'text-white' : 'text-[#111827]'}`}>
|
? 'border-[#FDF7E7] bg-[#FDF7E7] text-[#92722A]'
|
||||||
{step.label}
|
: isCompleted
|
||||||
|
? 'border-[#92722A] bg-[#FDF7E7] text-[#92722A]'
|
||||||
|
: 'border-[#D1D5DB] text-[#6B7280]'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{index + 1}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
<span className="flex-1">
|
||||||
</button>
|
<span className={`block text-[15px] font-semibold ${isActive ? 'text-white' : 'text-[#111827]'}`}>
|
||||||
</li>
|
{step.label}
|
||||||
);
|
</span>
|
||||||
})}
|
</span>
|
||||||
</ol>
|
</button>
|
||||||
</aside>
|
</li>
|
||||||
<div className="flex-1 overflow-y-auto" style={{ maxHeight: 'calc(85vh - 120px)' }}>
|
);
|
||||||
<div className="px-6 py-6">
|
})}
|
||||||
{renderStepContent()}
|
</ol>
|
||||||
|
</aside>
|
||||||
|
<div className="flex-1">
|
||||||
|
<div className="px-6 py-6">
|
||||||
|
{renderStepContent()}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Footer */}
|
{/* Footer */}
|
||||||
<div className="border-t border-[#F1F2F4] bg-white">
|
<div className="border-t border-[#F1F2F4] bg-white">
|
||||||
<div className="px-8 py-4 flex items-center justify-between gap-3">
|
<div className="px-8 py-4 flex items-center justify-between gap-3">
|
||||||
<div className="min-h-[1rem] flex items-center text-xs text-[#B45309]">
|
<div className="min-h-[1rem] flex items-center text-xs text-[#B45309]">
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<span className="inline-flex items-center gap-2">
|
<span className="inline-flex items-center gap-2">
|
||||||
<svg className="h-4 w-4 animate-spin text-[#92722A]" viewBox="0 0 24 24" fill="none">
|
<svg className="h-4 w-4 animate-spin text-[#92722A]" viewBox="0 0 24 24" fill="none">
|
||||||
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
||||||
<path
|
<path
|
||||||
className="opacity-75"
|
className="opacity-75"
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
d="M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z"
|
d="M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
<span>Saving profile…</span>
|
<span>Saving profile…</span>
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span> </span>
|
<span> </span>
|
||||||
)}
|
)}
|
||||||
</div>
|
|
||||||
{activeStep === formSteps.length - 1 ? (
|
|
||||||
<div className="flex items-center gap-3">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="inline-flex justify-center rounded-md border border-[#92722A] bg-white px-4 py-2 text-sm font-medium text-[#92722A] shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
|
|
||||||
onClick={() => onClose && onClose()}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className={`h-10 px-8 rounded-md bg-[#92722A] text-sm font-medium text-white shadow-[0_8px_18px_rgba(146,114,42,0.35)] ${loading ? 'opacity-60 cursor-not-allowed' : ''}`}
|
|
||||||
onClick={handleSave}
|
|
||||||
disabled={loading}
|
|
||||||
>
|
|
||||||
{loading ? 'Saving…' : 'Update'}
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
) : (
|
|
||||||
<button
|
<div className="flex items-center gap-3">
|
||||||
type="button"
|
{activeStep > 0 && (
|
||||||
className="h-10 px-8 rounded-md bg-[#92722A] text-sm font-medium text-white shadow-[0_8px_18px_rgba(146,114,42,0.35)]"
|
<button
|
||||||
onClick={handleNext}
|
type="button"
|
||||||
>
|
className="inline-flex justify-center rounded-md border border-[#92722A] bg-white px-4 py-2 text-sm font-medium text-[#92722A] shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
|
||||||
Next
|
onClick={handlePrev}
|
||||||
</button>
|
>
|
||||||
)}
|
Previous
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{activeStep === formSteps.length - 1 ? (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="inline-flex justify-center rounded-md border border-[#92722A] bg-white px-4 py-2 text-sm font-medium text-[#92722A] shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
|
||||||
|
onClick={() => navigate('/survey')}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`h-10 px-8 rounded-md bg-[#92722A] text-sm font-medium text-white shadow-[0_8px_18px_rgba(146,114,42,0.35)] ${loading ? 'opacity-60 cursor-not-allowed' : ''}`}
|
||||||
|
onClick={handleSave}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
{loading ? 'Saving…' : 'Update'}
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="h-10 px-8 rounded-md bg-[#92722A] text-sm font-medium text-white shadow-[0_8px_18px_rgba(146,114,42,0.35)]"
|
||||||
|
onClick={handleNext}
|
||||||
|
>
|
||||||
|
Next
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -1133,3 +1073,4 @@ useEffect(() => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default EditCompanyProfile;
|
export default EditCompanyProfile;
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -15,20 +15,33 @@ export const getUnits = async () => {
|
|||||||
|
|
||||||
export const createUnit = async (unitData) => {
|
export const createUnit = async (unitData) => {
|
||||||
try {
|
try {
|
||||||
|
// Log the data being sent for debugging
|
||||||
|
console.log('Creating unit with data:', unitData);
|
||||||
|
|
||||||
const response = await postRequest(UNIT_MASTER_ENDPOINT, unitData);
|
const response = await postRequest(UNIT_MASTER_ENDPOINT, unitData);
|
||||||
|
console.log('Unit created successfully:', response.data);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating unit:', 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;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateUnit = async (id, unitData) => {
|
export const updateUnit = async (id, unitData) => {
|
||||||
try {
|
try {
|
||||||
|
console.log('Updating unit with data:', unitData);
|
||||||
|
|
||||||
const response = await putRequest(`${UNIT_MASTER_ENDPOINT}/${id}`, unitData);
|
const response = await putRequest(`${UNIT_MASTER_ENDPOINT}/${id}`, unitData);
|
||||||
|
console.log('Unit updated successfully:', response.data);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating unit:', error);
|
console.error('Error updating unit:', error);
|
||||||
|
console.error('Error details:', error.response?.data);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -36,9 +49,25 @@ export const updateUnit = async (id, unitData) => {
|
|||||||
export const deleteUnit = async (id) => {
|
export const deleteUnit = async (id) => {
|
||||||
try {
|
try {
|
||||||
const response = await deleteRequest(`${UNIT_MASTER_ENDPOINT}/${id}`);
|
const response = await deleteRequest(`${UNIT_MASTER_ENDPOINT}/${id}`);
|
||||||
|
console.log('Unit deleted successfully:', response.data);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error deleting unit:', 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;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Loading…
Reference in New Issue
Block a user