feat: complete settings sync, standard UI inputs, prescriptions flow, pet profile and checkout enhancements
Deploy Canina / deploy (push) Failing after 51s
Deploy Canina / deploy (push) Failing after 51s
This commit is contained in:
1 parent
b3c60a1a7d
commit
6df92f03d7
32 files changed
+61750
-59151
No files matched your search
@@ -15,6 +15,7 @@ import TopUpModal from "./TopUpModal";
|
||||
import { ticketService, Ticket, TicketMessage } from "../lib/services/ticketService";
|
||||
import { usePetStore } from "../lib/store/usePetStore";
|
||||
import PetProfile from "./PetProfile";
|
||||
import api, { BASE_DOMAIN } from "../lib/services/api";
|
||||
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
|
||||
@@ -33,17 +34,37 @@ export default function UserDashboard() {
|
||||
}, [isLoggedIn, router]);
|
||||
|
||||
const { orders } = useCartStore();
|
||||
const [activeTab, setActiveTab] = React.useState<"profile" | "orders" | "wallet" | "addresses" | "tickets" | "pets" | "overview">("profile");
|
||||
const [activeTab, setActiveTab] = React.useState<"profile" | "orders" | "wallet" | "addresses" | "tickets" | "pets" | "prescriptions" | "overview">("profile");
|
||||
|
||||
// Set tab from URL query param if present
|
||||
useEffect(() => {
|
||||
const tabParam = searchParams.get('tab');
|
||||
if (tabParam && ['profile', 'orders', 'wallet', 'addresses', 'tickets', 'pets'].includes(tabParam)) {
|
||||
setActiveTab(tabParam as "profile" | "orders" | "wallet" | "addresses" | "tickets" | "pets");
|
||||
if (tabParam && ['profile', 'orders', 'wallet', 'addresses', 'tickets', 'pets', 'prescriptions'].includes(tabParam)) {
|
||||
setActiveTab(tabParam as "profile" | "orders" | "wallet" | "addresses" | "tickets" | "pets" | "prescriptions");
|
||||
}
|
||||
}, [searchParams]);
|
||||
|
||||
const [isLoadingOrders, setIsLoadingOrders] = useState(false);
|
||||
const [prescriptions, setPrescriptions] = useState<any[]>([]);
|
||||
const [isLoadingPrescriptions, setIsLoadingPrescriptions] = useState(false);
|
||||
|
||||
const fetchPrescriptions = React.useCallback(async () => {
|
||||
try {
|
||||
setIsLoadingPrescriptions(true);
|
||||
const res = await api.get('/prescriptions');
|
||||
setPrescriptions(Array.isArray(res.data) ? res.data : (res.data?.data || []));
|
||||
} catch {
|
||||
// ignore
|
||||
} finally {
|
||||
setIsLoadingPrescriptions(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (activeTab === 'prescriptions') {
|
||||
fetchPrescriptions();
|
||||
}
|
||||
}, [activeTab, fetchPrescriptions]);
|
||||
|
||||
// Tickets State
|
||||
const [tickets, setTickets] = useState<Ticket[]>([]);
|
||||
@@ -343,6 +364,7 @@ export default function UserDashboard() {
|
||||
{ id: "profile", label: "اطلاعات فردی", icon: <UserCircle className="w-5 h-5" /> },
|
||||
{ id: "pets", label: "پتهای من", icon: <Dog className="w-5 h-5" /> },
|
||||
{ id: "orders", label: "سفارشات من", icon: <Package className="w-5 h-5" /> },
|
||||
{ id: "prescriptions", label: "نسخههای من", icon: <Stethoscope className="w-5 h-5" /> },
|
||||
{ id: "wallet", label: "کیف پول", icon: <Wallet className="w-5 h-5" /> },
|
||||
{ id: "addresses", label: "آدرسها", icon: <MapPin className="w-5 h-5" /> },
|
||||
{ id: "tickets", label: "پشتیبانی و مشاوره", icon: <MessageSquare className="w-5 h-5" /> },
|
||||
@@ -377,8 +399,8 @@ export default function UserDashboard() {
|
||||
{tabs.map(tab => (
|
||||
<button
|
||||
key={tab.id}
|
||||
onClick={() => setActiveTab(tab.id as 'overview' | 'orders' | 'addresses' | 'wallet' | 'tickets')}
|
||||
className={`flex items-center justify-center gap-2 px-3 sm:px-4 py-2.5 sm:py-3 rounded-xl sm:rounded-2xl transition-all font-bold text-xs sm:text-sm ${activeTab === tab.id ? "bg-canina-blue text-white shadow-lg shadow-canina-blue/20" : "text-medical-gray-600 hover:bg-medical-gray-100 bg-medical-gray-50"}`}
|
||||
onClick={() => setActiveTab(tab.id as any)}
|
||||
className={`flex items-center justify-center gap-2 px-3 sm:px-4 py-2.5 sm:py-3 rounded-xl sm:rounded-2xl transition-all font-bold text-xs sm:text-sm cursor-pointer ${activeTab === tab.id ? "bg-canina-blue text-white shadow-lg shadow-canina-blue/20" : "text-medical-gray-600 hover:bg-medical-gray-100 bg-medical-gray-50"}`}
|
||||
>
|
||||
<div className="flex-shrink-0">{tab.icon}</div>
|
||||
<span>{tab.label}</span>
|
||||
@@ -1067,7 +1089,106 @@ export default function UserDashboard() {
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</motion.div>
|
||||
|
||||
{activeTab === "prescriptions" && (
|
||||
<div>
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 mb-8">
|
||||
<div>
|
||||
<h3 className="text-2xl font-black text-medical-gray-900 italic flex items-center gap-2">
|
||||
<Stethoscope className="w-6 h-6 text-canina-blue" />
|
||||
نسخههای پزشکی من
|
||||
</h3>
|
||||
<p className="text-xs font-bold text-medical-gray-400 mt-1">
|
||||
پیگیری وضعیت نسخههای بارگذاری شده و توصیههای دارویی دامپزشک
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => router.push('/?rx=1')}
|
||||
className="px-5 py-3 bg-canina-blue text-white rounded-2xl text-xs font-black hover:bg-canina-dark transition-all flex items-center gap-2 shadow-lg shadow-canina-blue/20 cursor-pointer"
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
<span>ارسال نسخه جدید</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{isLoadingPrescriptions ? (
|
||||
<div className="py-20 text-center text-medical-gray-400 font-bold text-sm">
|
||||
در حال بارگذاری نسخهها...
|
||||
</div>
|
||||
) : prescriptions.length === 0 ? (
|
||||
<div className="py-20 text-center space-y-4">
|
||||
<div className="w-16 h-16 bg-medical-gray-50 text-medical-gray-300 rounded-full flex items-center justify-center mx-auto">
|
||||
<Stethoscope className="w-8 h-8" />
|
||||
</div>
|
||||
<p className="text-sm font-bold text-medical-gray-400">هنوز هیچ نسخهای ثبت نکردهاید.</p>
|
||||
<button
|
||||
onClick={() => router.push('/?rx=1')}
|
||||
className="px-6 py-2.5 bg-medical-gray-900 text-white rounded-xl text-xs font-bold hover:bg-canina-blue transition-all cursor-pointer"
|
||||
>
|
||||
ثبت اولین نسخه
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{prescriptions.map((rx: any) => (
|
||||
<div
|
||||
key={rx.id}
|
||||
className="p-5 sm:p-6 bg-medical-gray-50 border border-medical-gray-200 rounded-[1.5rem] sm:rounded-[2rem] space-y-3 transition-all hover:shadow-md"
|
||||
>
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 pb-3 border-b border-medical-gray-200">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-xs font-black text-medical-gray-900">نسخه #{rx.id.slice(0, 8)}</span>
|
||||
{rx.pet && (
|
||||
<span className="px-2 py-0.5 bg-purple-50 text-purple-700 text-[10px] font-bold rounded-lg border border-purple-100">
|
||||
🐾 {rx.pet.name} ({rx.pet.breed || rx.pet.type})
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className={`px-3 py-1 text-xs font-black rounded-full ${
|
||||
rx.status === 'APPROVED' ? 'bg-green-100 text-green-700' :
|
||||
rx.status === 'REJECTED' ? 'bg-red-100 text-red-700' :
|
||||
'bg-amber-100 text-amber-700'
|
||||
}`}>
|
||||
{rx.status === 'APPROVED' ? 'تایید شده' : rx.status === 'REJECTED' ? 'عدم تایید' : 'در حال بررسی'}
|
||||
</span>
|
||||
<span className="text-[11px] text-medical-gray-400 font-bold">
|
||||
{toPersian(new Date(rx.createdAt).toLocaleDateString('fa-IR'))}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{rx.notes && (
|
||||
<p className="text-xs text-medical-gray-600">
|
||||
<strong className="text-medical-gray-800">توضیحات شما: </strong>
|
||||
{rx.notes}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{rx.adminNotes && (
|
||||
<div className="p-3.5 bg-canina-blue/5 border border-canina-blue/10 rounded-xl text-xs text-canina-blue leading-relaxed font-bold">
|
||||
<strong className="text-canina-dark block mb-1">پاسخ دامپزشک کنینا:</strong>
|
||||
{rx.adminNotes.split('__PRESCRIBED_PRODUCTS__:')[0]}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="pt-2 flex items-center justify-end gap-2">
|
||||
<a
|
||||
href={rx.fileUrl.startsWith('http') ? rx.fileUrl : `${BASE_DOMAIN}${rx.fileUrl}`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="px-4 py-2 bg-white border border-medical-gray-200 text-medical-gray-700 hover:text-canina-blue hover:border-canina-blue rounded-xl text-xs font-bold transition-all"
|
||||
>
|
||||
مشاهده تصویر نسخه
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</motion.div>
|
||||
</div>
|
||||
|
||||
{/* Sidebar Widgets (Wallet & Charity) */}
|
||||
|
||||
Reference in new issue
Block a user