restaurant list + fix build

This commit is contained in:
hamid zarghami
2025-12-29 14:49:55 +03:30
parent fe07425d7e
commit 8bdd838ddc
12 changed files with 205 additions and 7 deletions
+3
View File
@@ -130,5 +130,8 @@ export const Pages = {
warnings: { warnings: {
list: "/dmenu/reports/list", list: "/dmenu/reports/list",
}, },
restaurants: {
list: "/dmenu/restaurants/list",
},
}, },
}; };
+14 -1
View File
@@ -77,7 +77,8 @@
"icons": "آیکون ها", "icons": "آیکون ها",
"dmenu": "دی منو", "dmenu": "دی منو",
"groups_icon": "گروه های آیکون", "groups_icon": "گروه های آیکون",
"reports": "گزارش ها" "reports": "گزارش ها",
"restaurants": "رستوران ها"
}, },
"slider": { "slider": {
"new_slider": "اسلایدر جدید", "new_slider": "اسلایدر جدید",
@@ -869,5 +870,17 @@
"date": "تاریخ", "date": "تاریخ",
"detail": "جزییات" "detail": "جزییات"
}, },
"restaurant": {
"list_restaurant": "لیست رستوران‌ها",
"name": "نام",
"phone": "شماره تماس",
"address": "آدرس",
"domain": "دامنه",
"status": "وضعیت",
"plan": "پلن",
"created_at": "تاریخ ایجاد",
"active": "فعال",
"inactive": "غیرفعال"
},
"cancel": "لغو" "cancel": "لغو"
} }
+7
View File
@@ -46,3 +46,10 @@ export const useGetReports = () => {
queryFn: api.getReports, queryFn: api.getReports,
}); });
}; };
export const useGetRestaurants = () => {
return useQuery({
queryKey: ["restaurants"],
queryFn: api.getRestaurants,
});
};
+1 -1
View File
@@ -10,7 +10,7 @@ import PageLoading from '../../../components/PageLoading'
import TrashWithConfrim from '../../../components/TrashWithConfrim' import TrashWithConfrim from '../../../components/TrashWithConfrim'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { ErrorType } from '../../../helpers/types' import { ErrorType } from '../../../helpers/types'
import { GroupIconType } from './types/Types' import { GroupIconType } from '../types/Types'
const GroupIconList: FC = () => { const GroupIconList: FC = () => {
+1 -1
View File
@@ -10,7 +10,7 @@ import PageLoading from '../../../components/PageLoading'
import TrashWithConfrim from '../../../components/TrashWithConfrim' import TrashWithConfrim from '../../../components/TrashWithConfrim'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { ErrorType } from '../../../helpers/types' import { ErrorType } from '../../../helpers/types'
import { IconType } from './types/Types' import { IconType } from '../types/Types'
import moment from 'moment-jalaali' import moment from 'moment-jalaali'
const IconsList: FC = () => { const IconsList: FC = () => {
@@ -8,7 +8,7 @@ import * as Yup from 'yup'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { TickCircle } from 'iconsax-react' import { TickCircle } from 'iconsax-react'
import { useCreateGroupIcon } from '../../hooks/useIconData' import { useCreateGroupIcon } from '../../hooks/useIconData'
import { CreateGroupIconType } from '../types/Types' import { CreateGroupIconType } from '../../types/Types'
import { ErrorType } from '../../../../helpers/types' import { ErrorType } from '../../../../helpers/types'
interface CreateGroupIconProps { interface CreateGroupIconProps {
@@ -10,7 +10,7 @@ import { toast } from 'react-toastify'
import { TickCircle } from 'iconsax-react' import { TickCircle } from 'iconsax-react'
import { useCreateIcon, useGetGroupIcons } from '../../hooks/useIconData' import { useCreateIcon, useGetGroupIcons } from '../../hooks/useIconData'
import { useSingleUpload } from '../../../service/hooks/useServiceData' import { useSingleUpload } from '../../../service/hooks/useServiceData'
import { CreateIconType, GroupIconType } from '../types/Types' import { CreateIconType, GroupIconType } from '../../types/Types'
import { ErrorType } from '../../../../helpers/types' import { ErrorType } from '../../../../helpers/types'
interface CreateIconProps { interface CreateIconProps {
+109
View File
@@ -0,0 +1,109 @@
import { FC } from 'react'
import { useTranslation } from 'react-i18next'
import { useGetRestaurants } from '../hooks/useIconData'
import PageLoading from '../../../components/PageLoading'
import Td from '../../../components/Td'
import { RestaurantType } from '../types/Types'
import moment from 'moment-jalaali'
import { Copy } from 'iconsax-react'
import { toast } from 'react-toastify'
const RestaurantsList: FC = () => {
const { t } = useTranslation('global')
const { data: restaurants, isLoading } = useGetRestaurants()
const restaurantsList = (restaurants as { data?: RestaurantType[] })?.data || []
const handleCopyAddress = async (address: string | null) => {
if (!address) return
try {
await navigator.clipboard.writeText(address)
toast.success('کپی شد')
} catch {
toast.error('خطا در کپی کردن')
}
}
return (
<div className='mt-4'>
<div className='flex w-full justify-between items-center'>
<div>
{t('restaurant.list_restaurant')}
</div>
</div>
{
isLoading ?
<PageLoading />
:
<div className='relative overflow-x-auto rounded-3xl mt-9 w-full'>
<table className='w-full text-sm '>
<thead className='thead'>
<tr>
<Td text={t('restaurant.name')} />
<Td text={t('restaurant.phone')} />
<Td text={t('restaurant.address')} />
<Td text={t('restaurant.domain')} />
<Td text={t('restaurant.plan')} />
<Td text={t('restaurant.status')} />
<Td text={t('restaurant.created_at')} />
<Td text={''} />
</tr>
</thead>
<tbody>
{
restaurantsList.map((item: RestaurantType) => {
return (
<tr key={item.id} className='tr'>
<Td text={item.name} />
<Td text={item.phone || '-'} />
<Td text={''}>
<div className='flex items-center gap-2'>
<span>{item.address || '-'}</span>
{item.address && (
<Copy
size={18}
color='#8C90A3'
className='cursor-pointer hover:text-primary transition-colors'
onClick={() => handleCopyAddress(item.address)}
/>
)}
</div>
</Td>
<Td text={item.domain || '-'} />
<Td text={item.plan || '-'} />
<Td text={''}>
<div className={`w-fit px-3 py-1 rounded-2xl text-xs ${item.isActive
? 'bg-green-100 text-green-700'
: 'bg-red-100 text-red-700'
}`}>
{item.isActive ? t('restaurant.active') : t('restaurant.inactive')}
</div>
</Td>
<Td text={''}>
<div className='dltr text-right'>
{moment(item.createdAt).format('jYYYY-jMM-jDD HH:mm')}
</div>
</Td>
<Td text={''} />
</tr>
)
})
}
</tbody>
</table>
{restaurantsList.length === 0 && (
<div className="text-center py-12">
<div className="text-gray-500 text-lg">هیچ رستورانی یافت نشد</div>
</div>
)}
</div>
}
</div>
)
}
export default RestaurantsList
+6
View File
@@ -5,6 +5,7 @@ import {
GroupIconsResponse, GroupIconsResponse,
IconsResponse, IconsResponse,
ReportsResponse, ReportsResponse,
RestaurantsResponse,
} from "../types/Types"; } from "../types/Types";
export const getIcons = async (): Promise<IconsResponse> => { export const getIcons = async (): Promise<IconsResponse> => {
@@ -41,3 +42,8 @@ export const getReports = async (): Promise<ReportsResponse> => {
const { data } = await axios.get("/admin/dmenu/contacts"); const { data } = await axios.get("/admin/dmenu/contacts");
return data; return data;
}; };
export const getRestaurants = async (): Promise<RestaurantsResponse> => {
const { data } = await axios.get("/admin/dmenu/restaurants");
return data;
};
+49 -1
View File
@@ -1,4 +1,4 @@
import { IResponse } from "../../../../types/response.types"; import { IResponse } from "../../../types/response.types";
export type CreateGroupIconType = { export type CreateGroupIconType = {
name: string; name: string;
@@ -58,3 +58,51 @@ export type ReportItem = {
export interface ReportsResponse extends IResponse<ReportItem[]> { export interface ReportsResponse extends IResponse<ReportItem[]> {
statusCode: number; statusCode: number;
} }
export type ScoreType = {
scoreAmount: string;
scoreCredit: string;
birthdayScore: string;
purchaseScore: string;
referrerScore: string;
registerScore: string;
purchaseAmount: string;
marriageDateScore: string;
};
export type RestaurantType = {
id: string;
createdAt: string;
updatedAt: string;
deletedAt: string | null;
name: string;
slug: string;
logo: string;
address: string | null;
menuColor: string | null;
latitude: number | null;
longitude: number | null;
serviceArea: string | null;
isActive: boolean;
establishedYear: number | null;
phone: string;
instagram: string | null;
telegram: string | null;
whatsapp: string | null;
description: string | null;
seoTitle: string | null;
seoDescription: string | null;
tagNames: string | null;
images: string | null;
vat: number;
domain: string;
score: ScoreType;
plan: string;
subscriptionId: string;
subscriptionEndDate: string;
subscriptionStartDate: string;
};
export interface RestaurantsResponse extends IResponse<RestaurantType[]> {
statusCode: number;
}
+2
View File
@@ -80,6 +80,7 @@ import PermissionLogs from '../pages/accessLogs/PermissionLogs'
import IconsList from '../pages/dmenu/icon/List' import IconsList from '../pages/dmenu/icon/List'
import GroupIconList from '../pages/dmenu/icon/GroupList' import GroupIconList from '../pages/dmenu/icon/GroupList'
import WarningsList from '../pages/dmenu/report/List.tsx' import WarningsList from '../pages/dmenu/report/List.tsx'
import RestaurantsList from '../pages/dmenu/restaurant/List.tsx'
// import WarningsList from '../pages/dmenu/reports/List' // TODO: Create this component // import WarningsList from '../pages/dmenu/reports/List' // TODO: Create this component
const MainRouter: FC = () => { const MainRouter: FC = () => {
@@ -173,6 +174,7 @@ const MainRouter: FC = () => {
<Route path={Pages.dmenu.icons.list} element={<IconsList />} /> <Route path={Pages.dmenu.icons.list} element={<IconsList />} />
<Route path={Pages.dmenu.icons.groupList} element={<GroupIconList />} /> <Route path={Pages.dmenu.icons.groupList} element={<GroupIconList />} />
<Route path={Pages.dmenu.warnings.list} element={<WarningsList />} /> <Route path={Pages.dmenu.warnings.list} element={<WarningsList />} />
<Route path={Pages.dmenu.restaurants.list} element={<RestaurantsList />} />
</Routes> </Routes>
</div> </div>
</div> </div>
+11 -1
View File
@@ -2,7 +2,7 @@ import { FC, useEffect } from 'react'
import LogoImage from '../assets/images/logo.svg' import LogoImage from '../assets/images/logo.svg'
import LogoSmall from '../assets/images/logo-small.svg' import LogoSmall from '../assets/images/logo-small.svg'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { Card, Code, CodeCircle, DocumentLike, DocumentText, Element3, Gallery, Headphone, Home2, Logout, Message, Messages3, Money3, NotificationStatus, People, Profile, Receipt21, Setting2, SmsTracking, Teacher, TicketDiscount, UserSquare, Activity, Icon, Category, Warning2 } from 'iconsax-react' import { Card, Code, CodeCircle, DocumentLike, DocumentText, Element3, Gallery, Headphone, Home2, Logout, Message, Messages3, Money3, NotificationStatus, People, Profile, Receipt21, Setting2, SmsTracking, Teacher, TicketDiscount, UserSquare, Activity, Icon, Category, Warning2, Building } from 'iconsax-react'
import SideBarItem from './SideBarItem' import SideBarItem from './SideBarItem'
import { useLocation } from 'react-router-dom' import { useLocation } from 'react-router-dom'
import { Pages } from '../config/Pages' import { Pages } from '../config/Pages'
@@ -334,6 +334,16 @@ const SideBar: FC = () => {
activeName='dmenu' activeName='dmenu'
/> />
</div> </div>
<div className='text-xs text-[#8C90A3]'>
<SideBarItem
icon={<Building variant={isActive('restaurants') ? 'Bold' : 'Outline'} color={isActive('restaurants') ? 'black' : '#8C90A3'} size={iconSizeSideBar} />}
title={t('sidebar.restaurants')}
isActive={isActive('restaurants')}
link={Pages.dmenu.restaurants.list}
activeName='dmenu'
/>
</div>
</div> </div>
</> </>
} }