-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
164 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"use client"; | ||
|
||
import { | ||
SnackbarVariant, | ||
useGlobalSnackbarStore, | ||
} from "@/store/useGlobalSnackbarStore"; | ||
import { CheckCircle, Error, Warning } from "@mui/icons-material"; | ||
import { Snackbar, SnackbarContent, Stack } from "@mui/material"; | ||
|
||
const GlobalToast = () => { | ||
const { isOpen, variant, message, closeToast } = useGlobalSnackbarStore(); | ||
return ( | ||
<Snackbar | ||
open={isOpen} | ||
color={variant} | ||
key={message} | ||
onClose={closeToast} | ||
autoHideDuration={3000} | ||
anchorOrigin={{ vertical: "bottom", horizontal: "center" }} | ||
sx={{ mb: 6 }} | ||
> | ||
<SnackbarContent | ||
message={<SnackbarMessage variant={variant} message={message} />} | ||
/> | ||
</Snackbar> | ||
); | ||
}; | ||
|
||
const SnackbarMessage = ({ | ||
message, | ||
variant, | ||
}: { | ||
message: string; | ||
variant: SnackbarVariant; | ||
}) => { | ||
return ( | ||
<Stack direction="row" gap={1} alignItems="center"> | ||
{IconSelector(variant)} | ||
{message} | ||
</Stack> | ||
); | ||
}; | ||
|
||
const IconSelector = (variant: SnackbarVariant) => { | ||
switch (variant) { | ||
case "danger": | ||
return <Error sx={{color:'red'}} />; | ||
case "warning": | ||
return <Warning sx={{color:'orange'}}/>; | ||
default: | ||
return <CheckCircle sx={{color:'green'}}/>; | ||
} | ||
}; | ||
|
||
export default GlobalToast; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { useState } from "react"; | ||
import { MoreVertOutlined } from "@mui/icons-material"; | ||
import { ButtonBase, Menu, MenuItem } from "@mui/material"; | ||
import { useDeletePostMutation } from "@/queries/post/useDeletePostMutation"; | ||
|
||
type PostCardOptionDropdownProps = { | ||
postId:number | ||
}; | ||
|
||
const PostCardOptionDropdown = ({postId}: PostCardOptionDropdownProps) => { | ||
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); | ||
const open = Boolean(anchorEl); | ||
|
||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
const {mutate:deletePost}=useDeletePostMutation() | ||
|
||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
return ( | ||
<> | ||
<ButtonBase aria-label="settings" sx={{ p: 0 }} onClick={handleClick}> | ||
<MoreVertOutlined /> | ||
</ButtonBase> | ||
<Menu open={open} anchorEl={anchorEl} onClose={handleClose}> | ||
<MenuItem onClick={()=>{ | ||
if(confirm('정말 삭제하시겠습니까?')){ | ||
deletePost(postId) | ||
} | ||
}}>삭제</MenuItem> | ||
<MenuItem>수정</MenuItem> | ||
</Menu> | ||
</> | ||
); | ||
}; | ||
|
||
export default PostCardOptionDropdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { create } from "zustand"; | ||
|
||
interface GlobalSnackbarStore { | ||
isOpen: boolean; | ||
message: string; | ||
variant: SnackbarVariant; | ||
fireToast: (message: string, variant?: SnackbarVariant) => void; | ||
closeToast:()=>void | ||
} | ||
export type SnackbarVariant = "neutral" | "success" | "danger" | "warning"; | ||
|
||
export const useGlobalSnackbarStore = create<GlobalSnackbarStore>((set) => ({ | ||
isOpen: false, | ||
message: "", | ||
variant: "neutral", | ||
fireToast: (message, variant = "neutral") => | ||
set({ isOpen: true, message, variant }), | ||
closeToast: () => set((prev) => ({ ...prev, message: "", isOpen: false })), | ||
})); | ||
|
||
export const useFireToast =()=> useGlobalSnackbarStore((state)=>state.fireToast) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
export default function errorHandler(error: string) { | ||
console.log(error); | ||
"use client"; | ||
// import { useGlobalSnackbarStore } from "@/store/useGlobalSnackbarStore"; | ||
import { isAxiosError } from "axios"; | ||
|
||
export default function ErrorHandler(error: Error) { | ||
// const { fireToast } = useGlobalSnackbarStore(); | ||
if (isAxiosError(error) && error.response) { | ||
// FIXME : Zustand 사용 연구 | ||
// error.response.status === 401 && fireToast("로그인 후 이용 가능합니다"); | ||
error.response.status === 401 && console.log("로그인 후 이용 가능합니다"); | ||
} | ||
} |