feat: complete tickets & vet consultation, fix wallet balance overflow, b2b toggle, and transaction manual verification
Deploy Canina / deploy (push) Successful in 1m51s
Deploy Canina / deploy (push) Successful in 1m51s
This commit is contained in:
1 parent
1aa9d6e34d
commit
42707c04cf
24 files changed
+1856
-139
No files matched your search
@@ -17,6 +17,7 @@ import {
|
||||
EyeOff,
|
||||
} from "lucide-react";
|
||||
import { useUserStore } from "../lib/store/userStore";
|
||||
import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
import { authService } from "../lib/services/authService";
|
||||
import { toast } from "sonner";
|
||||
import { toPersian, toEnglishDigits } from "../lib/utils";
|
||||
@@ -26,6 +27,14 @@ interface AuthModalProps {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
function extractOtpFromText(text: string): string {
|
||||
if (!text) return "";
|
||||
const clean = toEnglishDigits(text);
|
||||
const match = clean.match(/(\d{5})/);
|
||||
if (match) return match[1];
|
||||
return clean.replace(/[^0-9]/g, "").slice(0, 5);
|
||||
}
|
||||
|
||||
export default function AuthModal({ isOpen, onClose }: AuthModalProps) {
|
||||
const { fetchProfile } = useUserStore();
|
||||
const [view, setView] = useState<
|
||||
@@ -59,12 +68,17 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) {
|
||||
phoneNumberRef.current = phoneNumber;
|
||||
}, [phoneNumber]);
|
||||
|
||||
// Robust focus retry on view === "otp"
|
||||
useEffect(() => {
|
||||
if (view === "otp") {
|
||||
const timer = setTimeout(() => {
|
||||
otpInputRef.current?.focus();
|
||||
}, 100);
|
||||
return () => clearTimeout(timer);
|
||||
const timers = [50, 150, 300, 500].map((delay) =>
|
||||
setTimeout(() => {
|
||||
if (otpInputRef.current) {
|
||||
otpInputRef.current.focus({ preventScroll: true });
|
||||
}
|
||||
}, delay),
|
||||
);
|
||||
return () => timers.forEach((t) => clearTimeout(t));
|
||||
}
|
||||
}, [view]);
|
||||
|
||||
@@ -98,7 +112,7 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) {
|
||||
|
||||
const triggerVerifyOtp = useCallback(
|
||||
async (codeToVerify: string) => {
|
||||
const cleanCode = toEnglishDigits(codeToVerify).replace(/[^0-9]/g, "").slice(0, 5);
|
||||
const cleanCode = extractOtpFromText(codeToVerify);
|
||||
const cleanPhone = toEnglishDigits(phoneNumberRef.current).replace(/[^0-9]/g, "");
|
||||
if (cleanCode.length !== 5 || !cleanPhone) return;
|
||||
|
||||
@@ -136,7 +150,7 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) {
|
||||
.then((otp) => {
|
||||
if (!isMounted) return;
|
||||
if (otp && typeof otp.code === "string") {
|
||||
const clean = toEnglishDigits(otp.code).replace(/[^0-9]/g, "").slice(0, 5);
|
||||
const clean = extractOtpFromText(otp.code);
|
||||
if (clean) {
|
||||
setOtpCode(clean);
|
||||
if (otpInputRef.current) {
|
||||
@@ -156,7 +170,7 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) {
|
||||
const handleDomAutofill = (e: Event) => {
|
||||
const target = e.target as HTMLInputElement;
|
||||
if (target && target.value) {
|
||||
const clean = toEnglishDigits(target.value).replace(/[^0-9]/g, "").slice(0, 5);
|
||||
const clean = extractOtpFromText(target.value);
|
||||
setOtpCode(clean);
|
||||
if (clean.length === 5) {
|
||||
triggerVerifyOtp(clean);
|
||||
@@ -180,9 +194,9 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) {
|
||||
}, [view, triggerVerifyOtp]);
|
||||
|
||||
const handleOtpChange = (val: string) => {
|
||||
const clean = toEnglishDigits(val).replace(/[^0-9]/g, "").slice(0, 5);
|
||||
const clean = extractOtpFromText(val);
|
||||
setOtpCode(clean);
|
||||
if (otpInputRef.current) {
|
||||
if (otpInputRef.current && otpInputRef.current.value !== clean) {
|
||||
otpInputRef.current.value = clean;
|
||||
}
|
||||
if (clean.length === 5) {
|
||||
@@ -469,16 +483,18 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pt-3 border-t border-medical-gray-100">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setView("wholesale-request")}
|
||||
className="w-full py-3 bg-amber-50 text-amber-900 border border-amber-200 rounded-xl text-xs font-black flex items-center justify-center gap-2 hover:bg-amber-100 transition-colors cursor-pointer"
|
||||
>
|
||||
<Building2 className="w-4 h-4 text-amber-600" />
|
||||
درخواست حساب خریدار عمده (پتشاپ / کلینیک)
|
||||
</button>
|
||||
</div>
|
||||
{useSettingsStore.getState().getBoolean('b2bRegistrationOpen', true) && useSettingsStore.getState().getBoolean('b2b_enabled', true) && (
|
||||
<div className="pt-3 border-t border-medical-gray-100">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setView("wholesale-request")}
|
||||
className="w-full py-3 bg-amber-50 text-amber-900 border border-amber-200 rounded-xl text-xs font-black flex items-center justify-center gap-2 hover:bg-amber-100 transition-colors cursor-pointer"
|
||||
>
|
||||
<Building2 className="w-4 h-4 text-amber-600" />
|
||||
درخواست حساب خریدار عمده (پتشاپ / کلینیک)
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
@@ -784,6 +800,11 @@ export default function AuthModal({ isOpen, onClose }: AuthModalProps) {
|
||||
value={otpCode}
|
||||
onChange={(e) => handleOtpChange(e.target.value)}
|
||||
onInput={(e) => handleOtpChange((e.target as HTMLInputElement).value)}
|
||||
onPaste={(e) => {
|
||||
e.preventDefault();
|
||||
const pasted = e.clipboardData.getData('text');
|
||||
handleOtpChange(pasted);
|
||||
}}
|
||||
disabled={isLoading}
|
||||
className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-2xl py-4 pr-12 pl-4 focus:ring-2 focus:ring-canina-blue/20 outline-none font-bold text-center text-2xl font-mono tracking-[0.5em]"
|
||||
dir="ltr"
|
||||
|
||||
Reference in new issue
Block a user