feat(ui): optimize wiki ingredient links, product images, back buttons, and checkout settings
Deploy Canina / deploy (push) Successful in 1m54s
Deploy Canina / deploy (push) Successful in 1m54s
This commit is contained in:
1 parent
03c6ed58c7
commit
2d83a00169
15 files changed
+550
-396
No files matched your search
@@ -78,8 +78,20 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
}
|
||||
}, [initialView]);
|
||||
|
||||
const [uploadProgress, setUploadProgress] = useState<number | null>(null);
|
||||
const [activePetTab, setActivePetTab] = useState<"health" | "orders" | "prescriptions">("health");
|
||||
|
||||
// URL query param retention for pet and tab
|
||||
useEffect(() => {
|
||||
const petParam = searchParams.get('pet');
|
||||
if (petParam && pets.length > 0) {
|
||||
const matchedPet = pets.find(p => p.id === petParam || p.name === petParam);
|
||||
if (matchedPet && matchedPet.id !== activePet?.id) {
|
||||
setActivePet(matchedPet.id);
|
||||
}
|
||||
}
|
||||
}, [searchParams, pets, activePet?.id, setActivePet]);
|
||||
|
||||
// URL query param retention for tab
|
||||
useEffect(() => {
|
||||
const tabParam = searchParams.get('tab');
|
||||
@@ -365,7 +377,15 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={() => { setActivePet(pet.id); setView("detail"); }}
|
||||
onClick={() => {
|
||||
setActivePet(pet.id);
|
||||
setView("detail");
|
||||
if (typeof window !== 'undefined') {
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.set('pet', pet.id);
|
||||
window.history.replaceState({}, '', url.toString());
|
||||
}
|
||||
}}
|
||||
className="w-full py-4 bg-medical-gray-900 text-white rounded-2xl font-black hover:bg-canina-blue transition-all flex items-center justify-center gap-2 group-hover:shadow-lg"
|
||||
>
|
||||
مشاهده شناسنامه سلامت
|
||||
@@ -523,47 +543,93 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[10px] font-black text-medical-gray-400 uppercase tracking-widest mb-3 pr-2">تصویر یا عکس پت</label>
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
type="text"
|
||||
value={formData.imageUrl || ''}
|
||||
onChange={e => setFormData({ ...formData, imageUrl: e.target.value })}
|
||||
className="flex-1 bg-medical-gray-50 border border-medical-gray-200 rounded-2xl py-3 px-4 focus:ring-2 focus:ring-canina-blue/20 outline-none text-xs font-mono"
|
||||
placeholder="آدرس یا لینک عکس..."
|
||||
/>
|
||||
<label className="bg-canina-blue text-white px-4 py-3 rounded-2xl text-xs font-bold cursor-pointer hover:bg-canina-dark transition-all flex items-center justify-center shrink-0">
|
||||
آپلود فایل
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
className="hidden"
|
||||
onChange={async (e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
const fd = new FormData();
|
||||
fd.append('file', file);
|
||||
try {
|
||||
const res = await api.post('/pets/upload-image', fd, { headers: { 'Content-Type': 'multipart/form-data' } });
|
||||
const url = res.data?.url || res.data?.path || res.data?.data?.url;
|
||||
if (url) {
|
||||
setFormData({ ...formData, imageUrl: url });
|
||||
toast.success("تصویر با موفقیت آپلود شد");
|
||||
}
|
||||
} catch {
|
||||
try {
|
||||
const res = await api.post('/upload', fd, { headers: { 'Content-Type': 'multipart/form-data' } });
|
||||
const url = res.data?.url || res.data?.path || res.data?.data?.url;
|
||||
if (url) {
|
||||
setFormData({ ...formData, imageUrl: url });
|
||||
toast.success("تصویر با موفقیت آپلود شد");
|
||||
<div className="flex flex-col sm:flex-row items-center gap-4 bg-medical-gray-50 p-4 rounded-2xl border border-medical-gray-200">
|
||||
{/* Photo preview container */}
|
||||
<div className="relative w-20 h-20 rounded-2xl overflow-hidden bg-medical-gray-200 border-2 border-dashed border-medical-gray-300 flex items-center justify-center shrink-0">
|
||||
{formData.imageUrl ? (
|
||||
<img
|
||||
src={formData.imageUrl.startsWith('http') ? formData.imageUrl : `${BASE_DOMAIN}${formData.imageUrl}`}
|
||||
alt="عکس پت"
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<Dog className="w-8 h-8 text-medical-gray-400" />
|
||||
)}
|
||||
|
||||
{uploadProgress !== null && (
|
||||
<div className="absolute inset-0 bg-black/60 backdrop-blur-xs flex flex-col items-center justify-center text-white">
|
||||
<div className="relative w-10 h-10 flex items-center justify-center">
|
||||
<svg className="w-full h-full -rotate-90" viewBox="0 0 36 36">
|
||||
<path
|
||||
className="text-white/20"
|
||||
strokeWidth="3"
|
||||
stroke="currentColor"
|
||||
fill="none"
|
||||
d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831"
|
||||
/>
|
||||
<path
|
||||
className="text-canina-blue"
|
||||
strokeDasharray={`${uploadProgress}, 100`}
|
||||
strokeWidth="3"
|
||||
strokeLinecap="round"
|
||||
stroke="currentColor"
|
||||
fill="none"
|
||||
d="M18 2.0845 a 15.9155 15.9155 0 0 1 0 31.831 a 15.9155 15.9155 0 0 1 0 -31.831"
|
||||
/>
|
||||
</svg>
|
||||
<span className="absolute text-[9px] font-black">{toPersian(uploadProgress)}%</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex-1 w-full space-y-2">
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
type="text"
|
||||
value={formData.imageUrl || ''}
|
||||
onChange={e => setFormData({ ...formData, imageUrl: e.target.value })}
|
||||
className="flex-1 bg-white border border-medical-gray-200 rounded-xl py-2.5 px-3 focus:ring-2 focus:ring-canina-blue/20 outline-none text-xs font-mono"
|
||||
placeholder="آدرس اینترنتی تصویر..."
|
||||
/>
|
||||
<label className="bg-canina-blue text-white px-4 py-2.5 rounded-xl text-xs font-black cursor-pointer hover:bg-canina-dark transition-all flex items-center justify-center shrink-0 shadow-xs">
|
||||
انتخاب تصویر
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
className="hidden"
|
||||
onChange={async (e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
const fd = new FormData();
|
||||
fd.append('file', file);
|
||||
setUploadProgress(10);
|
||||
try {
|
||||
const res = await api.post('/pets/upload-image', fd, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
onUploadProgress: (progressEvent) => {
|
||||
const total = progressEvent.total || file.size;
|
||||
const percent = Math.round((progressEvent.loaded * 100) / total);
|
||||
setUploadProgress(percent);
|
||||
}
|
||||
});
|
||||
const url = res.data?.url || res.data?.path || res.data?.data?.url;
|
||||
if (url) {
|
||||
setFormData({ ...formData, imageUrl: url });
|
||||
toast.success("تصویر با موفقیت آپلود شد");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Pet image upload error:", err);
|
||||
toast.error("خطا در آپلود تصویر");
|
||||
} finally {
|
||||
setTimeout(() => setUploadProgress(null), 500);
|
||||
}
|
||||
} catch {
|
||||
toast.error("خطا در آپلود تصویر");
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<p className="text-[10px] text-medical-gray-400 font-bold">فرمتهای مجاز: JPG, PNG (حداکثر ۱۰ مگابایت)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
@@ -724,18 +790,19 @@ export default function PetProfile({ initialView, advisorNeed, embedded = false
|
||||
</div>
|
||||
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={() => setView("index")}
|
||||
className="px-6 py-2.5 bg-white border border-medical-gray-200 rounded-xl text-[10px] font-black uppercase tracking-widest hover:border-canina-blue transition-all"
|
||||
>
|
||||
بازگشت به لیست
|
||||
</button>
|
||||
<button
|
||||
onClick={startEdit}
|
||||
className="px-6 py-2.5 bg-canina-blue text-white rounded-xl text-[10px] font-black uppercase tracking-widest shadow-lg shadow-canina-blue/20 hover:scale-105 transition-all flex items-center gap-2"
|
||||
className="px-6 py-2.5 bg-canina-blue text-white rounded-xl text-xs font-black shadow-lg shadow-canina-blue/20 hover:scale-105 transition-all flex items-center gap-2"
|
||||
>
|
||||
<Edit3 className="w-3.5 h-3.5" />
|
||||
ویرایش پرونده
|
||||
<span>ویرایش پرونده</span>
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setView("index")}
|
||||
className="px-6 py-2.5 bg-white border border-medical-gray-200 rounded-xl text-xs font-black text-medical-gray-700 hover:border-canina-blue hover:text-canina-blue transition-all flex items-center gap-1.5"
|
||||
>
|
||||
<span>بازگشت به لیست</span>
|
||||
<ChevronLeft className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user