diff --git a/src/app/admin/block/components/layout.tsx b/src/app/admin/block/components/layout.tsx index 26ae28ae..aae284f2 100644 --- a/src/app/admin/block/components/layout.tsx +++ b/src/app/admin/block/components/layout.tsx @@ -2,6 +2,7 @@ import React, { FormEvent } from "react"; import Image from "next/image"; import { useRouter } from "next/navigation"; +import QuestionIcon from "@app/admin/block/components/question-icon"; const Layout = ({ title, @@ -9,7 +10,7 @@ const Layout = ({ children, }: Readonly<{ title: string; - onSubmit: (e: FormEvent) => void; + onSubmit?: (e: FormEvent) => void; children: React.ReactNode; }>) => { const router = useRouter(); @@ -27,21 +28,7 @@ const Layout = ({

{title}

-
- question - {title === "링크 블록" && ( -
- • 기본 정보와 공개 여부 값은 필수입니다.
• 예약 공개와 - 스티커는 프로 기능입니다. -
-
- )} -
+
{children} diff --git a/src/app/admin/block/image/components/image-box.tsx b/src/app/admin/block/image/components/image-box.tsx index 827dc2e7..dc03b17e 100644 --- a/src/app/admin/block/image/components/image-box.tsx +++ b/src/app/admin/block/image/components/image-box.tsx @@ -3,11 +3,11 @@ import Image from "next/image"; import ErrorBoundary from "@app/(intro)/components/error-boundary"; interface Props { - handeInputImageClick: () => void; + // handeInputImageClick: () => void; selectedImageUrl: string; } -const ImageBox = ({ handeInputImageClick, selectedImageUrl }: Props) => { +const ImageBox = ({ selectedImageUrl }: Props) => { return (
{/* { - const inputImageRef = useRef(null); + // const inputImageRef = useRef(null); const [title, setTitle] = useState(""); const [connectingUrl, setConnectingUrl] = useState(""); const [selectedImageUrl, setSelectedImageUrl] = useState(""); const router = useRouter(); - const setResponseMessage = async (response: Response) => { - if (response.ok) { - console.log("성공"); - return response.json(); - } else { - const errorResponse = await response.json(); - const { status } = response; - const { message } = errorResponse; - console.log(status); - if (status === 500) { - alert("서버 에러"); - } - console.log(`Error: ${status}, Message: ${message || "Unknown error"}`); - throw new Error(`Error: ${response.status}`); - } - }; - const postBlock = async ( - path: string, - params: { [index: string]: string | number }, - ) => { - const token = sessionStorage.getItem("token"); - if (!token) { - router.push("/login"); - return; - } - const nowSequence = await getSequence(token); - params["sequence"] = nowSequence + 1; - - try { - const response = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}${path}`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${token}`, - }, - body: JSON.stringify(params), - }, - ); - return await setResponseMessage(response); - } catch (error) { - throw new Error( - error instanceof Error ? error.message : "알 수 없는 에러", - ); - } - }; - const newAddImageBlock = async () => { + const addImageBlock = () => { const params = { type: 4, title, url: connectingUrl, imgUrl: selectedImageUrl, }; - postBlock("/api/link/add", params) - .then((response) => async () => { - if (response.ok) { - console.log("성공"); - return response.json(); - } else { - const errorResponse = await response.json(); - const { status } = response; - const { message } = errorResponse; - console.log(status); - if (status === 500) { - alert("서버 에러"); - } - console.log( - `Error: ${status}, Message: ${message || "Unknown error"}`, - ); - throw new Error(`Error: ${response.status}`); - } - }) - .catch((error) => { - console.error(error); - alert("서버 응답이 실패했습니다."); - }); + postBlock("/api/link/add", params, router).then((res) => { + if (res) console.log(res); + }); }; // const addImageBlock = async () => { @@ -137,12 +71,12 @@ const Page = () => { const handleAddButtonClick = (e: FormEvent) => { e.preventDefault(); if (!selectedImageUrl) return; - newAddImageBlock().then(); + addImageBlock(); }; - const handeInputImageClick = () => { - inputImageRef.current?.click(); - }; + // const handeInputImageClick = () => { + // inputImageRef.current?.click(); + // }; // const selectFile = (e: React.ChangeEvent) => { // const file = e.target.files?.[0]; @@ -197,7 +131,7 @@ const Page = () => { {/*/>*/} { }; console.log(nowSequence); try { - const response = await fetch(`/api/api/link/add`, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${token}`, + const response = await fetch( + `${process.env.NEXT_PUBLIC_API_URL}/api/link/add`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + body: JSON.stringify(params), }, - body: JSON.stringify(params), - }); + ); if (response.ok) { alert("비디오 블록 추가 완료"); router.push("/admin"); diff --git a/src/lib/post-block.ts b/src/lib/post-block.ts new file mode 100644 index 00000000..048ae71c --- /dev/null +++ b/src/lib/post-block.ts @@ -0,0 +1,40 @@ +import { getSequence } from "./get-sequence"; +import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime"; + +export const postBlock = async ( + path: string, + params: { [index: string]: string | number }, + router?: AppRouterInstance, +) => { + const token = sessionStorage.getItem("token"); + if (!token) { + if (router) router.push("/login"); + return; + } + params["sequence"] = (await getSequence(token)) + 1; + + try { + const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}${path}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + body: JSON.stringify(params), + }); + const responseJson = await response.json(); + if (response.ok) { + console.log("성공"); + return responseJson; + } else { + const { status } = response; + const { message } = responseJson; + if (status === 500) { + alert("서버 에러"); + } + console.log(`Error: ${status}, Message: ${message || "Unknown error"}`); + } + } catch (error) { + throw new Error(error instanceof Error ? error.message : "알 수 없는 에러"); + } +};