feat(advisor): refactor SmartAdvisor to a 4-step wizard separating symptoms and medical history
- Step 3: Current clinical symptoms (pain/limping, hair loss/itching, diarrhea/digestion, appetite loss, dental tartar, eye discharge, etc.) - Step 4: Medical & surgical history (joint surgery, pregnancy/lactation, post-illness recovery, heart failure, parasite history) - Merge symptoms and history into pet profile for hyper-accurate supplement recommendations
This commit is contained in:
1 parent
6d568d56ae
commit
78f0727e92
1 file changed
+75
-28
@@ -25,19 +25,24 @@ interface SmartAdvisorProps {
|
||||
onComplete?: (data: any) => void;
|
||||
}
|
||||
|
||||
const MEDICAL_OPTIONS = [
|
||||
const CURRENT_SYMPTOMS = [
|
||||
{ id: "joint_pain", label: "درد مفاصل و لنگیدن", condition: "درد مفاصل" },
|
||||
{ id: "joint_surgery", label: "جراحی مفاصل", condition: "جراحی مفاصل" },
|
||||
{ id: "puppy_growth", label: "رشد سریع تولهسگ", condition: "رشد سریع تولهسگ" },
|
||||
{ id: "tendon", label: "ضعف تاندون و رباط", condition: "تاندون" },
|
||||
{ id: "diarrhea", label: "اسهال و یبوست", condition: "اسهال" },
|
||||
{ id: "weakness", label: "ضعف بعد از بیماری", condition: "ضعف بعد از بیماری" },
|
||||
{ id: "hair_loss", label: "ریزش مو، خارش و خشکی پوست", condition: "ریزش مو" },
|
||||
{ id: "diarrhea", label: "اسهال، یبوست و مشکلات گوارشی", condition: "اسهال" },
|
||||
{ id: "appetite", label: "بیاشتهایی و کاهش وزن", condition: "بیاشتهایی" },
|
||||
{ id: "dental", label: "جرم دندان و بوی بد دهان", condition: "جرم دندان" },
|
||||
{ id: "eye", label: "مشکلات یا شستشوی چشم", condition: "چشم" },
|
||||
{ id: "recent_birth", label: "زایمان اخیر", condition: "زایمان اخیر" },
|
||||
{ id: "pregnancy", label: "بارداری و شیردهی", condition: "بارداری" },
|
||||
{ id: "eye", label: "ترشحات یا مشکلات چشم", condition: "چشم" },
|
||||
{ id: "puppy_growth", label: "رشد سریع و تعادل استخوانی", condition: "رشد سریع تولهسگ" },
|
||||
{ id: "tendon", label: "سفتی عضلات و ضعف تاندون", condition: "تاندون" },
|
||||
];
|
||||
|
||||
const MEDICAL_HISTORIES = [
|
||||
{ id: "joint_surgery", label: "سابقه جراحی مفاصل/استخوان", condition: "جراحی مفاصل" },
|
||||
{ id: "recent_birth", label: "زایمان اخیر / شیردهی فعال", condition: "زایمان اخیر" },
|
||||
{ id: "pregnancy", label: "دوران بارداری", condition: "بارداری" },
|
||||
{ id: "weakness", label: "ضعف بعد از بیماری / نقاهت", condition: "ضعف بعد از بیماری" },
|
||||
{ id: "heart", label: "نارسایی یا حساسیت قلبی", condition: "نارسایی قلبی" },
|
||||
{ id: "parasite", label: "سابقه آلودگی انگلی", condition: "آلودگی انگلی" },
|
||||
];
|
||||
|
||||
export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorProps & { rules?: any[] }) {
|
||||
@@ -47,17 +52,6 @@ export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorPro
|
||||
const { addPet, setActivePet } = usePetStore();
|
||||
const texts = useSettingsStore(state => state.texts);
|
||||
const getText = useSettingsStore(state => state.getText);
|
||||
const medicalOptions = React.useMemo(() => {
|
||||
const jsonStr = texts['medical_options'];
|
||||
if (jsonStr) {
|
||||
try {
|
||||
return JSON.parse(jsonStr) as typeof MEDICAL_OPTIONS;
|
||||
} catch (e) {
|
||||
console.error("Failed to parse medical_options JSON:", e);
|
||||
}
|
||||
}
|
||||
return MEDICAL_OPTIONS;
|
||||
}, [texts]);
|
||||
|
||||
const [step, setStep] = useState(1);
|
||||
|
||||
@@ -73,7 +67,8 @@ export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorPro
|
||||
const [weight, setWeight] = useState<number>(10);
|
||||
const [activityLevel, setActivityLevel] = useState<"کم" | "متوسط" | "زیاد">("متوسط");
|
||||
|
||||
// Step 3 Data
|
||||
// Step 3 Data (Symptoms) & Step 4 Data (History)
|
||||
const [currentSymptoms, setCurrentSymptoms] = useState<string[]>([]);
|
||||
const [medicalConditions, setMedicalConditions] = useState<string[]>([]);
|
||||
|
||||
const handleNext = () => {
|
||||
@@ -90,8 +85,9 @@ export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorPro
|
||||
const handleBack = () => setStep(s => s - 1);
|
||||
|
||||
const handleSubmit = () => {
|
||||
const combinedConditions = Array.from(new Set([...currentSymptoms, ...medicalConditions]));
|
||||
const data = {
|
||||
name, type, breed, age, weight, activityLevel, medicalConditions
|
||||
name, type, breed, age, weight, activityLevel, medicalConditions: combinedConditions
|
||||
};
|
||||
if (onComplete) {
|
||||
onComplete(data);
|
||||
@@ -120,7 +116,7 @@ export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorPro
|
||||
<span className="text-canina-blue text-xs font-black uppercase tracking-widest font-vazir">{getText('advisor_badge', "تکنولوژی پایش هوشمند")}</span>
|
||||
</motion.div>
|
||||
<h2 className="text-4xl lg:text-5xl font-black text-medical-gray-900 mb-4 font-lalezar tracking-wide">{getText('advisor_title', "دستیار سلامت کانینا")}</h2>
|
||||
<p className="text-medical-gray-600 font-medium text-base font-shabnam">{getText('advisor_subtitle', "فقط چند قدم تا صدور شناسنامه هوشمند و دریافت پیشنهادات تخصصی")}</p>
|
||||
<p className="text-medical-gray-600 font-medium text-base font-shabnam">{getText('advisor_subtitle', "فقط ۴ قدم تا صدور شناسنامه هوشمند و دریافت پیشنهادات تخصصی")}</p>
|
||||
</div>
|
||||
|
||||
<div className="bg-medical-gray-50 rounded-[3.5rem] border border-medical-gray-100 p-8 lg:p-12 shadow-2xl shadow-medical-gray-200/50 relative overflow-hidden">
|
||||
@@ -129,7 +125,7 @@ export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorPro
|
||||
<motion.div
|
||||
className="h-full bg-canina-blue"
|
||||
initial={{ width: "0%" }}
|
||||
animate={{ width: `${(step / 3) * 100}%` }}
|
||||
animate={{ width: `${(step / 4) * 100}%` }}
|
||||
transition={{ duration: 0.5 }}
|
||||
/>
|
||||
</div>
|
||||
@@ -283,7 +279,7 @@ export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorPro
|
||||
onClick={handleNext}
|
||||
className="flex-[2] py-6 bg-medical-gray-900 text-white rounded-3xl font-black text-lg hover:bg-canina-blue focus-visible:ring-4 focus-visible:ring-canina-blue/30 focus-visible:outline-none transition-all shadow-xl shadow-medical-gray-900/10 flex items-center justify-center gap-3 font-vazir min-h-[48px]"
|
||||
>
|
||||
{getText('advisor_next_final', "گام نهایی سلامت")}
|
||||
{getText('advisor_next_symptoms', "بررسی علائم بالینی فعلی")}
|
||||
<ChevronLeft className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
@@ -299,12 +295,63 @@ export default function SmartAdvisor({ onComplete, rules = [] }: SmartAdvisorPro
|
||||
className="space-y-8"
|
||||
>
|
||||
<div className="text-center">
|
||||
<h3 className="text-2xl font-black text-medical-gray-900 mb-2 font-vazir uppercase italic tracking-tight">{getText('advisor_step3_title', "گام آخر: سوابق و حساسیتها")}</h3>
|
||||
<p className="text-medical-gray-600 font-bold font-vazir">{getText('advisor_step3_desc', "در صورت وجود هر یک از موارد زیر، آن را تیک بزنید")}</p>
|
||||
<h3 className="text-2xl font-black text-medical-gray-900 mb-2 font-vazir uppercase italic tracking-tight">{getText('advisor_step3_symptoms_title', "گام سوم: علائم بالینی فعلی")}</h3>
|
||||
<p className="text-medical-gray-600 font-bold font-vazir">{getText('advisor_step3_symptoms_desc', "آیا همدم شما در حال حاضر هیچکدام از علائم زیر را تجربه میکند؟")}</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{medicalOptions.map((opt) => (
|
||||
{CURRENT_SYMPTOMS.map((opt) => (
|
||||
<button
|
||||
key={opt.id}
|
||||
onClick={() => {
|
||||
setCurrentSymptoms(prev =>
|
||||
prev.includes(opt.condition) ? prev.filter(c => c !== opt.condition) : [...prev, 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'}`}>
|
||||
<ShieldCheck className="w-5 h-5" />
|
||||
</div>
|
||||
<span className={`text-sm font-black font-vazir ${currentSymptoms.includes(opt.condition) ? 'text-canina-blue' : 'text-medical-gray-900'}`}>{opt.label}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex gap-4 pt-4">
|
||||
<button
|
||||
onClick={handleBack}
|
||||
className="flex-1 py-6 bg-medical-gray-100 text-medical-gray-600 rounded-3xl font-black text-lg hover:bg-medical-gray-200 focus-visible:ring-4 focus-visible:ring-canina-blue/30 focus-visible:outline-none transition-all flex items-center justify-center gap-3 font-vazir min-h-[48px]"
|
||||
>
|
||||
<ChevronRight className="w-5 h-5" />
|
||||
{getText('advisor_back', "قبلی")}
|
||||
</button>
|
||||
<button
|
||||
onClick={handleNext}
|
||||
className="flex-[2] py-6 bg-medical-gray-900 text-white rounded-3xl font-black text-lg hover:bg-canina-blue focus-visible:ring-4 focus-visible:ring-canina-blue/30 focus-visible:outline-none transition-all shadow-xl shadow-medical-gray-900/10 flex items-center justify-center gap-3 font-vazir min-h-[48px]"
|
||||
>
|
||||
{getText('advisor_next_history', "سوابق پزشکی و جراحی")}
|
||||
<ChevronLeft className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{step === 4 && (
|
||||
<motion.div
|
||||
key="step4"
|
||||
initial={{ opacity: 0, x: 20 }}
|
||||
animate={{ opacity: 1, x: 0 }}
|
||||
exit={{ opacity: 0, x: -20 }}
|
||||
className="space-y-8"
|
||||
>
|
||||
<div className="text-center">
|
||||
<h3 className="text-2xl font-black text-medical-gray-900 mb-2 font-vazir uppercase italic tracking-tight">{getText('advisor_step4_history_title', "گام چهارم: سوابق پزشکی و جراحی")}</h3>
|
||||
<p className="text-medical-gray-600 font-bold font-vazir">{getText('advisor_step4_history_desc', "در صورت وجود سابقه جراحی، بارداری یا نارسایی، آن را مشخص کنید")}</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{MEDICAL_HISTORIES.map((opt) => (
|
||||
<button
|
||||
key={opt.id}
|
||||
onClick={() => {
|
||||
|
||||
Reference in new issue
Block a user