fix some APIs

This commit is contained in:
Mahdi Rahimi 2025-12-31 08:19:01 +03:30
parent 5fa4ebfb04
commit 2c55926f49
3 changed files with 110 additions and 95 deletions

View File

@ -19,8 +19,9 @@ const CafeManagement = () => {
try { try {
const res = await cafeService.getCafeList(); const res = await cafeService.getCafeList();
if (res.data.success && res.data.data) { console.log("🔄 Fetching cafes:", res?.data?.data?.data);
setCafes(res.data.data); if (res.data.success && res?.data?.data?.data) {
setCafes(res?.data?.data?.data);
console.log("✅ Cafes loaded successfully:", res.data); console.log("✅ Cafes loaded successfully:", res.data);
} else { } else {
setError("داده‌های دریافتی معتبر نیست"); setError("داده‌های دریافتی معتبر نیست");
@ -68,125 +69,131 @@ const CafeManagement = () => {
); );
} }
return ( return (
<> <>
{/* جدول دسکتاپ */} {/* جدول دسکتاپ */}
<div className="hidden lg:block mt-10 overflow-x-auto"> <div className="hidden lg:block mt-10 overflow-x-auto">
<table className="w-full border-collapse"> <table className="w-full border-collapse">
<thead> <thead>
<tr className="bg-thead"> <tr className="bg-thead">
<th className="px-4 py-3 text-right text-text2 font-medium text-sm">لوگو</th> <th className="px-4 py-3 text-right text-text2 font-medium text-sm">لوگو</th>
<th className="px-4 py-3 text-right text-text2 font-medium text-sm">اسم</th> <th className="px-4 py-3 text-right text-text2 font-medium text-sm">اسم</th>
<th className="px-4 py-3 text-right text-text2 font-medium text-sm">آدرس</th> <th className="px-4 py-3 text-right text-text2 font-medium text-sm">آدرس</th>
<th className="px-4 py-3 text-right text-text2 font-medium text-sm">ریتینگ</th> <th className="px-4 py-3 text-right text-text2 font-medium text-sm">ریتینگ</th>
<th className="px-4 py-3 text-right text-text2 font-medium text-sm">ساعت کاری</th> <th className="px-4 py-3 text-right text-text2 font-medium text-sm">ساعت کاری</th>
<th className="px-4 py-3 text-right text-text2 font-medium text-sm">ادیت</th> <th className="px-4 py-3 text-right text-text2 font-medium text-sm">ادیت</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{cafes.map((cafe) => ( {cafes.map((cafe) => (
<tr key={cafe._id} className="border-b border-[#EFEEEE] hover:bg-hover transition-colors"> <tr key={cafe?._id} className="border-b border-[#EFEEEE] hover:bg-hover transition-colors">
<td className="px-4 py-4 text-right"> <td className="px-4 py-4 text-right">
<img <img
src={cafe.photo || Pic1} src={cafe?.photo || Pic1}
alt={cafe.Name} alt={cafe?.Name}
className="w-10 h-10 rounded-full object-cover" className="w-10 h-10 rounded-full object-cover"
/> />
</td> </td>
<td className="px-4 py-4 text-right text-[#402E32] font-medium text-sm whitespace-nowrap"> <td className="px-4 py-4 text-right text-[#402E32] font-medium text-sm whitespace-nowrap">
{cafe.Name} {cafe?.Name}
</td> </td>
<td className="px-4 py-4 text-right text-[#402E32] text-sm max-w-xs overflow-hidden text-ellipsis"> <td className="px-4 py-4 text-right text-[#402E32] text-sm max-w-xs overflow-hidden text-ellipsis">
{cafe.address} {cafe?.address}
</td> </td>
<td className="px-4 py-4 text-right"> <td className="px-4 py-4 text-right">
<div className="flex items-center gap-2"> <div className="flex flex-col gap-1">
<img src={Star1} alt="rating" className="w-5 h-5" /> <div className="flex items-center gap-1">
<span className="text-[#402E32] text-sm">{cafe.rating || 0}</span> <img src={Star1} alt="rating" className="w-4 h-4" />
</div> <span className="text-[#402E32]">{cafe?.rating || 0}</span>
</td> </div>
<td className="px-4 py-4 text-right"> <span className="block">از {cafe?.ratingCount} نفر</span>
<div className="flex items-center gap-2"> </div>
<img src={Group} alt="time" className="w-5 h-5" /> </td>
<span className="text-[#402E32] text-sm whitespace-nowrap"> <td className="px-4 py-4 text-right">
{cafe.openinghour || "نامشخص"} <div className="flex items-center gap-2">
</span> <img src={Group} alt="time" className="w-5 h-5" />
</div> <span className="text-[#402E32] text-sm whitespace-nowrap">
</td> {cafe?.openinghour || "نامشخص"}
<td className="px-4 py-4 text-center"> </span>
<Link </div>
to={`/edit-cafe/${cafe._id}`} </td>
className="inline-flex items-center justify-center gap-2 border-2 border-[#BB8F70] px-6 py-2 rounded-3xl text-sm font-light text-text1 hover:bg-button1 hover:border-button1 transition-all duration-300" <td className="px-4 py-4 text-center">
> <Link
<span>ادیت</span> to={`/edit-cafe/${cafe?._id}`}
<BiEdit className="w-4 h-4" /> className="inline-flex items-center justify-center gap-2 border-2 border-[#BB8F70] px-6 py-2 rounded-3xl text-sm font-light text-text1 hover:bg-button1 hover:border-button1 transition-all duration-300"
</Link> >
</td> <span>ادیت</span>
</tr> <BiEdit className="w-4 h-4" />
))} </Link>
</tbody> </td>
</table> </tr>
</div> ))}
</tbody>
</table>
</div>
{/* کارت موبایل */} {/* کارت موبایل */}
<div className="lg:hidden mt-6 space-y-4"> <div className="lg:hidden mt-6 space-y-4">
{cafes.map((cafe) => ( {cafes.map((cafe) => (
<div <div
key={cafe._id} key={cafe?._id}
className="bg-white border-2 border-[#8b8886] rounded-xl p-4" className="bg-white border-2 border-[#8b8886] rounded-xl p-4"
> >
<div className="flex items-start gap-4 mb-4"> <div className="flex items-start gap-4 mb-4">
<img <img
src={cafe.photo || Pic1} src={cafe?.photo || Pic1}
alt={cafe.Name} alt={cafe?.Name}
className="w-16 h-16 rounded-full object-cover flex-shrink-0" className="w-16 h-16 rounded-full object-cover flex-shrink-0"
/> />
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0">
<h3 className="font-bold text-[#402E32] mb-1 text-sm"> <h3 className="font-bold text-[#402E32] mb-1 text-sm">
{cafe.Name} {cafe?.Name}
</h3> </h3>
<p className="text-xs text-gray-600 truncate"> <p className="text-xs text-gray-600 truncate">
{cafe.address} {cafe?.address}
</p> </p>
</div> </div>
</div> </div>
<div className="flex items-center justify-between mb-4 text-xs gap-4"> <div className="flex items-center justify-between mb-4 text-xs gap-4">
<div className="flex items-center gap-1"> <div className="flex flex-col gap-1">
<img src={Star1} alt="rating" className="w-4 h-4" /> <div className="flex items-center gap-1">
<span className="text-[#402E32]">{cafe.rating || 0}</span> <img src={Star1} alt="rating" className="w-4 h-4" />
<span className="text-[#402E32]">{cafe?.rating || 0}</span>
</div>
<span className="block">از {cafe?.ratingCount} نفر</span>
</div> </div>
<div className="flex items-center gap-1"> <div className="flex items-center gap-1">
<img src={Group} alt="time" className="w-4 h-4" /> <img src={Group} alt="time" className="w-4 h-4" />
<span className="text-[#402E32]"> <span className="text-[#402E32]">
{cafe.openinghour || "نامشخص"} {cafe?.openinghour || "نامشخص"}
</span> </span>
</div> </div>
</div> </div>
<Link <Link
to={`/edit-cafe/${cafe._id}`} to={`/edit-cafe/${cafe?._id}`}
className="flex justify-center items-center gap-2 w-full border-2 border-[#BB8F70] py-2 rounded-full text-sm font-medium text-text1 hover:bg-button1 hover:border-button1 transition-all duration-300" className="flex justify-center items-center gap-2 w-full border-2 border-[#BB8F70] py-2 rounded-full text-sm font-medium text-text1 hover:bg-button1 hover:border-button1 transition-all duration-300"
> >
<span className="">ادیت کافه</span> <span className="">ادیت کافه</span>
<BiEdit className="w-4 h-4" /> <BiEdit className="w-4 h-4" />
</Link> </Link>
</div>
))}
</div>
</>
);
};
return (
<section dir="rtl" className="w-full pt-24 max-w-full overflow-x-hidden">
{/* بخش دکمه اضافه کردن */}
<div className="flex items-center justify-between mb-8">
<button className="flex items-center justify-center gap-3 px-6 py-3 bg-button1 text-white rounded-3xl text-sm lg:text-base font-medium hover:bg-hover2 transition-all duration-300 cursor-pointer">
<span>افزودن شعبه جدید</span>
<img src={Vector9} alt="افزودن" className="w-5 h-5" />
</button>
</div> </div>
))}
</div>
</>
);
};
return (
<section dir="rtl" className="w-full pt-24 max-w-full overflow-x-hidden">
{/* بخش دکمه اضافه کردن */}
<div className="flex items-center justify-between mb-8">
<button className="flex items-center justify-center gap-3 px-6 py-3 bg-button1 text-white rounded-3xl text-sm lg:text-base font-medium hover:bg-hover2 transition-all duration-300 cursor-pointer">
<span>افزودن شعبه جدید</span>
<img src={Vector9} alt="افزودن" className="w-5 h-5" />
</button>
</div>
{/* عنوان */} {/* عنوان */}
<h1 className="text-[#402E32] font-bold text-lg lg:text-xl mb-6"> <h1 className="text-[#402E32] font-bold text-lg lg:text-xl mb-6">

View File

@ -16,10 +16,18 @@ import { setProfile } from "../../redux/slices/profileSlice";
import authService from "../../services/auth"; import authService from "../../services/auth";
import toggleTheme from "../../components/ToggleTheme"; import toggleTheme from "../../components/ToggleTheme";
import { CgDarkMode } from "react-icons/cg"; import { CgDarkMode } from "react-icons/cg";
import { useSelector } from "react-redux";
export default function Login() { export default function Login() {
const navigate = useNavigate(); const navigate = useNavigate();
const dispatch = useDispatch(); const dispatch = useDispatch();
const token = useSelector((state) => state.auth.token);
useEffect(() => {
if (token) {
navigate("/dashboard");
}
}, [token, navigate]);
// State Management // State Management
const [userName, setUserName] = useState(""); const [userName, setUserName] = useState("");
@ -137,8 +145,8 @@ export default function Login() {
onClick={toggleTheme} onClick={toggleTheme}
className="fixed top-4 right-4 z-50 w-12 h-10 flex justify-center items-center" className="fixed top-4 right-4 z-50 w-12 h-10 flex justify-center items-center"
> >
<CgDarkMode className="w-6 h-6 text-[#8B8886]" /> <CgDarkMode className="w-6 h-6 text-[#8B8886]" />
</button> </button>
{/* Main Content */} {/* Main Content */}
<div className="flex min-h-screen"> <div className="flex min-h-screen">

View File

@ -1,7 +1,7 @@
import requests from "./api/base-api"; import requests from "./api/base-api";
const cafeService = { const cafeService = {
getCafeList: () => requests.get("/cafe/v1/get-cafe-list"), getCafeList: () => requests.get("/admin/v1/get-cafe-lists"),
editCafe: (id, cafeData) => requests.put(`/cafe/v1/get-cafe-profile-by-cafe/${id}`, cafeData), editCafe: (id, cafeData) => requests.put(`/cafe/v1/get-cafe-profile-by-cafe/${id}`, cafeData),
}; };