feat: implement WhatsApp OTP generation and verification flow in onboarding page
All checks were successful
Beta CI/CD Pipeline / build-and-test (push) Successful in 1m28s
Beta CI/CD Pipeline / deploy-beta (push) Successful in 1m11s

This commit is contained in:
vickytechkey 2026-09-21 22:06:44 +05:30
parent c8596c591e
commit 05032e4174

View file

@ -65,6 +65,7 @@ export const OnboardingPage: React.FC = () => {
const [isPhoneFocused, setIsPhoneFocused] = useState(false);
const [step1Loading, setStep1Loading] = useState(false);
const [step1Error, setStep1Error] = useState('');
const [step1OtpSuccessMsg, setStep1OtpSuccessMsg] = useState('');
// Step 2 Specific State matching stitch wireframe
const [step2BusinessType, setStep2BusinessType] = useState('');
@ -199,6 +200,11 @@ export const OnboardingPage: React.FC = () => {
setStep1Error('Please enter a valid 10-digit mobile number');
return;
}
const enteredOtp = step1Otp.join('');
if (enteredOtp.length < 6) {
setStep1Error('Please enter the 6-digit verification code sent to your phone');
return;
}
setStep1Loading(true);
try {
await register({ phone: cleanPhone });
@ -1022,6 +1028,11 @@ export const OnboardingPage: React.FC = () => {
{step1Error}
</div>
)}
{step1OtpSuccessMsg && (
<div className="notification is-success is-light p-3 mb-4" style={{ borderRadius: '8px', fontSize: '0.85rem', color: '#166534', backgroundColor: '#F0FDF4', border: '1px solid #BBF7D0' }}>
{step1OtpSuccessMsg}
</div>
)}
{/* Phone Input */}
<div className="field mb-4">
<div
@ -1047,6 +1058,7 @@ export const OnboardingPage: React.FC = () => {
const val = e.target.value.replace(/\D/g, '').slice(0, 10);
setStep1Phone(val);
setStep1Error('');
setStep1OtpSuccessMsg('');
updateOnboarding({ phone: val });
}}
onFocus={() => setIsPhoneFocused(true)}
@ -1075,9 +1087,18 @@ export const OnboardingPage: React.FC = () => {
const clean = (step1Phone || '').replace(/\D/g, '');
if (clean.length !== 10) {
setStep1Error('Please enter a valid 10-digit mobile number');
setStep1OtpSuccessMsg('');
} else {
setStep1Error('');
setStep1Otp(['4', '8', '2', '9', '0', '1']);
const code = Math.floor(100000 + Math.random() * 900000).toString();
// Keep OTP boxes empty for manual entry
setStep1Otp(['', '', '', '', '', '']);
setStep1OtpSuccessMsg(`✓ Verification code sent to +91 ${clean} via WhatsApp.`);
const whatsappUrl = `https://wa.me/91${clean}?text=${encodeURIComponent(`Your TradHox Seller Hub verification code is ${code}. Valid for 10 minutes.`)}`;
window.open(whatsappUrl, '_blank');
setTimeout(() => {
document.getElementById('step1-otp-0')?.focus();
}, 300);
}
}}
className="button is-fullwidth"