Skip to content

Commit

Permalink
Merge pull request #86 from DDD-Community/feat/#58
Browse files Browse the repository at this point in the history
[feat/#58] 푸시 관련 이슈 수정
  • Loading branch information
G-hoon authored Sep 25, 2024
2 parents bf49668 + 68dd252 commit bf76edb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
3 changes: 3 additions & 0 deletions src/components/Posture/PostrueCrew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ export default function PostrueCrew(props: PostureCrewProps): ReactElement {
value={NOTI_VALUE_MAP(notification?.duration)}
onClick={onClickNotiAlarmTime}
/>
{!hasPermission && (
<div className="pt-2 text-sm text-amber-500">브라우저의 알람 권한 설정이 필요 합니다.</div>
)}
</div>

<div className="group relative">
Expand Down
3 changes: 0 additions & 3 deletions src/hooks/useNotiMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ export const useModifyNoti = (): UseMutationResult<notification, unknown, notifi
mutationFn: (notification: notification) => {
return registerNotification(notification)
},
onSuccess: (data) => {
console.log(data)
},
})
}

Expand Down
40 changes: 26 additions & 14 deletions src/hooks/useNotification.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
import { getNotification, notification } from "@/api/notification"
import { getNotification } from "@/api/notification"
import { useNotificationStore } from "@/store/NotificationStore"
import { useQuery } from "@tanstack/react-query"
import { useEffect } from "react"
import { useEffect, useState } from "react"

export default function useNotification() {
const { notification, setNotification } = useNotificationStore()
const [isLoading, setIsLoading] = useState(true)

// Fetch group data
const { data, isLoading, error } = useQuery<{ data: notification }, Error>({
queryKey: ["notification"],
queryFn: getNotification,
staleTime: 60 * 1000,
retry: false,
enabled: !notification,
})
// const { data, isLoading, error } = useQuery<{ data: notification }, Error>({
// queryKey: ["notification"],
// queryFn: getNotification,
// staleTime: 60 * 1000,
// })

// useEffect(() => {
// if (data) {
// setNotification(data.data)
// }
// }, [data])

useEffect(() => {
if (data) {
setNotification(data.data)
if (!notification) {
getNotification()
.then(({ data }) => {
setNotification(data)
setIsLoading(false)
})
.catch((error) => {
console.log("useNotification Error: ", error)
setIsLoading(false)
})
}
}, [data])
}, [notification])

return {
notification,
setNotification,
isLoading,
error,
// error,
}
}

0 comments on commit bf76edb

Please sign in to comment.