11import { useState } from "react" ;
2+ import { usePostGuard } from "@/hooks/usePostGuard" ;
23import Input from "../input/Input" ;
34import Image from "next/image" ;
45import { createDashboard } from "@/api/dashboards" ;
@@ -23,9 +24,10 @@ interface NewDashboardProps {
2324export default function NewDashboard ( { onClose, onCreate } : NewDashboardProps ) {
2425 const [ title , setTitle ] = useState ( "" ) ;
2526 const [ selected , setSelected ] = useState < number | null > ( null ) ;
26- const [ loading , setLoading ] = useState ( false ) ;
2727 const [ titleLength , setTitleLength ] = useState < number > ( 0 ) ;
2828
29+ const { guard : postGuard , isLoading } = usePostGuard ( ) ;
30+
2931 const maxTitleLength = 30 ;
3032 const colors = [ "#7ac555" , "#760DDE" , "#FF9800" , "#76A5EA" , "#E876EA" ] ;
3133
@@ -44,16 +46,15 @@ export default function NewDashboard({ onClose, onCreate }: NewDashboardProps) {
4446 } ;
4547
4648 try {
47- setLoading ( true ) ;
48- const response = await createDashboard ( payload ) ;
49- onCreate ?.( response . data ) ;
50- onClose ?.( ) ;
51- toast . success ( "대시보드가 생성되었습니다." ) ;
49+ await postGuard ( async ( ) => {
50+ const response = await createDashboard ( payload ) ;
51+ onCreate ?.( response . data ) ;
52+ onClose ?.( ) ;
53+ toast . success ( "대시보드가 생성되었습니다." ) ;
54+ } ) ;
5255 } catch ( error ) {
5356 console . error ( "대시보드 생성 실패:" , error ) ;
5457 toast . error ( "대시보드 생성에 실패했습니다." ) ;
55- } finally {
56- setLoading ( false ) ;
5758 }
5859 } ;
5960
@@ -116,12 +117,12 @@ export default function NewDashboard({ onClose, onCreate }: NewDashboardProps) {
116117 </ button >
117118 < button
118119 onClick = { handleSubmit }
119- disabled = { ! title || selected === null }
120+ disabled = { ! title || selected === null || isLoading }
120121 className = { `cursor-pointer sm:w-[256px] sm:h-[54px] w-[144px] h-[54px] rounded-[8px]
121122 border border-[var(--color-gray3)] text-[var(--color-white)]
122123 ${ ! title || selected === null ? "bg-gray-300 cursor-not-allowed" : "bg-[var(--primary)]" } ` }
123124 >
124- { loading ? "생성 중..." : "생성" }
125+ { isLoading ? "생성 중..." : "생성" }
125126 </ button >
126127 </ div >
127128 </ div >
0 commit comments