fix(pets): resolve pet registration flow, missing assets, 401 guard, and add none option to symptoms
Deploy Canina / deploy (push) Successful in 1m51s
Deploy Canina / deploy (push) Successful in 1m51s
This commit is contained in:
1 parent
93126c1724
commit
cc8f52cb3f
19 files changed
+115704
-115146
No files matched your search
@@ -57,12 +57,14 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
.then(res => setProducts(res.data))
|
||||
.catch(err => console.error("Error fetching products in PetProfile:", err));
|
||||
|
||||
api.get("/prescriptions")
|
||||
.then(res => {
|
||||
const data = Array.isArray(res.data) ? res.data : (res.data?.data || []);
|
||||
setPrescriptions(data);
|
||||
})
|
||||
.catch(() => {});
|
||||
if (typeof window !== 'undefined' && localStorage.getItem('accessToken')) {
|
||||
api.get("/prescriptions")
|
||||
.then(res => {
|
||||
const data = Array.isArray(res.data) ? res.data : (res.data?.data || []);
|
||||
setPrescriptions(data);
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -218,12 +220,17 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
const handleBackStep = () => setStep(s => s - 1);
|
||||
|
||||
const handleSubmit = () => {
|
||||
const cleanedConditions = (formData.medicalConditions || []).filter(c => !c.includes("هیچکدام"));
|
||||
const cleanedData = {
|
||||
...formData,
|
||||
medicalConditions: cleanedConditions
|
||||
};
|
||||
if (view === "edit" && activePet) {
|
||||
updatePet(activePet.id, formData);
|
||||
updatePet(activePet.id, cleanedData);
|
||||
toast.success("اطلاعات شناسنامه با موفقیت بروزرسانی شد");
|
||||
setView("detail");
|
||||
} else {
|
||||
addPet(formData);
|
||||
addPet(cleanedData);
|
||||
toast.success("شناسنامه جدید با موفقیت صادر شد");
|
||||
setView("detail");
|
||||
}
|
||||
@@ -695,32 +702,49 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
<label className="block text-[10px] font-black text-medical-gray-400 uppercase tracking-widest mb-3 pr-2">سوابق درمانی و موارد خاص</label>
|
||||
<div className="grid grid-cols-1 gap-3">
|
||||
{[
|
||||
"هیچکدام (سلامت کامل و بدون سابقه بیماری)",
|
||||
"جراحی مفاصل",
|
||||
"زایمان اخیر",
|
||||
"بارداری",
|
||||
"مشکلات گوارشی",
|
||||
"ریزش موی شدید",
|
||||
"بیاشتهایی"
|
||||
].map(condition => (
|
||||
<button
|
||||
key={condition}
|
||||
onClick={() => {
|
||||
const current = formData.medicalConditions;
|
||||
setFormData({
|
||||
...formData,
|
||||
medicalConditions: current.includes(condition)
|
||||
? current.filter(c => c !== condition)
|
||||
: [...current, condition]
|
||||
})
|
||||
}}
|
||||
className={`flex items-center gap-4 p-4 border-2 rounded-2xl transition-all ${formData.medicalConditions.includes(condition) ? 'border-canina-blue bg-canina-blue/5 text-canina-blue' : 'border-medical-gray-50 text-medical-gray-500'}`}
|
||||
>
|
||||
<div className={`w-6 h-6 rounded-lg flex items-center justify-center border ${formData.medicalConditions.includes(condition) ? 'bg-canina-blue border-canina-blue text-white' : 'border-medical-gray-200'}`}>
|
||||
{formData.medicalConditions.includes(condition) && <ShieldCheck className="w-3.5 h-3.5" />}
|
||||
</div>
|
||||
<span className="font-black text-sm italic">{condition}</span>
|
||||
</button>
|
||||
))}
|
||||
].map(condition => {
|
||||
const isNone = condition.includes("هیچکدام");
|
||||
const isSelected = isNone
|
||||
? (formData.medicalConditions.length === 0 || formData.medicalConditions.includes(condition))
|
||||
: formData.medicalConditions.includes(condition);
|
||||
|
||||
return (
|
||||
<button
|
||||
key={condition}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
if (isNone) {
|
||||
setFormData({
|
||||
...formData,
|
||||
medicalConditions: ["هیچکدام (سلامت کامل و بدون سابقه بیماری)"]
|
||||
});
|
||||
} else {
|
||||
const filtered = formData.medicalConditions.filter(c => !c.includes("هیچکدام"));
|
||||
const updated = filtered.includes(condition)
|
||||
? filtered.filter(c => c !== condition)
|
||||
: [...filtered, condition];
|
||||
setFormData({
|
||||
...formData,
|
||||
medicalConditions: updated.length === 0 ? ["هیچکدام (سلامت کامل و بدون سابقه بیماری)"] : updated
|
||||
});
|
||||
}
|
||||
}}
|
||||
className={`flex items-center gap-4 p-4 border-2 rounded-2xl transition-all ${isSelected ? 'border-canina-blue bg-canina-blue/5 text-canina-blue' : 'border-medical-gray-50 text-medical-gray-500'}`}
|
||||
>
|
||||
<div className={`w-6 h-6 rounded-lg flex items-center justify-center border ${isSelected ? 'bg-canina-blue border-canina-blue text-white' : 'border-medical-gray-200'}`}>
|
||||
{isSelected && <ShieldCheck className="w-3.5 h-3.5" />}
|
||||
</div>
|
||||
<span className="font-black text-sm italic">{condition}</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
|
||||
<div className="pt-2">
|
||||
<label className="block text-[10px] font-black text-medical-gray-400 uppercase tracking-widest mb-2 pr-2">
|
||||
@@ -775,7 +799,30 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
}
|
||||
|
||||
// 3. Detailed Dashboard View
|
||||
if (!activePet) return null;
|
||||
if (!activePet) {
|
||||
if (pets.length > 0) {
|
||||
return (
|
||||
<div className="max-w-6xl mx-auto px-4 py-20" dir="rtl">
|
||||
<PetProfileSkeleton />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className={cn(embedded ? "w-full font-vazir" : "min-h-screen bg-medical-gray-50 py-8 px-2 sm:px-4 font-vazir")} dir="rtl">
|
||||
<div className="max-w-5xl mx-auto space-y-6">
|
||||
<SmartAdvisor
|
||||
onComplete={async (data) => {
|
||||
const newPet = { ...data, id: Date.now().toString(), reminders: [], logs: [], consumptions: [] } as unknown as GlobalPetProfile;
|
||||
await addPet(newPet);
|
||||
setActivePet(newPet.id);
|
||||
toast.success(`شناسنامه سلامت ${data.name} با موفقیت صادر شد`);
|
||||
setView("detail");
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn(embedded ? "w-full font-vazir" : "min-h-screen bg-medical-gray-50 py-8 sm:py-12 px-2 sm:px-4 font-vazir")} dir="rtl">
|
||||
|
||||
@@ -30,6 +30,7 @@ interface SmartAdvisorProps {
|
||||
}
|
||||
|
||||
const CURRENT_SYMPTOMS = [
|
||||
{ id: "none_symptom", label: "هیچکدام (سلامت کامل و بدون علامت)", condition: "هیچکدام (سلامت کامل)" },
|
||||
{ id: "joint_pain", label: "درد مفاصل و لنگیدن", condition: "درد مفاصل" },
|
||||
{ id: "hair_loss", label: "ریزش مو، خارش و خشکی پوست", condition: "ریزش مو" },
|
||||
{ id: "diarrhea", label: "اسهال، یبوست و مشکلات گوارشی", condition: "اسهال" },
|
||||
@@ -41,6 +42,7 @@ const CURRENT_SYMPTOMS = [
|
||||
];
|
||||
|
||||
const MEDICAL_HISTORIES = [
|
||||
{ id: "none_history", label: "هیچکدام (بدون سابقه بیماری و جراحی)", condition: "هیچکدام (بدون سابقه بیماری)" },
|
||||
{ id: "joint_surgery", label: "سابقه جراحی مفاصل/استخوان", condition: "جراحی مفاصل" },
|
||||
{ id: "recent_birth", label: "زایمان اخیر / شیردهی فعال", condition: "زایمان اخیر" },
|
||||
{ id: "pregnancy", label: "دوران بارداری", condition: "بارداری" },
|
||||
@@ -92,9 +94,41 @@ export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorPro
|
||||
const [weight, setWeight] = useState<number>(10);
|
||||
const [activityLevel, setActivityLevel] = useState<"کم" | "متوسط" | "زیاد">("متوسط");
|
||||
|
||||
// Step 3 Data (Symptoms) & Step 4 Data (History)
|
||||
const [currentSymptoms, setCurrentSymptoms] = useState<string[]>([]);
|
||||
const [medicalConditions, setMedicalConditions] = useState<string[]>([]);
|
||||
// Step 3 Data (Symptoms) & Step 4 Data (History) - default to none
|
||||
const [currentSymptoms, setCurrentSymptoms] = useState<string[]>(["هیچکدام (سلامت کامل)"]);
|
||||
const [medicalConditions, setMedicalConditions] = useState<string[]>(["هیچکدام (بدون سابقه بیماری)"]);
|
||||
|
||||
const toggleSymptom = (condition: string) => {
|
||||
if (condition === "هیچکدام (سلامت کامل)") {
|
||||
setCurrentSymptoms(["هیچکدام (سلامت کامل)"]);
|
||||
return;
|
||||
}
|
||||
setCurrentSymptoms(prev => {
|
||||
const filtered = prev.filter(c => c !== "هیچکدام (سلامت کامل)");
|
||||
if (filtered.includes(condition)) {
|
||||
const next = filtered.filter(c => c !== condition);
|
||||
return next.length === 0 ? ["هیچکدام (سلامت کامل)"] : next;
|
||||
} else {
|
||||
return [...filtered, condition];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const toggleMedicalHistory = (condition: string) => {
|
||||
if (condition === "هیچکدام (بدون سابقه بیماری)") {
|
||||
setMedicalConditions(["هیچکدام (بدون سابقه بیماری)"]);
|
||||
return;
|
||||
}
|
||||
setMedicalConditions(prev => {
|
||||
const filtered = prev.filter(c => c !== "هیچکدام (بدون سابقه بیماری)");
|
||||
if (filtered.includes(condition)) {
|
||||
const next = filtered.filter(c => c !== condition);
|
||||
return next.length === 0 ? ["هیچکدام (بدون سابقه بیماری)"] : next;
|
||||
} else {
|
||||
return [...filtered, condition];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const handleNext = () => {
|
||||
if (step === 1) {
|
||||
@@ -110,7 +144,8 @@ export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorPro
|
||||
const handleBack = () => setStep(s => s - 1);
|
||||
|
||||
const calculateRecommendation = async () => {
|
||||
const combinedConditions = Array.from(new Set([...currentSymptoms, ...medicalConditions]));
|
||||
const rawConditions = Array.from(new Set([...currentSymptoms, ...medicalConditions]));
|
||||
const combinedConditions = rawConditions.filter(c => !c.includes("هیچکدام"));
|
||||
|
||||
let matchedProd: Record<string, unknown> | null = null;
|
||||
|
||||
@@ -153,7 +188,8 @@ export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorPro
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
const combinedConditions = Array.from(new Set([...currentSymptoms, ...medicalConditions]));
|
||||
const rawConditions = Array.from(new Set([...currentSymptoms, ...medicalConditions]));
|
||||
const combinedConditions = rawConditions.filter(c => !c.includes("هیچکدام"));
|
||||
const data = {
|
||||
name, type, breed, age, weight, activityLevel, medicalConditions: combinedConditions
|
||||
};
|
||||
@@ -469,11 +505,7 @@ export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorPro
|
||||
{CURRENT_SYMPTOMS.map((opt) => (
|
||||
<button
|
||||
key={opt.id}
|
||||
onClick={() => {
|
||||
setCurrentSymptoms(prev =>
|
||||
prev.includes(opt.condition) ? prev.filter(c => c !== opt.condition) : [...prev, opt.condition]
|
||||
);
|
||||
}}
|
||||
onClick={() => toggleSymptom(opt.condition)}
|
||||
className={`flex items-center gap-4 p-5 rounded-2xl border-2 transition-all text-right focus-visible:ring-4 focus-visible:ring-canina-blue/30 focus-visible:outline-none min-h-[48px] ${currentSymptoms.includes(opt.condition) ? 'border-canina-blue bg-white shadow-md' : 'border-transparent bg-white/50 text-medical-gray-600 hover:bg-white'}`}
|
||||
>
|
||||
<div className={`w-8 h-8 rounded-lg flex items-center justify-center border ${currentSymptoms.includes(opt.condition) ? 'bg-canina-blue border-canina-blue text-white' : 'border-medical-gray-300 text-transparent'}`}>
|
||||
@@ -520,11 +552,7 @@ export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorPro
|
||||
{MEDICAL_HISTORIES.map((opt) => (
|
||||
<button
|
||||
key={opt.id}
|
||||
onClick={() => {
|
||||
setMedicalConditions(prev =>
|
||||
prev.includes(opt.condition) ? prev.filter(c => c !== opt.condition) : [...prev, opt.condition]
|
||||
);
|
||||
}}
|
||||
onClick={() => toggleMedicalHistory(opt.condition)}
|
||||
className={`flex items-center gap-4 p-5 rounded-2xl border-2 transition-all text-right focus-visible:ring-4 focus-visible:ring-canina-blue/30 focus-visible:outline-none min-h-[48px] ${medicalConditions.includes(opt.condition) ? 'border-canina-blue bg-white shadow-md' : 'border-transparent bg-white/50 text-medical-gray-600 hover:bg-white'}`}
|
||||
>
|
||||
<div className={`w-8 h-8 rounded-lg flex items-center justify-center border ${medicalConditions.includes(opt.condition) ? 'bg-canina-blue border-canina-blue text-white' : 'border-medical-gray-300 text-transparent'}`}>
|
||||
|
||||
Reference in new issue
Block a user