+26
-10
@@ -1,31 +1,47 @@
|
||||
import { useState, type FC } from "react";
|
||||
import { useGetAdmins, useDeleteAdmin } from "./hooks/useAdminData";
|
||||
import { useGetAdmins, useDeleteAdmin, useGetAdminMe } from "./hooks/useAdminData";
|
||||
import Table from "@/components/Table";
|
||||
import PresignedImage from "@/components/PresignedImage";
|
||||
import moment from "moment-jalaali";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Paths } from "@/config/Paths";
|
||||
import Button from "@/components/Button";
|
||||
import { AddSquare, Eye } from "iconsax-react";
|
||||
import { AddSquare, Eye, ShieldSecurity } from "iconsax-react";
|
||||
import TrashWithConfrim from "@/components/TrashWithConfrim";
|
||||
|
||||
const AdminList: FC = () => {
|
||||
const [page, setPage] = useState<number>(1);
|
||||
const { data } = useGetAdmins(page);
|
||||
const deleteAdminMutation = useDeleteAdmin();
|
||||
const { data: adminMe } = useGetAdminMe();
|
||||
const canManageRoles = adminMe?.data?.role?.permissions?.some(
|
||||
(p) => p.name === "manage_roles",
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="mt-5">
|
||||
<div className="flex justify-between items-center">
|
||||
<h1 className="text-lg font-light">مدیران</h1>
|
||||
<Link to={Paths.admin.create}>
|
||||
<Button className="w-fit px-6">
|
||||
<div className="flex gap-1.5">
|
||||
<AddSquare size={18} color="black" />
|
||||
<div className="text-[13px] font-light">ادمین جدید</div>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
<div className="flex gap-2">
|
||||
{canManageRoles && (
|
||||
<Link to={Paths.role.list}>
|
||||
<Button className="w-fit px-6 bg-[#F5F7FC]">
|
||||
<div className="flex gap-1.5">
|
||||
<ShieldSecurity size={18} color="black" />
|
||||
<div className="text-[13px] font-light text-black">نقشها</div>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
<Link to={Paths.admin.create}>
|
||||
<Button className="w-fit px-6">
|
||||
<div className="flex gap-1.5">
|
||||
<AddSquare size={18} color="black" />
|
||||
<div className="text-[13px] font-light">ادمین جدید</div>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Table
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as api from "../service/AdminService";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { CreateAdminType } from "../types/Types";
|
||||
import type { CreateAdminType, UpdateAdminMeType } from "../types/Types";
|
||||
|
||||
export const useGetAdmins = (page: number = 1, limit: number = 10) => {
|
||||
return useQuery({
|
||||
@@ -59,3 +59,14 @@ export const useGetAdminMe = () => {
|
||||
queryFn: api.getAdminMe,
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateAdminMe = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (params: UpdateAdminMeType) => api.updateAdminMe(params),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["adminMe"] });
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ import type {
|
||||
RolesResponseType,
|
||||
AdminDetailResponseType,
|
||||
AdminMeResponseType,
|
||||
UpdateAdminMeType,
|
||||
} from "../types/Types";
|
||||
|
||||
export const getAdmins = async (page: number, limit: number = 10) => {
|
||||
@@ -52,3 +53,8 @@ export const getAdminMe = async () => {
|
||||
const { data } = await axios.get<AdminMeResponseType>("/admin/admins/me");
|
||||
return data;
|
||||
};
|
||||
|
||||
export const updateAdminMe = async (params: UpdateAdminMeType) => {
|
||||
const { data } = await axios.patch<AdminMeResponseType>("/admin/admins/me", params);
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -65,4 +65,11 @@ export interface AdminMeDataType {
|
||||
avatarUrl?: string | null;
|
||||
role: RoleItemType;
|
||||
}
|
||||
export type UpdateAdminMeType = {
|
||||
phone: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
avatarUrl?: string;
|
||||
};
|
||||
|
||||
export type AdminMeResponseType = BaseResponse<AdminMeDataType>;
|
||||
|
||||
Reference in New Issue
Block a user