forked from baron/baron-sso
af 린트 적용
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { AxiosError } from "axios";
|
||||
import { ArrowLeft, Shield, Trash2, UserPlus, Users } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { Link, useParams } from "react-router-dom";
|
||||
@@ -62,14 +63,13 @@ export function UserGroupDetailPage() {
|
||||
const [selectedTargetTenantId, setSelectedTargetTenantId] = useState("");
|
||||
const [selectedRelation, setSelectedRelation] = useState("view");
|
||||
|
||||
// Fetch specific group details
|
||||
const {
|
||||
data: currentGroup,
|
||||
isLoading: isGroupLoading,
|
||||
error,
|
||||
} = useQuery({
|
||||
queryKey: ["user-group-detail", id],
|
||||
queryFn: () => fetchGroup(tenantId!, id!),
|
||||
queryFn: () => fetchGroup(tenantId ?? "", id ?? ""),
|
||||
enabled: !!id && !!tenantId,
|
||||
retry: false,
|
||||
});
|
||||
@@ -77,7 +77,7 @@ export function UserGroupDetailPage() {
|
||||
// Fetch assigned roles
|
||||
const { data: groupRoles, isLoading: isRolesLoading } = useQuery({
|
||||
queryKey: ["user-group-roles", id],
|
||||
queryFn: () => fetchGroupRoles(tenantId!, id!),
|
||||
queryFn: () => fetchGroupRoles(tenantId ?? "", id ?? ""),
|
||||
enabled: !!id && !!tenantId,
|
||||
});
|
||||
|
||||
@@ -96,7 +96,7 @@ export function UserGroupDetailPage() {
|
||||
});
|
||||
|
||||
const addMemberMutation = useMutation({
|
||||
mutationFn: (userId: string) => addGroupMember(tenantId!, id!, userId),
|
||||
mutationFn: (userId: string) => addGroupMember(tenantId ?? "", id ?? "", userId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["user-group-detail", id] });
|
||||
setIsAddMemberOpen(false);
|
||||
@@ -105,15 +105,17 @@ export function UserGroupDetailPage() {
|
||||
t("msg.admin.groups.members.add_success", "구성원이 추가되었습니다."),
|
||||
);
|
||||
},
|
||||
onError: (error: any) => {
|
||||
onError: (error: AxiosError<{ error?: string }>) => {
|
||||
toast.error(
|
||||
error.message || t("err.common.unknown", "오류가 발생했습니다."),
|
||||
error.response?.data?.error ||
|
||||
error.message ||
|
||||
t("err.common.unknown", "오류가 발생했습니다."),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
const removeMemberMutation = useMutation({
|
||||
mutationFn: (userId: string) => removeGroupMember(tenantId!, id!, userId),
|
||||
mutationFn: (userId: string) => removeGroupMember(tenantId ?? "", id ?? "", userId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["user-group-detail", id] });
|
||||
toast.success(
|
||||
@@ -127,7 +129,7 @@ export function UserGroupDetailPage() {
|
||||
|
||||
const assignRoleMutation = useMutation({
|
||||
mutationFn: () =>
|
||||
assignGroupRole(tenantId!, id!, selectedTargetTenantId, selectedRelation),
|
||||
assignGroupRole(tenantId ?? "", id ?? "", selectedTargetTenantId, selectedRelation),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["user-group-roles", id] });
|
||||
setIsAddRoleOpen(false);
|
||||
@@ -135,16 +137,18 @@ export function UserGroupDetailPage() {
|
||||
t("msg.admin.groups.roles.assign_success", "역할이 할당되었습니다."),
|
||||
);
|
||||
},
|
||||
onError: (error: any) => {
|
||||
onError: (error: AxiosError<{ error?: string }>) => {
|
||||
toast.error(
|
||||
error.message || t("err.common.unknown", "오류가 발생했습니다."),
|
||||
error.response?.data?.error ||
|
||||
error.message ||
|
||||
t("err.common.unknown", "오류가 발생했습니다."),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
const removeRoleMutation = useMutation({
|
||||
mutationFn: (role: { targetTenantId: string; relation: string }) =>
|
||||
removeGroupRole(tenantId!, id!, role.targetTenantId, role.relation),
|
||||
removeGroupRole(tenantId ?? "", id ?? "", role.targetTenantId, role.relation),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["user-group-roles", id] });
|
||||
toast.success(
|
||||
@@ -172,8 +176,8 @@ export function UserGroupDetailPage() {
|
||||
<div className="p-4 bg-destructive/10 text-destructive rounded-md text-left text-sm font-mono overflow-auto max-w-xl mx-auto border border-destructive/20">
|
||||
<p>
|
||||
Error:{" "}
|
||||
{(error as any)?.response?.data?.error ||
|
||||
(error as any)?.message ||
|
||||
{(error as AxiosError<{ error?: string }>)?.response?.data?.error ||
|
||||
error.message ||
|
||||
"Not found"}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user