diff --git a/ipi-survey-platform/src/pages/ChangePassword/ChangePassword.jsx b/ipi-survey-platform/src/pages/ChangePassword/ChangePassword.jsx index 06d66fc..1097fe5 100644 --- a/ipi-survey-platform/src/pages/ChangePassword/ChangePassword.jsx +++ b/ipi-survey-platform/src/pages/ChangePassword/ChangePassword.jsx @@ -59,7 +59,12 @@ const ChangePassword = () => { const navigate = useNavigate(); const location = useLocation(); - const registeredEmail = location.state?.email || ""; + const { email: registeredEmail, user_type: userType } = location.state || {}; + + // Ensure user_type is set in the form data + const [formData, setFormData] = React.useState({ + user_type: userType + }); const [otp, setOtp] = React.useState(""); const [newPassword, setNewPassword] = React.useState(""); @@ -132,6 +137,7 @@ if (newPassword !== confirmPassword) { otp: otp.trim(), password: newPassword, confirm_password: confirmPassword, + user_type: userType // Use the user_type from location state }; const response = await apiClient.post("/forgot-password/verify-otp", payload); @@ -197,6 +203,21 @@ if (newPassword !== confirmPassword) { /> +
+ +
+ + +
+
+ { - const [openIndex, setOpenIndex] = useState(null); - - const faqs = [ + const [openIndexLeft, setOpenIndexLeft] = useState(null); + const [openIndexRight, setOpenIndexRight] = useState(null); + + // FULL FAQ DATA + const leftFaqs = [ { question: "Do I need an account to respond?", answer: "Yes. FCSC provisions accounts to selected establishments. Use Login to access the survey.", }, - { - question: "Can I register myself?", - answer: - "No. There is no self-registration. If you were contacted but can’t access your account, use Forgot password or Contact support.", - }, { question: "Is my data public?", answer: "No. Results are published only in aggregate form.", }, - { - question: "What if production was zero in a month?", - answer: "Enter 0 for the month and provide a reason when prompted.", - }, { question: "Can I update after submission?", answer: "Yes, if a revision window is open or if FCSC requests a correction.", }, - { - question: "Which browser is supported?", - answer: "Latest Chrome, Edge, Safari.", - }, { question: "How long does it take?", answer: "Most respondents complete within minutes each quarter, depending on product lines.", }, + ]; + + const rightFaqs = [ + { + question: "Can I register myself?", + answer: + "No. There is no self-registration. If you were contacted but can’t access your account, use Forgot password or Contact support.", + }, + { + question: "What if production was zero in a month?", + answer: "Enter 0 for the month and provide a reason when prompted.", + }, + { + question: "Which browser is supported?", + answer: "Latest Chrome, Edge, Safari.", + }, { question: "Who can I contact?", answer: "See Need help below.", }, ]; - - const toggleFaq = (index) => { - setOpenIndex(openIndex === index ? null : index); + + // Auto height expand component + const Expandable = ({ isOpen, children }) => { + const ref = useRef(null); + + useEffect(() => { + if (isOpen) { + ref.current.style.maxHeight = ref.current.scrollHeight + "px"; + } else { + ref.current.style.maxHeight = "0px"; + } + }, [isOpen]); + + return ( +
+ {children} +
+ ); }; - + return (

Frequently asked questions

- -
- {faqs.map((faq, index) => { - const isOpen = openIndex === index; - return ( -
- - - {isOpen && ( -

- {faq.answer} -

- )} -
- ); - })} + + {faq.question} + + + {isOpen ? ( + + ) : ( + + )} + + + +

+ {faq.answer} +

+
+
+ ); + })} + + + {/* RIGHT COLUMN */} +
+ {rightFaqs.map((faq, index) => { + const isOpen = openIndexRight === index; + + return ( +
+ + + +

+ {faq.answer} +

+
+
+ ); + })} +
+
); }; - -export default Faq; + +export default Faq; \ No newline at end of file diff --git a/ipi-survey-platform/src/pages/PublicContactForm.jsx b/ipi-survey-platform/src/pages/PublicContactForm.jsx index 48b6e2d..96775ca 100644 --- a/ipi-survey-platform/src/pages/PublicContactForm.jsx +++ b/ipi-survey-platform/src/pages/PublicContactForm.jsx @@ -8,6 +8,7 @@ const PublicContactForm = () => { const navigate = useNavigate(); const [formData, setFormData] = useState({ + userType: "establishment_user", establishmentName: "", establishmentId: "", email: "", @@ -74,7 +75,13 @@ const PublicContactForm = () => { const validate = (data = formData) => { const newErrors = {}; - if (!data.establishmentName.trim()) newErrors.establishmentName = "Required."; + if (!data.userType) { + newErrors.userType = "Please select user type"; + } else if (data.userType === 'establishment_user') { + if (!data.establishmentName.trim()) newErrors.establishmentName = "Required."; + if (!data.establishmentId.trim()) newErrors.establishmentId = "Required."; + } + if (!data.email.trim()) newErrors.email = "Required."; else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email)) newErrors.email = "Enter a valid email address."; @@ -113,6 +120,7 @@ const PublicContactForm = () => { setLoading(true); try { const payload = { + user_type: formData.userType, establishment_name: formData.establishmentName.trim(), establishment_code: formData.establishmentId.trim(), registered_email: formData.email.trim(), @@ -124,7 +132,10 @@ const PublicContactForm = () => { showToast('success', 'Verification Code sent to your registered email successfully!'); setTimeout(() => { navigate("/change-password", { - state: { email: formData.email.trim() }, + state: { + email: formData.email.trim(), + user_type: formData.userType + }, }); }, 1500); } else { @@ -156,13 +167,19 @@ const PublicContactForm = () => { const payload = { registered_email: formData.email.trim(), otp: otp.trim(), + user_type: formData.userType // Add user_type to the verification request }; const response = await apiClient.post("/forgot-password/verify-otp", payload); if (response?.data?.status === "success") { setSuccess("Verification Code verified successfully. Redirecting to change password..."); - setTimeout(() => navigate("/change-password"), 1500); + setTimeout(() => navigate("/change-password", { + state: { + email: formData.email.trim(), + user_type: formData.userType // Ensure user_type is passed + } + }), 1500); } else { const serverMsg = response?.data?.message?.toLowerCase() || ""; @@ -240,27 +257,74 @@ const PublicContactForm = () => { {errorMsg} )} + +
+ + + {errors.userType && ( +

{errors.userType}

+ )} +
{success && (
{success}
)} - - + {formData.userType === 'establishment_user' && ( +
+
+ + + {errors.establishmentName && ( +

{errors.establishmentName}

+ )} +
+ +
+ + + {errors.establishmentId && ( +

{errors.establishmentId}

+ )} +
+
+ )} +