diff --git a/.yarnrc.yml b/.yarnrc.yml deleted file mode 100644 index fc8ec93..0000000 --- a/.yarnrc.yml +++ /dev/null @@ -1,3 +0,0 @@ -nodeLinker: node-modules - -yarnPath: .yarn/releases/yarn-3.4.1.cjs diff --git a/components/Button/Authority/index.tsx b/components/Button/Authority/index.tsx index 2617211..c7346c8 100644 --- a/components/Button/Authority/index.tsx +++ b/components/Button/Authority/index.tsx @@ -4,6 +4,7 @@ import * as api from '@/api/user' import React from 'react' import { useMutation } from 'react-query' import httpClient from '@/lib/httpClient' +import Swal from 'sweetalert2' interface AuthorityProps { email: string @@ -15,7 +16,11 @@ interface AuthorityApiProps extends AuthorityProps { const Authority = ({ email }: AuthorityProps) => { const { mutate } = useMutation(({ email, authority }: AuthorityApiProps) => httpClient.authority.put({ email, authority }), { - onSuccess: () => alert('유저 권한이 변경되었습니다!'), + onSuccess: () => + Swal.fire({ + icon: 'success', + title: '유저 권한이 변경되었습니다!', + }), }) const onClickAuthorityUser = (authority: string) => { diff --git a/components/Button/Detail/index.tsx b/components/Button/Detail/index.tsx index 8595460..5114f43 100644 --- a/components/Button/Detail/index.tsx +++ b/components/Button/Detail/index.tsx @@ -7,6 +7,9 @@ import { useRecoilValue } from 'recoil' import { useRouter } from 'next/router' import httpClient from '@/lib/httpClient' import { Storage } from '@/lib/storage' +import { CustomToastContainer } from '@/layout/HomeLayout.style' +import { toast } from 'react-toastify' +import Swal from 'sweetalert2' interface DetailBtnProps { docsId: number @@ -21,7 +24,10 @@ const DetailBtn = ({ docsId }: DetailBtnProps) => { const updateDocsTitleMutation = useMutation(() => httpClient.updateTitle.putByTitle(router.pathname, docsName), { onSuccess: (res) => { - alert('문서 이름이 변경되었습니다!') + Swal.fire({ + icon: 'success', + title: '문서 이름 변경 완료!', + }) queryClient.invalidateQueries('lastModifiedDocs') router.push(`/docs/${res.data.title}`) }, @@ -42,16 +48,18 @@ const DetailBtn = ({ docsId }: DetailBtnProps) => { const updateDocsTypeMutation = useMutation(onUpdateType, { onSuccess: (res) => { - alert('문서 이름이 변경되었습니다!') + Swal.fire({ + icon: 'success', + title: '문서 타입 변경 완료!', + }) queryClient.invalidateQueries('lastModifiedDocs') router.push(`/docs/${res.data.title}`) }, }) const onClickNavigatePage = (type: string) => { - if (type === 'VERSION') return router.push(`/version/${router.pathname}`) + if (type === 'VERSION') return router.push(`/version/${router.query.title}`) if (type === 'UPDATE' && !user.id) return alert('로그인 후 편집하실 수 있습니다!') - console.log(router) router.push(`/update/${router.query.title}`) } @@ -67,24 +75,21 @@ const DetailBtn = ({ docsId }: DetailBtnProps) => { const deleteDocsTitleMutation = useMutation(onDeleteDocsTitle, { onSuccess: () => { - alert('문서가 삭제되었습니다!') + Swal.fire({ + icon: 'success', + title: '문서 삭제 완료!', + }) router.push('/') }, }) const onClickChangeDocsName = async () => { - if (!docsName.length) { - alert('내용이 없습니다.') - return - } + if (!docsName.length) return toast.error('내용이 없습니다.') updateDocsTitleMutation.mutate() } const onClickChangeDocsType = async () => { - if (!docsType.length) { - alert('내용이 없습니다.') - return - } + if (!docsType.length) return toast.error('내용이 없습니다.') updateDocsTypeMutation.mutate() } @@ -94,6 +99,7 @@ const DetailBtn = ({ docsId }: DetailBtnProps) => { return ( + {user.authority === 'ADMIN' ? ( <> setDocsType(e.target.value)} /> diff --git a/components/Section/Header/index.tsx b/components/Section/Header/index.tsx index 221b0f2..66db36c 100644 --- a/components/Section/Header/index.tsx +++ b/components/Section/Header/index.tsx @@ -6,6 +6,7 @@ import React from 'react' import { useRouter } from 'next/router' import useUser from '@/hooks/useUser' import { headerInitState, subheaderInitState } from '@/state/headerInitState' +import { toast } from 'react-toastify' const Header = () => { const [search, setSearch] = React.useState('') @@ -15,7 +16,7 @@ const Header = () => { const navigateSearchResult = () => { if (search.length) return router.push(`/search/${search}`) - return alert('검색할 문서명을 입력해주세요!') + return toast.error('검색할 문서명을 입력해주세요!') } return ( diff --git a/hooks/useUser.tsx b/hooks/useUser.tsx index 16b3096..cc7c924 100644 --- a/hooks/useUser.tsx +++ b/hooks/useUser.tsx @@ -6,26 +6,35 @@ import { useRouter } from 'next/router' import { useQuery } from 'react-query' import { useRecoilState } from 'recoil' import httpClient from '@/lib/httpClient' +import { getAccessToken } from '@/lib/httpClient/getAccessToken' +import Swal from 'sweetalert2' interface UseUserOptions { authorizedPage?: boolean } +const getUser = async () => { + return ( + await httpClient.myuser.get({ + headers: { + Authorization: Storage.getItem('access_token'), + }, + }) + ).data +} + const useUser = (options?: UseUserOptions) => { const [user, setUser] = useRecoilState(userState) const router = useRouter() - const getUser = async () => { - return ( - await httpClient.myuser.get({ - headers: { - Authorization: Storage.getItem('access_token'), - }, - }) - ).data - } - - const { data: userInfo, remove, isLoading } = useQuery('getUser', getUser, { enabled: !!Storage.getItem('access_token') }) + const { + data: userInfo, + remove, + isLoading, + } = useQuery('getUser', getUser, { + retry: 1, + onError: () => getAccessToken(), + }) const logout = () => { httpClient.logout.delete({ @@ -41,7 +50,10 @@ const useUser = (options?: UseUserOptions) => { React.useEffect(() => { if (options?.authorizedPage && !isLoading && !userInfo) { - alert('로그인이 필요한 페이지입니다.') + Swal.fire({ + icon: 'error', + title: '로그인이 필요한 페이지입니다.', + }) router.push('/') // openModal() } diff --git a/layout/AccidentLayout.tsx b/layout/AccidentLayout.tsx new file mode 100644 index 0000000..2542464 --- /dev/null +++ b/layout/AccidentLayout.tsx @@ -0,0 +1,45 @@ +import { AccodianMenu, Aside, Board, Classify, ScrollBtn, SubFooter } from '@/components' +import Docs from '@/types/docs.type' +import React from 'react' +import * as S from './StaticLayout.style' + +interface AccidentLayoutPropsType { + years: number[] + docs: Docs[] +} + +const AccidentLayout = ({ years, docs }: AccidentLayoutPropsType) => { + return ( + + + + 부마위키:사건/사고 + + + 사건/사고 + + + + {years.map((year) => ( + + {docs.map((accident: Docs) => ( + + {accident.enroll === year && ( + + {accident.title} + + )} + + ))} + + ))} + + + + +