Skip to content
Snippets Groups Projects
Commit 2a04d6be authored by 한동현's avatar 한동현
Browse files

feat: 라우팅 삭제 API 연동

parent 3c342280
No related branches found
No related tags found
No related merge requests found
...@@ -11,16 +11,27 @@ import { Badge } from '@/components/ui/badge'; ...@@ -11,16 +11,27 @@ import { Badge } from '@/components/ui/badge';
import { Skeleton } from '@/components/ui/skeleton'; import { Skeleton } from '@/components/ui/skeleton';
import { useAuthStore } from '@/stores/authStore'; import { useAuthStore } from '@/stores/authStore';
import { Routing } from '@/types/routing'; import { Routing } from '@/types/routing';
import {
AlertDialog,
AlertDialogContent,
AlertDialogAction,
AlertDialogCancel,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogDescription,
AlertDialogFooter,
} from '@/components/ui/alert-dialog';
export default function RoutingList() { export default function RoutingList() {
const { authFetch, selectedProject } = useAuthStore(); const { authFetch, selectedProject } = useAuthStore();
const [routings, setRoutings] = useState<Routing[] | null>(null); const [routings, setRoutings] = useState<Routing[] | null>(null);
const [selectedRouting, setSelectedRouting] = useState<Routing | null>(null);
useEffect(() => { useEffect(() => {
authFetch(`/api/routings?projectId=${selectedProject?.id}`) authFetch(`/api/routings?projectId=${selectedProject?.id}`)
.then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {
toast.error('포트포워딩 정보를 조회할 수 없습니다.'); toast.error('라우팅 정보를 조회할 수 없습니다.');
return { contents: [] }; return { contents: [] };
} }
...@@ -31,6 +42,24 @@ export default function RoutingList() { ...@@ -31,6 +42,24 @@ export default function RoutingList() {
}); });
}, [authFetch, selectedProject]); }, [authFetch, selectedProject]);
const handleDelete = () => {
if (selectedRouting === null) throw Error('selectedRouting is null');
authFetch(`/api/routing?routingId=${selectedRouting.id}`, {
method: 'DELETE',
}).then((response) => {
if (!response.ok) {
console.error(response);
toast.error('라우팅 설정 삭제에 실패했습니다');
} else {
toast.warning('라우팅 설정이 삭제되었습니다');
setRoutings((prev) => prev!.filter((routing) => routing.id !== selectedRouting.id));
}
});
setSelectedRouting(null);
};
return ( return (
<div className="flex flex-1 flex-col gap-4 p-6"> <div className="flex flex-1 flex-col gap-4 p-6">
<div className="flex justify-between mb-2"> <div className="flex justify-between mb-2">
...@@ -147,10 +176,8 @@ export default function RoutingList() { ...@@ -147,10 +176,8 @@ export default function RoutingList() {
<Pencil /> <Pencil />
</Link> </Link>
</Button> </Button>
<Button variant="secondary" className="size-8"> <Button variant="secondary" className="size-8" onClick={() => setSelectedRouting(routing)}>
<Link to={`./delete/${routing.id}`}>
<Trash /> <Trash />
</Link>
</Button> </Button>
</div> </div>
</TableCell> </TableCell>
...@@ -161,6 +188,21 @@ export default function RoutingList() { ...@@ -161,6 +188,21 @@ export default function RoutingList() {
</Table> </Table>
</CardContent> </CardContent>
</Card> </Card>
<AlertDialog open={selectedRouting !== null} onOpenChange={(open) => open || setSelectedRouting(null)}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>웹 라우팅 설정 삭제</AlertDialogTitle>
<AlertDialogDescription>
정말 '{selectedRouting?.name}' 라우팅 설정을 삭제하시겠습니까?
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>취소</AlertDialogCancel>
<AlertDialogAction onClick={handleDelete}>삭제</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div> </div>
); );
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment