Skip to content

Commit

Permalink
feat: alert zustand상태 분리 및 폴더 구조 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
minsu-zip committed Aug 11, 2024
1 parent a0bdb19 commit b7cb075
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/app/album/create/hooks/useAlbum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { useRouter } from "next/navigation"

import { postAlbum } from "@/app/api/photo"
import { getQueryClient } from "@/common/QueryProviders"
import { useAlert } from "@/store/AlertContext"
import { useAlertStore } from "@/store/alert"

import { usePatchPhotoAlbum } from "../../../scanner/hooks/usePhoto"
import type { AlbumType } from "../../types"

export const usePostAlbum = () => {
const { showAlert } = useAlert()
const { showAlert } = useAlertStore()
const router = useRouter()
const { patchPhotoAlbum } = usePatchPhotoAlbum()

Expand Down
4 changes: 2 additions & 2 deletions src/app/profile/_components/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Button from "@/common/Button"
import Icon from "@/common/Icon"
import { LIST_ITEM_INFO } from "@/constants"
import { isExternalLink, isInternalLink } from "@/libs"
import { useAlert } from "@/store/AlertContext"
import { useAlertStore } from "@/store/alert"

interface ItemButtonType {
label: string
Expand All @@ -21,7 +21,7 @@ export interface ListItemProps {

const ListItem = () => {
const router = useRouter()
const { showAlert } = useAlert()
const { showAlert } = useAlertStore()

const handleClick = async (item: ItemButtonType) => {
if (item.action) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/scanner/hooks/usePhoto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useMutation, useQuery } from "@tanstack/react-query"

import { getAlbums, patchPhotoAlbum, postQrCode } from "@/app/api/photo"
import { useAlert } from "@/store/AlertContext"
import { useAlertStore } from "@/store/alert"

export const usePostQrCode = () => {
const { showAlert } = useAlert()
const { showAlert } = useAlertStore()

const { data, mutate, isPending } = useMutation({
mutationFn: (code: string) => postQrCode(code),
Expand Down
37 changes: 0 additions & 37 deletions src/store/AlertContext.tsx

This file was deleted.

14 changes: 14 additions & 0 deletions src/store/alert/AlertProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use client"

import Alert from "../../common/Alert"
import useAlertStore from "./useAlertStore"

const AlertProvider = () => {
const { title, description, visible, hideAlert } = useAlertStore()

if (!visible) return null

return <Alert title={title} description={description} onClose={hideAlert} />
}

export default AlertProvider
2 changes: 2 additions & 0 deletions src/store/alert/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as AlertProvider } from "./AlertProvider"
export { default as useAlertStore } from "./useAlertStore"
20 changes: 20 additions & 0 deletions src/store/alert/useAlertStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { create } from "zustand"

interface AlertState {
title: string
description: string
visible: boolean
showAlert: (title: string, description: string) => void
hideAlert: () => void
}

const useAlertStore = create<AlertState>((set) => ({
title: "",
description: "",
visible: false,
showAlert: (title: string, description: string) =>
set({ title, description, visible: true }),
hideAlert: () => set({ visible: false }),
}))

export default useAlertStore

0 comments on commit b7cb075

Please sign in to comment.