From cbe88f385f713133864353fb357a1210a7d1df99 Mon Sep 17 00:00:00 2001 From: shunsuke-tamura Date: Fri, 28 Jun 2024 16:33:17 +0900 Subject: [PATCH] =?UTF-8?q?bug-fix:=20204=E3=81=AE=E3=83=AA=E3=82=AF?= =?UTF-8?q?=E3=82=A8=E3=82=B9=E3=83=88=E3=82=92zodios=E4=BD=BF=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E5=8F=A9=E3=81=8F=E3=81=A8=E3=83=80=E3=83=A1=E3=81=A0?= =?UTF-8?q?=E3=81=A8=E3=81=84=E3=81=86=E3=81=93=E3=81=A8=E3=81=8C=E3=82=8F?= =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=9F=E3=81=AE=E3=81=A7=E3=80=81fetch?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E3=81=88=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app/routes/posts.$postId.tsx | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/frontend/app/routes/posts.$postId.tsx b/frontend/app/routes/posts.$postId.tsx index 5a3b2f8..13493b1 100644 --- a/frontend/app/routes/posts.$postId.tsx +++ b/frontend/app/routes/posts.$postId.tsx @@ -1,8 +1,4 @@ -import { - type ActionFunctionArgs, - type LoaderFunctionArgs, - json, -} from "@remix-run/node"; +import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node"; import { Form, Link, @@ -11,10 +7,9 @@ import { useParams, } from "@remix-run/react"; import classNames from "classnames"; -import { useState } from "react"; import formatDate from "utils/formatDate"; -import apiClient from "~/apiClient/apiClient"; -import Dialog, { useDialog } from "~/components/dialog"; +import apiClient, { API_BASE_URL } from "~/apiClient/apiClient"; +import { useDialog } from "~/components/dialog"; export async function loader({ params, request }: LoaderFunctionArgs) { try { @@ -48,19 +43,16 @@ export async function loader({ params, request }: LoaderFunctionArgs) { export async function action({ params, request }: ActionFunctionArgs) { const postId = Number.parseInt(params.postId as string); try { - await apiClient.deletePost(undefined, { - params: { - postId, - }, + await fetch(`${API_BASE_URL}/posts/${postId}`, { + method: "DELETE", headers: { Cookie: request.headers.get("Cookie") as string, }, }); return redirect("/"); } catch (e) { - return new Response((e as Error).message, { - status: 400, - }); + console.error(e); + throw new Response(JSON.stringify(e), { status: 500 }); } }