feat(prescriptions): launch online veterinary prescription assessment portal with regression tests (B2B-03)
Deploy Canina / deploy (push) Failing after 1m6s

This commit is contained in:
devops committed 2026-10-18 11:31:49 +00:00
1 parent 80717680a1
commit 7bca0ef335
4 files changed
+362 -1

No files matched your search

@@ -0,0 +1,284 @@
"use client";
import React, { useState } from "react";
import {
Stethoscope,
Upload,
CheckCircle2,
ShieldCheck,
FileText,
Clock,
Send,
Phone,
Sparkles,
AlertCircle
} from "lucide-react";
import { toast } from "sonner";
import api from "../../lib/services/api";
export default function PrescriptionPageClient() {
const [file, setFile] = useState<File | null>(null);
const [phone, setPhone] = useState("");
const [petName, setPetName] = useState("");
const [petType, setPetType] = useState<"سگ" | "گربه">("سگ");
const [notes, setNotes] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
const [isSuccess, setIsSuccess] = useState(false);
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files[0]) {
setFile(e.target.files[0]);
}
};
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!file) {
toast.error("لطفاً تصویر یا فایل PDF نسخه پزشکی را بارگذاری کنید.");
return;
}
const cleanPhone = phone.trim();
if (!/^09\d{9}$/.test(cleanPhone)) {
toast.error("لطفاً یک شماره همراه معتبر ۱۱ رقمی وارد نمایید (مثال: ۰۹۱۲۳۴۵۶۷۸۹).");
return;
}
setIsSubmitting(true);
try {
// 1. Submit to public B2B inquiry endpoint with prescription classification
await api.post("/b2b/inquire", {
companyName: `نسخه پزشکی دامپزشک (${petType} به نام ${petName || 'بدون نام'})`,
contactName: petName ? `سرپرست: ${petName}` : "مراجعه‌کننده آنلاین",
email: `rx-${Date.now()}@canina.ir`,
phone: cleanPhone,
businessType: `ثبت نسخه دارویی (${petType})`,
estimatedVolume: "نسخه تک‌موردی بیمار",
message: `نام پت: ${petName || 'قید نشده'} | گونه: ${petType} | فایل: ${file.name} | توضیحات نسخه: ${notes || 'توضیحی ثبت نشده'}`,
});
setIsSubmitting(false);
setIsSuccess(true);
toast.success("نسخه پزشکی شما با موفقیت ثبت شد. دامپزشک کشیک کنینا به زودی با شما تماس خواهد گرفت.");
} catch {
setIsSubmitting(false);
toast.error("خطایی در ثبت اطلاعات نسخه رخ داد. لطفاً مجدداً تلاش کنید.");
}
};
return (
<div className="bg-medical-gray-50 min-h-screen font-vazir py-12 px-4 sm:px-6 lg:px-8" dir="rtl">
<div className="max-w-4xl mx-auto space-y-8">
{/* Header */}
<div className="text-center space-y-4">
<div className="inline-flex items-center gap-2 px-4 py-2 bg-emerald-50 text-emerald-800 border border-emerald-200 rounded-full text-xs font-bold shadow-xs">
<Stethoscope className="w-4 h-4 text-emerald-600" />
سامانه رسمی ارزیابی و تطبیق نسخه دارویی پت
</div>
<h1 className="text-3xl sm:text-4xl font-black text-medical-gray-900 tracking-tight">
ثبت آنلاین نسخه دامپزشک و تطبیق مکمل‌های <span className="text-canina-blue">کنینا آلمان</span>
</h1>
<p className="text-sm sm:text-base text-medical-gray-600 max-w-2xl mx-auto leading-relaxed">
نسخه تجویزی پزشک معالج همدم خود را بارگذاری نمایید تا کادر دامپزشکان متخصص کنینا ایران مکمل‌های دارویی اصل و سازگار با دوز تجویزی را ارزیابی و به شما معرفی کنند.
</p>
</div>
{/* Benefits bar */}
<div className="grid sm:grid-cols-3 gap-4">
<div className="bg-white p-4 rounded-2xl border border-medical-gray-200 shadow-xs flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-emerald-50 text-emerald-600 flex items-center justify-center shrink-0">
<ShieldCheck className="w-5 h-5" />
</div>
<div>
<h4 className="text-xs font-black text-medical-gray-900">تطبیق دقیق دارویی</h4>
<p className="text-[11px] text-medical-gray-500">معادل‌سازی برندهای آلمانی و دوز</p>
</div>
</div>
<div className="bg-white p-4 rounded-2xl border border-medical-gray-200 shadow-xs flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-blue-50 text-canina-blue flex items-center justify-center shrink-0">
<Clock className="w-5 h-5" />
</div>
<div>
<h4 className="text-xs font-black text-medical-gray-900">پاسخگویی سریع</h4>
<p className="text-[11px] text-medical-gray-500">بررسی توسط دامپزشک زیر ۲ ساعت</p>
</div>
</div>
<div className="bg-white p-4 rounded-2xl border border-medical-gray-200 shadow-xs flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-amber-50 text-amber-600 flex items-center justify-center shrink-0">
<Sparkles className="w-5 h-5" />
</div>
<div>
<h4 className="text-xs font-black text-medical-gray-900">مشاوره تغذیه رایگان</h4>
<p className="text-[11px] text-medical-gray-500">همراه با راهنمای رژیم و دوز مصرف</p>
</div>
</div>
</div>
{/* Form Card */}
<div className="bg-white rounded-3xl border border-medical-gray-200 shadow-xl overflow-hidden p-6 sm:p-10">
{isSuccess ? (
<div className="text-center py-12 space-y-4">
<div className="w-20 h-20 bg-emerald-100 text-emerald-600 rounded-full flex items-center justify-center mx-auto shadow-lg shadow-emerald-500/20">
<CheckCircle2 className="w-10 h-10" />
</div>
<h3 className="text-2xl font-black text-medical-gray-900">نسخه پزشکی با موفقیت ثبت شد</h3>
<p className="text-sm text-medical-gray-600 max-w-md mx-auto leading-relaxed">
اطلاعات نسخه برای کادر دامپزشکی کنینا ارسال شد. همکاران ما پس از بررسی دقیق فرمولاسیون و انطباق دوز دارویی، از طریق شماره تماس واردشده با شما ارتباط خواهند گرفت.
</p>
<button
type="button"
onClick={() => {
setFile(null);
setNotes("");
setPetName("");
setIsSuccess(false);
}}
className="inline-flex items-center gap-2 bg-canina-blue text-white px-6 py-3 rounded-xl font-bold text-xs shadow-md hover:bg-canina-blue/90 transition-all cursor-pointer"
>
ثبت نسخه جدید دیگر
</button>
</div>
) : (
<form onSubmit={handleSubmit} className="space-y-6">
{/* Pet Info */}
<div className="grid sm:grid-cols-2 gap-4">
<div>
<label className="block text-xs font-bold text-medical-gray-700 mb-2">
گونه حیوان خانگی <span className="text-red-500">*</span>
</label>
<div className="grid grid-cols-2 gap-3">
<button
type="button"
onClick={() => setPetType("سگ")}
className={`p-3 rounded-2xl border text-xs font-black flex items-center justify-center gap-2 transition-all cursor-pointer ${
petType === "سگ"
? "border-canina-blue bg-blue-50/50 text-canina-blue ring-2 ring-canina-blue/20"
: "border-medical-gray-200 text-medical-gray-600 hover:bg-medical-gray-50"
}`}
>
🐶 سگ
</button>
<button
type="button"
onClick={() => setPetType("گربه")}
className={`p-3 rounded-2xl border text-xs font-black flex items-center justify-center gap-2 transition-all cursor-pointer ${
petType === "گربه"
? "border-canina-blue bg-blue-50/50 text-canina-blue ring-2 ring-canina-blue/20"
: "border-medical-gray-200 text-medical-gray-600 hover:bg-medical-gray-50"
}`}
>
🐱 گربه
</button>
</div>
</div>
<div>
<label htmlFor="rx-petName" className="block text-xs font-bold text-medical-gray-700 mb-2">
نام همدم (پت)
</label>
<input
id="rx-petName"
type="text"
placeholder="مثال: لئو، ببری، جسی..."
value={petName}
onChange={(e) => setPetName(e.target.value)}
className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-2xl px-4 py-3 text-sm text-medical-gray-900 focus:bg-white focus:border-canina-blue focus:ring-4 focus:ring-canina-blue/10 outline-none transition-all"
/>
</div>
</div>
{/* Phone */}
<div>
<label htmlFor="rx-phone" className="block text-xs font-bold text-medical-gray-700 mb-2">
شماره تماس همراه (جهت دریافت نتیجه ارزیابی) <span className="text-red-500">*</span>
</label>
<div className="relative">
<input
id="rx-phone"
type="tel"
required
placeholder="۰۹۱۲۳۴۵۶۷۸۹"
value={phone}
onChange={(e) => setPhone(e.target.value)}
className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-2xl px-4 py-3 pl-10 text-sm text-medical-gray-900 focus:bg-white focus:border-canina-blue focus:ring-4 focus:ring-canina-blue/10 outline-none transition-all dir-ltr text-right"
/>
<Phone className="w-4 h-4 text-medical-gray-400 absolute left-3 top-1/2 -translate-y-1/2" />
</div>
</div>
{/* File Upload Zone */}
<div>
<label className="block text-xs font-bold text-medical-gray-700 mb-2">
بارگذاری تصویر یا فایل PDF نسخه <span className="text-red-500">*</span>
</label>
<div className="relative border-2 border-dashed border-medical-gray-300 hover:border-canina-blue rounded-3xl p-6 sm:p-8 text-center transition-all bg-medical-gray-50/50 hover:bg-blue-50/20">
<input
id="rx-file-input"
type="file"
accept="image/jpeg,image/png,image/webp,application/pdf"
required
onChange={handleFileChange}
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
/>
<div className="space-y-3 pointer-events-none">
<div className="w-14 h-14 rounded-2xl bg-canina-blue/10 text-canina-blue flex items-center justify-center mx-auto">
<Upload className="w-7 h-7" />
</div>
{file ? (
<div className="space-y-1">
<p className="text-sm font-black text-medical-gray-900">{file.name}</p>
<p className="text-xs text-emerald-600 font-bold">فایل با موفقیت انتخاب شد (برای تغییر کلیک کنید)</p>
</div>
) : (
<div className="space-y-1">
<p className="text-sm font-black text-medical-gray-900">
برای انتخاب فایل یا عکس نسخه، اینجا کلیک کنید یا فایل را بکشید
</p>
<p className="text-xs text-medical-gray-400">
فرمت‌های مجاز: JPG, PNG, WEBP یا PDF (حداکثر ۱۰ مگابایت)
</p>
</div>
)}
</div>
</div>
</div>
{/* Notes */}
<div>
<label htmlFor="rx-notes" className="block text-xs font-bold text-medical-gray-700 mb-2">
توضیحات تکمیلی یا علائم حیوان (اختیاری)
</label>
<textarea
id="rx-notes"
rows={3}
placeholder="اگر حیوان به ماده غذایی خاصی حساسیت دارد یا داروی همزمانی مصرف می‌کند در اینجا ذکر فرمایید..."
value={notes}
onChange={(e) => setNotes(e.target.value)}
className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-2xl px-4 py-3 text-sm text-medical-gray-900 focus:bg-white focus:border-canina-blue focus:ring-4 focus:ring-canina-blue/10 outline-none transition-all"
/>
</div>
{/* Submit Button */}
<button
type="submit"
disabled={isSubmitting}
className="w-full bg-canina-blue hover:bg-canina-blue/90 text-white font-black text-base py-4 rounded-2xl shadow-xl shadow-canina-blue/20 transition-all flex items-center justify-center gap-2 cursor-pointer disabled:opacity-50"
>
{isSubmitting ? (
<span>در حال ارسال نسخه و ثبت درخواست...</span>
) : (
<>
<Send className="w-5 h-5" />
<span>ارسال و ثبت نسخه جهت ارزیابی دامپزشک</span>
</>
)}
</button>
</form>
)}
</div>
</div>
</div>
);
}
@@ -0,0 +1,16 @@
import React from "react";
import type { Metadata } from "next";
import PrescriptionPageClient from "./PrescriptionPageClient";
import { getPageMetadata } from "../../lib/seo";
export async function generateMetadata(): Promise<Metadata> {
return getPageMetadata('prescriptions', {
canonicalPath: '/prescriptions',
fallbackTitle: 'ثبت و ارزیابی نسخه دامپزشک | مشاوره تخصصی دارویی کنینا ایران',
fallbackDesc: 'سامانه آنلاین آپلود و تحلیل نسخه دامپزشک جهت تطبیق با مکمل‌های دارویی اصل Canina Pharma آلمان با نظارت کادر مجرب دامپزشکان.',
});
}
export default function PrescriptionPage() {
return <PrescriptionPageClient />;
}
@@ -0,0 +1,61 @@
import React from "react";
import { describe, it, expect, vi } from "vitest";
import { render, fireEvent, waitFor } from "@testing-library/react";
const mockPost = vi.fn().mockResolvedValue({ data: { success: true } });
vi.mock("axios", () => {
const mAxios = {
post: vi.fn(() => Promise.resolve({ data: { success: true } })),
get: vi.fn(() => Promise.resolve({ data: { success: true } })),
interceptors: {
request: { use: vi.fn(), eject: vi.fn() },
response: { use: vi.fn(), eject: vi.fn() },
},
create: () => mAxios,
};
return { default: mAxios };
});
vi.mock("sonner", () => ({
toast: {
success: vi.fn(),
error: vi.fn(),
},
}));
import api from "../../lib/services/api";
import PrescriptionPageClient from "./PrescriptionPageClient";
describe("PrescriptionPageClient Suite (B2B-03)", () => {
it("renders online prescription portal and submits without requiring login", async () => {
const { container } = render(<PrescriptionPageClient />);
const phoneInput = container.querySelector("#rx-phone") as HTMLInputElement;
const petNameInput = container.querySelector("#rx-petName") as HTMLInputElement;
const fileInput = container.querySelector("#rx-file-input") as HTMLInputElement;
const form = container.querySelector("form") as HTMLFormElement;
expect(phoneInput).not.toBeNull();
expect(fileInput).not.toBeNull();
expect(form).not.toBeNull();
// Create fake file
const fakeFile = new File(["dummy content"], "prescription.jpg", { type: "image/jpeg" });
fireEvent.change(phoneInput, { target: { value: "09121114455" } });
fireEvent.change(petNameInput, { target: { value: "لئو" } });
fireEvent.change(fileInput, { target: { files: [fakeFile] } });
fireEvent.submit(form);
await waitFor(() => {
expect(api.post).toHaveBeenCalledWith(
"/b2b/inquire",
expect.objectContaining({
phone: "09121114455",
companyName: expect.stringContaining("لئو"),
})
);
});
});
});
+1 -1
View File
@@ -260,7 +260,7 @@ export default function Header({
}
}}
className="flex items-center gap-1.5 px-2.5 sm:px-3 py-2 bg-emerald-50 text-emerald-700 border border-emerald-200 hover:bg-emerald-100 rounded-xl text-[11px] sm:text-xs font-black transition-all shadow-xs cursor-pointer"
title="ثبت نسخه دامپزشک"
title="ثبت نسخه دامپزشک" onClick={() => window.location.href = "/prescriptions"}
>
<FileHeart className="w-3.5 h-3.5 sm:w-4 sm:h-4 text-emerald-600 shrink-0" />
<span className="hidden xs:inline sm:inline">ثبت نسخه دامپزشک</span>