diff --git a/src/langs/fa.json b/src/langs/fa.json index 9987bee..3c61af0 100644 --- a/src/langs/fa.json +++ b/src/langs/fa.json @@ -73,7 +73,8 @@ "sliders": "اسلایدر", "support": "پلن پشتیبانی", "feedback": "گزارش ها", - "accessLogs": "لاگ‌های دسترسی" + "accessLogs": "لاگ‌های دسترسی", + "icons": "آیکون ها" }, "slider": { "new_slider": "اسلایدر جدید", @@ -845,7 +846,12 @@ }, "icon": { "group_list": "لیست گروه های آیکون", - "add_new_group": "افزودن گروه آیکون" + "add_new_group": "افزودن گروه آیکون", + "list_icon": "لیست آیکون ها", + "add_new_icon": "افزودن آیکون", + "name": "نام", + "icons_count": "تعداد آیکون ها", + "created_at": "تاریخ ایجاد" }, "cancel": "لغو" } diff --git a/src/pages/icon/GroupList.tsx b/src/pages/icon/GroupList.tsx index f0fe2bc..686a6f9 100644 --- a/src/pages/icon/GroupList.tsx +++ b/src/pages/icon/GroupList.tsx @@ -3,14 +3,47 @@ import { useTranslation } from 'react-i18next' import Button from '../../components/Button' import { Add } from 'iconsax-react' import CreateGroupIcon from './components/CreateGroupIcon' +import { useGetGroupIcons, useDeleteGroupIcon } from './hooks/useIconData' +import Td from '../../components/Td' +import Input from '../../components/Input' +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' const GroupIconList: FC = () => { const { t } = useTranslation('global') const [showModal, setShowModal] = useState(false) + const [search, setSearch] = useState('') + const { data: groupIcons, isLoading, refetch } = useGetGroupIcons() + const deleteGroupIcon = useDeleteGroupIcon() + + const handleCloseModal = () => { + setShowModal(false) + refetch() + } + + const handleDelete = (id: string) => { + deleteGroupIcon.mutate(id, { + onSuccess: () => { + refetch() + toast.success(t('success')) + }, + onError: (error: ErrorType) => { + toast.error(error.response?.data?.error?.message[0]) + } + }) + } + + const groups = (groupIcons as unknown as { data?: GroupIconType[] })?.data || [] + const filteredGroups = groups.filter((group: GroupIconType) => + group.name.toLowerCase().includes(search.toLowerCase()) + ) return ( -
+
{t('icon.group_list')} @@ -29,9 +62,61 @@ const GroupIconList: FC = () => {
+
+
+
+ setSearch(value)} + /> +
+
+
+ + { + isLoading ? + + : +
+ + + + + + + { + filteredGroups.map((item: GroupIconType) => { + return ( + + + + ) + }) + } + +
+ + + +
+ + + +
+ handleDelete(item.id)} + isLoading={deleteGroupIcon.isPending} + /> +
+
+
+ } + setShowModal(false)} + close={handleCloseModal} />
) diff --git a/src/pages/icon/List.tsx b/src/pages/icon/List.tsx index 89e1041..e7c57d5 100644 --- a/src/pages/icon/List.tsx +++ b/src/pages/icon/List.tsx @@ -1,12 +1,41 @@ -import { type FC } from 'react' +import { useState, type FC } from 'react' import { useGetIcons } from './hooks/useIconData' +import { useTranslation } from 'react-i18next' +import Button from '../../components/Button' +import { Add } from 'iconsax-react' const IconsList: FC = () => { + const { t } = useTranslation('global') + const [showModal, setShowModal] = useState(false) const { data: icons, isLoading, refetch } = useGetIcons() + const handleCloseModal = () => { + setShowModal(false) + refetch() + } + return ( -
IconsList
+
+
+
+ {t('icon.list_icon')} +
+ + +
+ +
) } diff --git a/src/pages/icon/hooks/useIconData.ts b/src/pages/icon/hooks/useIconData.ts index 6d04153..baa013f 100644 --- a/src/pages/icon/hooks/useIconData.ts +++ b/src/pages/icon/hooks/useIconData.ts @@ -1,5 +1,6 @@ import { useMutation, useQuery } from "@tanstack/react-query"; import * as api from "../service/IconService"; +import { GroupIconsResponse } from "../types/Types"; export const useGetIcons = () => { return useQuery({ @@ -13,3 +14,16 @@ export const useCreateGroupIcon = () => { mutationFn: api.createGroupIcon, }); }; + +export const useGetGroupIcons = () => { + return useQuery({ + queryKey: ["group-icons"], + queryFn: api.getGroupIcons, + }); +}; + +export const useDeleteGroupIcon = () => { + return useMutation({ + mutationFn: (id: string) => api.deleteGroupIcon(id), + }); +}; diff --git a/src/pages/icon/service/IconService.ts b/src/pages/icon/service/IconService.ts index 6979580..7715ff6 100644 --- a/src/pages/icon/service/IconService.ts +++ b/src/pages/icon/service/IconService.ts @@ -1,5 +1,5 @@ import axios from "../../../config/axios"; -import { CreateGroupIconType } from "../types/Types"; +import { CreateGroupIconType, GroupIconsResponse } from "../types/Types"; export const getIcons = async () => { const { data } = await axios.get("/admin/icons"); @@ -10,3 +10,13 @@ export const createGroupIcon = async (params: CreateGroupIconType) => { const { data } = await axios.post("/admin/icons/groups", params); return data; }; + +export const getGroupIcons = async (): Promise => { + const { data } = await axios.get("/admin/icons/groups"); + return data; +}; + +export const deleteGroupIcon = async (id: string) => { + const { data } = await axios.delete(`/admin/icons/groups/${id}`); + return data; +}; diff --git a/src/pages/icon/types/Types.ts b/src/pages/icon/types/Types.ts index 8bde863..95e7954 100644 --- a/src/pages/icon/types/Types.ts +++ b/src/pages/icon/types/Types.ts @@ -1,3 +1,18 @@ +import { IResponse } from "@/types/response.types"; + export type CreateGroupIconType = { name: string; }; + +export type GroupIconType = { + id: string; + createdAt: string; + updatedAt: string; + deletedAt: string | null; + name: string; + icons: unknown[]; +}; + +export interface GroupIconsResponse extends IResponse { + statusCode: number; +}