feat(prescriptions & auth): auto-create user and pet profile on prescription submit, validate mobile numbers with regex, allow public upload and auto-reset form state
Deploy Canina / deploy (push) Waiting to run
Deploy Canina / deploy (push) Waiting to run
This commit is contained in:
1 parent
b617331683
commit
4e304944ef
5 files changed
+103
-17
No files matched your search
@@ -35,10 +35,17 @@ export default function ContactFormClient() {
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!name.trim() || !phone.trim() || !message.trim()) {
|
||||
const cleanPhone = phone.trim();
|
||||
if (!name.trim() || !cleanPhone || !message.trim()) {
|
||||
setError("لطفاً نام، شماره موبایل و متن پیام را وارد کنید.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!/^09\d{9}$/.test(cleanPhone)) {
|
||||
setError("شماره همراه وارد شده معتبر نیست. (مثال: ۰۹۱۲۳۴۵۶۷۸۹)");
|
||||
return;
|
||||
}
|
||||
|
||||
setError("");
|
||||
setLoading(true);
|
||||
|
||||
|
||||
@@ -25,14 +25,30 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
}
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
setFile(null);
|
||||
setPetName("");
|
||||
setPhone("");
|
||||
setNotes("");
|
||||
setIsSubmitting(false);
|
||||
setIsSuccess(false);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
resetForm();
|
||||
onClose();
|
||||
};
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!file) {
|
||||
toast.error("لطفاً تصویر یا فایل نسخه پزشکی را انتخاب کنید.");
|
||||
return;
|
||||
}
|
||||
if (!phone) {
|
||||
toast.error("لطفاً شماره تماس جهت پیگیری را وارد نمایید.");
|
||||
|
||||
const cleanPhone = phone.trim();
|
||||
if (!/^09\d{9}$/.test(cleanPhone)) {
|
||||
toast.error("شماره همراه وارد شده معتبر نیست. (مثال: ۰۹۱۲۳۴۵۶۷۸۹)");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,10 +62,12 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
});
|
||||
const fileUrl = uploadRes.data?.data?.url || uploadRes.data?.url || uploadRes.data?.filename || file.name;
|
||||
|
||||
// Submit prescription to backend prescriptions endpoint
|
||||
// Submit prescription to backend with petName and phone for automatic user & pet profile creation
|
||||
await api.post("/prescriptions", {
|
||||
fileUrl,
|
||||
notes: `نام پت: ${petName || "ثبت نشده"} | شماره تماس: ${phone} | توضیحات: ${notes || "ندارد"}`
|
||||
phone: cleanPhone,
|
||||
petName: petName.trim() || undefined,
|
||||
notes: notes.trim() || undefined
|
||||
});
|
||||
|
||||
setIsSubmitting(false);
|
||||
@@ -58,8 +76,7 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
} catch (error) {
|
||||
console.error("[PrescriptionUpload] Submission error:", error);
|
||||
setIsSubmitting(false);
|
||||
setIsSuccess(true); // Fallback friendly UX
|
||||
toast.success("نسخه پزشکی دریافت شد و جهت بررسی در صف کارشناسان قرار گرفت.");
|
||||
toast.error("خطا در ارسال نسخه پزشکی. لطفاً مجدداً تلاش کنید.");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -75,7 +92,7 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
{/* Header */}
|
||||
<div className="bg-canina-blue text-white p-6 relative">
|
||||
<button
|
||||
onClick={onClose}
|
||||
onClick={handleClose}
|
||||
className="absolute left-5 top-5 text-white/80 hover:text-white bg-white/10 p-1.5 rounded-full transition-colors"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
@@ -103,7 +120,7 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
کارشناسان و دامپزشکان کانینا نسخه شما را بررسی کرده و ظرف حداکثر ۱۵ دقیقه جهت هماهنگی ارسال دارو با شما تماس خواهند گرفت.
|
||||
</p>
|
||||
<button
|
||||
onClick={() => { setIsSuccess(false); onClose(); }}
|
||||
onClick={handleClose}
|
||||
className="px-6 py-2.5 bg-canina-blue text-white rounded-xl text-xs font-black hover:bg-canina-dark transition-all"
|
||||
>
|
||||
متوجه شدم
|
||||
@@ -172,7 +189,7 @@ export default function PrescriptionUploadModal({ isOpen, onClose }: Prescriptio
|
||||
<div className="pt-2 flex items-center justify-end gap-3 border-t border-medical-gray-100">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
onClick={handleClose}
|
||||
className="px-4 py-2.5 rounded-xl text-xs font-bold text-medical-gray-500 hover:bg-medical-gray-100 transition-colors"
|
||||
>
|
||||
انصراف
|
||||
|
||||
Reference in new issue
Block a user