This commit is contained in:
hamid zarghami
2025-01-29 15:01:30 +03:30
parent 9c8b15a2cf
commit 018737df4e
7 changed files with 189 additions and 51 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
VITE_TOKEN_NAME = 'admin_token' VITE_TOKEN_NAME = 'admin_token'
VITE_REFRESH_TOKEN_NAME = 'admin_refresh_token' VITE_REFRESH_TOKEN_NAME = 'admin_refresh_token'
VITE_BASE_URL = 'https://danak-dsc-api.run.danakcorp.com' VITE_BASE_URL = 'https://danak-dsc-api.run.danakcorp.com'
# VITE_BASE_URL = 'http://192.168.0.207:3500' # VITE_BASE_URL = 'http://192.168.0.221:3500'
+2 -1
View File
@@ -156,7 +156,8 @@
"active": "فعال", "active": "فعال",
"deactive": "غیرفعال", "deactive": "غیرفعال",
"software_langauge": "زبان نرم افزار", "software_langauge": "زبان نرم افزار",
"link": "لینک" "link": "لینک",
"danak_sujescet": "پیشنهاد داناک"
}, },
"save": "ذخیره", "save": "ذخیره",
"search": "جستجو", "search": "جستجو",
+99 -49
View File
@@ -1,4 +1,4 @@
import { FC } from 'react' import { FC, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import Button from '../../components/Button' import Button from '../../components/Button'
import { Add, Eye } from 'iconsax-react' import { Add, Eye } from 'iconsax-react'
@@ -7,11 +7,24 @@ import Input from '../../components/Input'
import Td from '../../components/Td' import Td from '../../components/Td'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import { Pages } from '../../config/Pages' import { Pages } from '../../config/Pages'
import SwitchComponent from '../../components/Switch' import { useGetAllServices, useGetCategoryParents } from './hooks/useServiceData'
import PageLoading from '../../components/PageLoading'
import { ServiceCategoryType, ServiceItemType } from './types/ServiceTypes'
import moment from 'moment-jalaali'
import Pagination from '../../components/Pagination'
import ToggleStatusService from './components/ToggleStatusService'
import CheckBoxComponent from '../../components/CheckBoxComponent'
const ListService: FC = () => { const ListService: FC = () => {
const { t } = useTranslation('global') const { t } = useTranslation('global')
const [category, setCategory] = useState<string>('')
const [status, setstatus] = useState<'ACTIVE' | 'IN_ACTIVE' | ''>('')
const [page, setPage] = useState<number>(1)
const [search, setSearch] = useState<string>('')
const [isDanakSuggest, setIsDanakSuggest] = useState<boolean>(false)
const getServices = useGetAllServices(search, page, category, status, isDanakSuggest)
const getCategory = useGetCategoryParents()
return ( return (
<div className='mt-4'> <div className='mt-4'>
@@ -40,71 +53,108 @@ const ListService: FC = () => {
<div className='flex gap-4'> <div className='flex gap-4'>
<Select <Select
className='w-36' className='w-36'
items={[ items={
{ label: 'All', value: 'all' }, getCategory.data?.data ?
{ label: 'Active', value: 'active' }, getCategory.data?.data?.categories?.map((item: ServiceCategoryType) => ({
{ label: 'Inactive', value: 'inactive' }, label: item.title,
]} value: item.id,
}))
: []
}
placeholder={t('service.category')} placeholder={t('service.category')}
onChange={(e) => setCategory(e.target.value)}
/> />
<Select <Select
className='w-36' className='w-36'
items={[ items={[
{ label: 'All', value: 'all' }, { label: t('all'), value: '' },
{ label: 'Active', value: 'active' }, { label: t('service.active'), value: 'ACTIVE' },
{ label: 'Inactive', value: 'inactive' }, { label: t('service.deactive'), value: 'IN_ACTIVE' },
]} ]}
placeholder={t('service.status')} placeholder={t('service.status')}
onChange={(e) => setstatus(e.target.value as 'ACTIVE' | 'IN_ACTIVE' | '')}
/> />
<div className='flex text-sm items-center'>
<div className='text-xs whitespace-nowrap'>
{t('service.danak_sujescet')}
</div>
<CheckBoxComponent
checked={isDanakSuggest}
onChange={(e) => setIsDanakSuggest(e.target.checked)}
/>
</div>
</div> </div>
<div> <div>
<Input <Input
variant='search' variant='search'
placeholder={t('service.search')} placeholder={t('service.search')}
className='bg-white border border-border' className='bg-white border border-border'
onChangeSearchFinal={(value) => setSearch(value)}
/> />
</div> </div>
</div> </div>
<div className='relative overflow-x-auto rounded-3xl mt-9 w-full'> {
<table className='w-full text-sm '> getServices.isPending || getCategory.isPending ?
<thead className='thead'> <PageLoading />
<tr> :
<Td text='' /> <div className='relative overflow-x-auto rounded-3xl mt-9 w-full'>
<Td text={t('service.title')} /> <table className='w-full text-sm '>
<Td text={t('service.company_developed')} /> <thead className='thead'>
<Td text={t('service.category')} /> <tr>
<Td text={t('service.publish_date')} /> <Td text='' />
<Td text={t('ticket.status')} /> <Td text={t('service.title')} />
<Td text={t('ticket.detail')} /> <Td text={t('service.company_developed')} />
<Td text={''} /> <Td text={t('service.category')} />
</tr> <Td text={t('service.publish_date')} />
</thead> <Td text={t('ticket.status')} />
<tbody> <Td text={t('ticket.detail')} />
<tr className='tr'> <Td text={''} />
<Td text=''> </tr>
<div className='size-10 rounded-lg bg-red-100'></div> </thead>
</Td> <tbody>
<Td text={'دی منو'} /> {
<Td text={'شرکت داناک'} /> getServices.data?.data?.services?.map((item: ServiceItemType) => {
<Td text={'رستوران'} /> return (
<Td text={'۱۴۰۳/۰۹/۳۰'} /> <tr key={item.id} className='tr'>
<Td text={''}> <Td text=''>
<SwitchComponent <div className='size-10 rounded-lg overflow-hidden'>
active <img src={item.icon} className='size-full' />
onChange={() => null} </div>
/> </Td>
</Td> <Td text={item.name} />
<Td text={''}> <Td text={item.author} />
<Link to={Pages.ticket.detail + '1'}> <Td text={item.category?.title} />
<Eye size={20} color='#8C90A3' /> <Td text={moment(item.createDate).format('jYYYY-jMM-jDD')} />
</Link> <Td text={''}>
</Td> <ToggleStatusService
<Td text={''} /> id={item.id}
</tr> status={item.isActive}
</tbody> />
</table> </Td>
</div> <Td text={''}>
<Link to={Pages.ticket.detail + item.id}>
<Eye size={20} color='#8C90A3' />
</Link>
</Td>
<Td text={''} />
</tr>
)
})
}
</tbody>
</table>
<div className='flex justify-end pb-5'>
<Pagination
currentPage={page}
totalPages={getServices.data?.data?.pager?.totalPages}
onPageChange={setPage}
/>
</div>
</div>
}
</div> </div>
) )
} }
@@ -0,0 +1,28 @@
import { FC, useState } from 'react'
import { useToggleStatusService } from '../hooks/useServiceData'
import SwitchComponent from '../../../components/Switch'
type Props = {
id: string,
status: boolean,
}
const ToggleStatusService: FC<Props> = (props: Props) => {
const [isActive, setIsActive] = useState<boolean>(props.status)
const toggleStatus = useToggleStatusService()
const handleChange = (value: boolean) => {
setIsActive(value)
toggleStatus.mutate(props.id)
}
return (
<SwitchComponent
active={isActive}
onChange={handleChange}
/>
)
}
export default ToggleStatusService
+20
View File
@@ -6,6 +6,20 @@ import {
ToggleStatusCategoryType, ToggleStatusCategoryType,
} from "../types/ServiceTypes"; } from "../types/ServiceTypes";
export const useGetAllServices = (
search: string,
page: number,
category: string,
status: string,
isDanakSuggest: boolean
) => {
return useQuery({
queryKey: ["services", search, page, category, status, isDanakSuggest],
queryFn: () =>
api.getAllServicess(search, page, category, status, isDanakSuggest),
});
};
export const useGetCategoryParents = () => { export const useGetCategoryParents = () => {
return useQuery({ return useQuery({
queryKey: ["service-category"], queryKey: ["service-category"],
@@ -60,3 +74,9 @@ export const useMultiUpload = () => {
mutationFn: (variables: FormData) => api.uploadMultiple(variables), mutationFn: (variables: FormData) => api.uploadMultiple(variables),
}); });
}; };
export const useToggleStatusService = () => {
return useMutation({
mutationFn: (id: string) => api.toggleStatusService(id),
});
};
@@ -5,6 +5,30 @@ import {
ToggleStatusCategoryType, ToggleStatusCategoryType,
} from "../types/ServiceTypes"; } from "../types/ServiceTypes";
export const getAllServicess = async (
search: string,
page: number,
category: string,
status: string,
isDanakSuggest: boolean
) => {
let query = `?page=${page}`;
if (status) {
query += `&isActive=${status === "ACTIVE" ? "1" : "0"}`;
}
if (category) {
query += `&categoryId=${category}`;
}
if (search) {
query += `&q=${search}`;
}
if (isDanakSuggest) {
query += `&isDanakSuggest=${isDanakSuggest}`;
}
const { data } = await axios.get(`/services/list${query}`);
return data;
};
export const getCategoryParent = async () => { export const getCategoryParent = async () => {
const { data } = await axios.get(`/services/category`); const { data } = await axios.get(`/services/category`);
return data; return data;
@@ -53,3 +77,8 @@ export const uploadMultiple = async (params: FormData) => {
const { data } = await axios.post(`/uploader/multi-file`, params); const { data } = await axios.post(`/uploader/multi-file`, params);
return data; return data;
}; };
export const toggleStatusService = async (id: string) => {
const { data } = await axios.post(`/services/toggle-status/${id}`);
return data;
};
+10
View File
@@ -41,3 +41,13 @@ export type CreateServiceType = {
images?: string[]; images?: string[];
createDate: string; createDate: string;
}; };
export type ServiceItemType = {
id: string;
name: string;
author: string;
category: ServiceCategoryType;
createDate: string;
isActive: boolean;
icon: string;
};