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 {
const res = await cafeService.getCafeList();
if (res.data.success && res.data.data) {
setCafes(res.data.data);
console.log("🔄 Fetching cafes:", res?.data?.data?.data);
if (res.data.success && res?.data?.data?.data) {
setCafes(res?.data?.data?.data);
console.log("✅ Cafes loaded successfully:", res.data);
} else {
setError("داده‌های دریافتی معتبر نیست");
@ -68,125 +69,131 @@ const CafeManagement = () => {
);
}
return (
<>
{/* جدول دسکتاپ */}
<div className="hidden lg:block mt-10 overflow-x-auto">
<table className="w-full border-collapse">
<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>
</tr>
</thead>
<tbody>
{cafes.map((cafe) => (
<tr key={cafe._id} className="border-b border-[#EFEEEE] hover:bg-hover transition-colors">
<td className="px-4 py-4 text-right">
<img
src={cafe.photo || Pic1}
alt={cafe.Name}
className="w-10 h-10 rounded-full object-cover"
/>
</td>
<td className="px-4 py-4 text-right text-[#402E32] font-medium text-sm whitespace-nowrap">
{cafe.Name}
</td>
<td className="px-4 py-4 text-right text-[#402E32] text-sm max-w-xs overflow-hidden text-ellipsis">
{cafe.address}
</td>
<td className="px-4 py-4 text-right">
<div className="flex items-center gap-2">
<img src={Star1} alt="rating" className="w-5 h-5" />
<span className="text-[#402E32] text-sm">{cafe.rating || 0}</span>
</div>
</td>
<td className="px-4 py-4 text-right">
<div className="flex items-center gap-2">
<img src={Group} alt="time" className="w-5 h-5" />
<span className="text-[#402E32] text-sm whitespace-nowrap">
{cafe.openinghour || "نامشخص"}
</span>
</div>
</td>
<td className="px-4 py-4 text-center">
<Link
to={`/edit-cafe/${cafe._id}`}
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"
>
<span>ادیت</span>
<BiEdit className="w-4 h-4" />
</Link>
</td>
</tr>
))}
</tbody>
</table>
</div>
return (
<>
{/* جدول دسکتاپ */}
<div className="hidden lg:block mt-10 overflow-x-auto">
<table className="w-full border-collapse">
<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>
</tr>
</thead>
<tbody>
{cafes.map((cafe) => (
<tr key={cafe?._id} className="border-b border-[#EFEEEE] hover:bg-hover transition-colors">
<td className="px-4 py-4 text-right">
<img
src={cafe?.photo || Pic1}
alt={cafe?.Name}
className="w-10 h-10 rounded-full object-cover"
/>
</td>
<td className="px-4 py-4 text-right text-[#402E32] font-medium text-sm whitespace-nowrap">
{cafe?.Name}
</td>
<td className="px-4 py-4 text-right text-[#402E32] text-sm max-w-xs overflow-hidden text-ellipsis">
{cafe?.address}
</td>
<td className="px-4 py-4 text-right">
<div className="flex flex-col gap-1">
<div className="flex items-center gap-1">
<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>
</td>
<td className="px-4 py-4 text-right">
<div className="flex items-center gap-2">
<img src={Group} alt="time" className="w-5 h-5" />
<span className="text-[#402E32] text-sm whitespace-nowrap">
{cafe?.openinghour || "نامشخص"}
</span>
</div>
</td>
<td className="px-4 py-4 text-center">
<Link
to={`/edit-cafe/${cafe?._id}`}
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"
>
<span>ادیت</span>
<BiEdit className="w-4 h-4" />
</Link>
</td>
</tr>
))}
</tbody>
</table>
</div>
{/* کارت موبایل */}
<div className="lg:hidden mt-6 space-y-4">
{cafes.map((cafe) => (
<div
key={cafe._id}
key={cafe?._id}
className="bg-white border-2 border-[#8b8886] rounded-xl p-4"
>
<div className="flex items-start gap-4 mb-4">
<img
src={cafe.photo || Pic1}
alt={cafe.Name}
src={cafe?.photo || Pic1}
alt={cafe?.Name}
className="w-16 h-16 rounded-full object-cover flex-shrink-0"
/>
<div className="flex-1 min-w-0">
<h3 className="font-bold text-[#402E32] mb-1 text-sm">
{cafe.Name}
{cafe?.Name}
</h3>
<p className="text-xs text-gray-600 truncate">
{cafe.address}
{cafe?.address}
</p>
</div>
</div>
<div className="flex items-center justify-between mb-4 text-xs gap-4">
<div className="flex items-center gap-1">
<img src={Star1} alt="rating" className="w-4 h-4" />
<span className="text-[#402E32]">{cafe.rating || 0}</span>
<div className="flex flex-col gap-1">
<div className="flex items-center gap-1">
<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 className="flex items-center gap-1">
<img src={Group} alt="time" className="w-4 h-4" />
<span className="text-[#402E32]">
{cafe.openinghour || "نامشخص"}
{cafe?.openinghour || "نامشخص"}
</span>
</div>
</div>
<Link
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"
>
<span className="">ادیت کافه</span>
<BiEdit className="w-4 h-4" />
</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>
<Link
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"
>
<span className="">ادیت کافه</span>
<BiEdit className="w-4 h-4" />
</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>
{/* عنوان */}
<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 toggleTheme from "../../components/ToggleTheme";
import { CgDarkMode } from "react-icons/cg";
import { useSelector } from "react-redux";
export default function Login() {
const navigate = useNavigate();
const dispatch = useDispatch();
const token = useSelector((state) => state.auth.token);
useEffect(() => {
if (token) {
navigate("/dashboard");
}
}, [token, navigate]);
// State Management
const [userName, setUserName] = useState("");
@ -137,8 +145,8 @@ export default function Login() {
onClick={toggleTheme}
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>
{/* Main Content */}
<div className="flex min-h-screen">

View File

@ -1,7 +1,7 @@
import requests from "./api/base-api";
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),
};