forked from baron/baron-sso
클라이언트 상태 토글 기능 활성화 및 전역 알림 추가
This commit is contained in:
@@ -55,7 +55,18 @@ function ClientsPage() {
|
|||||||
const updateStatusMutation = useMutation({
|
const updateStatusMutation = useMutation({
|
||||||
mutationFn: (payload: { id: string; status: "active" | "inactive" }) =>
|
mutationFn: (payload: { id: string; status: "active" | "inactive" }) =>
|
||||||
updateClientStatus(payload.id, payload.status),
|
updateClientStatus(payload.id, payload.status),
|
||||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ["clients"] }),
|
onSuccess: (_, variables) => {
|
||||||
|
const statusText = variables.status === "active" ? "활성화" : "비활성화";
|
||||||
|
toast(`클라이언트가 ${statusText}되었습니다.`);
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["clients"] });
|
||||||
|
},
|
||||||
|
onError: (error: AxiosError<{ error?: string }>) => {
|
||||||
|
const errMsg =
|
||||||
|
error.response?.data?.error ??
|
||||||
|
error.message ??
|
||||||
|
"Failed to update client status";
|
||||||
|
toast(errMsg, "error");
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const deleteMutation = useMutation({
|
const deleteMutation = useMutation({
|
||||||
mutationFn: (clientId: string) => deleteClient(clientId),
|
mutationFn: (clientId: string) => deleteClient(clientId),
|
||||||
@@ -256,6 +267,10 @@ function ClientsPage() {
|
|||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<Switch
|
<Switch
|
||||||
|
disabled={
|
||||||
|
updateStatusMutation.isPending &&
|
||||||
|
updateStatusMutation.variables?.id === client.id
|
||||||
|
}
|
||||||
checked={client.status === "active"}
|
checked={client.status === "active"}
|
||||||
onCheckedChange={(checked) =>
|
onCheckedChange={(checked) =>
|
||||||
updateStatusMutation.mutate({
|
updateStatusMutation.mutate({
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { QueryClientProvider } from "@tanstack/react-query";
|
|||||||
import { StrictMode } from "react";
|
import { StrictMode } from "react";
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import { RouterProvider } from "react-router-dom";
|
import { RouterProvider } from "react-router-dom";
|
||||||
|
import { Toaster } from "./components/ui/toaster";
|
||||||
import { queryClient } from "./app/queryClient";
|
import { queryClient } from "./app/queryClient";
|
||||||
import { router } from "./app/routes";
|
import { router } from "./app/routes";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
@@ -16,6 +17,7 @@ createRoot(rootElement).render(
|
|||||||
<StrictMode>
|
<StrictMode>
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<RouterProvider router={router} />
|
<RouterProvider router={router} />
|
||||||
|
<Toaster />
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
</StrictMode>,
|
</StrictMode>,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user