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
+7
View File
@@ -46,3 +46,10 @@ export const useGetReports = () => {
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 { toast } from 'react-toastify'
import { ErrorType } from '../../../helpers/types'
import { GroupIconType } from './types/Types'
import { GroupIconType } from '../types/Types'
const GroupIconList: FC = () => {
+1 -1
View File
@@ -10,7 +10,7 @@ import PageLoading from '../../../components/PageLoading'
import TrashWithConfrim from '../../../components/TrashWithConfrim'
import { toast } from 'react-toastify'
import { ErrorType } from '../../../helpers/types'
import { IconType } from './types/Types'
import { IconType } from '../types/Types'
import moment from 'moment-jalaali'
const IconsList: FC = () => {
@@ -8,7 +8,7 @@ import * as Yup from 'yup'
import { toast } from 'react-toastify'
import { TickCircle } from 'iconsax-react'
import { useCreateGroupIcon } from '../../hooks/useIconData'
import { CreateGroupIconType } from '../types/Types'
import { CreateGroupIconType } from '../../types/Types'
import { ErrorType } from '../../../../helpers/types'
interface CreateGroupIconProps {
@@ -10,7 +10,7 @@ import { toast } from 'react-toastify'
import { TickCircle } from 'iconsax-react'
import { useCreateIcon, useGetGroupIcons } from '../../hooks/useIconData'
import { useSingleUpload } from '../../../service/hooks/useServiceData'
import { CreateIconType, GroupIconType } from '../types/Types'
import { CreateIconType, GroupIconType } from '../../types/Types'
import { ErrorType } from '../../../../helpers/types'
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,
IconsResponse,
ReportsResponse,
RestaurantsResponse,
} from "../types/Types";
export const getIcons = async (): Promise<IconsResponse> => {
@@ -41,3 +42,8 @@ export const getReports = async (): Promise<ReportsResponse> => {
const { data } = await axios.get("/admin/dmenu/contacts");
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 = {
name: string;
@@ -58,3 +58,51 @@ export type ReportItem = {
export interface ReportsResponse extends IResponse<ReportItem[]> {
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;
}