11'use client' ;
22import { getApi } from '@/app/api/config/appConfig' ;
3- import { useToast } from '@/shared/hook/useToast' ;
43import clsx from 'clsx' ;
54import { useEffect , useState } from 'react' ;
5+ import AlarmConfirm from './pages/my-alarm/AlarmConfirm' ;
66
77function ToggleBtn ( ) {
8- const [ isClick , setIsClick ] = useState < boolean | null > ( null ) ;
9- const { toastSuccess } = useToast ( ) ;
8+ const [ isAlarm , setIsAlarm ] = useState < boolean | null > ( null ) ;
9+ const [ isClick , setIsClick ] = useState < boolean > ( false ) ;
1010
1111 useEffect ( ( ) => {
1212 const fetchToggle = async ( ) => {
@@ -16,7 +16,8 @@ function ToggleBtn() {
1616 credentials : 'include' ,
1717 } ) ;
1818 const json = await res . json ( ) ;
19- setIsClick ( json . data . enabled ) ;
19+ console . log ( json ) ;
20+ setIsAlarm ( json . data . enabled ) ;
2021 } catch {
2122 console . error ( ) ;
2223 }
@@ -25,36 +26,36 @@ function ToggleBtn() {
2526 } , [ ] ) ;
2627
2728 const handleClick = async ( ) => {
28- if ( isClick === null ) return ;
29- const next = ! isClick ;
30- setIsClick ( next ) ;
31-
32- await fetch ( `${ getApi } /me/notification-setting` , {
33- method : 'PATCH' ,
34- credentials : 'include' ,
35- headers : { 'Content-Type' : 'application/json' } ,
36- body : JSON . stringify ( {
37- enabled : next ,
38- } ) ,
39- } ) ;
40- next ? toastSuccess ( '알림이 설정되었습니다.' ) : toastSuccess ( '알림이 해제되었습니다' ) ;
29+ setIsClick ( true ) ;
4130 } ;
4231
4332 return (
44- < button
45- className = { clsx (
46- 'rounded-full flex py-0.5 pl-[2px] w-17 h-7 duration-300' ,
47- isClick ? 'bg-tertiary' : 'bg-white'
33+ < div >
34+ { isClick && (
35+ < AlarmConfirm
36+ open = { isClick }
37+ onClose = { ( ) => setIsClick ( false ) }
38+ state = { isAlarm }
39+ cancle = { ( ) => setIsClick ( isClick ) }
40+ setIsAlarm = { setIsAlarm }
41+ setIsClick = { setIsClick }
42+ />
4843 ) }
49- onClick = { handleClick }
50- >
51- < div
44+ < button
5245 className = { clsx (
53- 'rounded-full w-6 h-6 duration-300' ,
54- isClick ? 'bg-secondary translate-x-10 ' : 'bg-gray-dark '
46+ 'rounded-full flex py-0.5 pl-[2px] w-17 h-7 duration-300' ,
47+ isAlarm ? 'bg-tertiary ' : 'bg-white '
5548 ) }
56- > </ div >
57- </ button >
49+ onClick = { handleClick }
50+ >
51+ < div
52+ className = { clsx (
53+ 'rounded-full w-6 h-6 duration-300' ,
54+ isAlarm ? 'bg-secondary translate-x-10' : 'bg-gray-dark'
55+ ) }
56+ > </ div >
57+ </ button >
58+ </ div >
5859 ) ;
5960}
6061export default ToggleBtn ;
0 commit comments