Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…Website-FE into hotfix/dashboard-admin-verification
  • Loading branch information
whitedev7773 committed Nov 6, 2024
2 parents 92fd417 + 9566b34 commit 617cef2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
5 changes: 1 addition & 4 deletions src/pages/Board.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ export default function Board() {
const [search, setSearch] = useState('');
const debouncedSearch = useDebounce(search, 500);

const { data: adminData } = useQuery('admin', async () => {
const res = await API.GET('/admin');
return res.data;
});
const { data: adminData } = useQuery('admin', () => API.GET('/admin'));

const { data, isLoading } = useQuery(
['posts-tag-search', tag, debouncedSearch],
Expand Down
39 changes: 29 additions & 10 deletions src/pages/NewArticleEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ import { Button } from '@components/forms/Button';

import { API } from '@/utils/api';
import { Link, useNavigate } from 'react-router-dom';
import useAlert from '@/hooks/modal/useAlert';
import { Alert } from '@/components/forms/modal/Alert';
import useLoading from '@/hooks/modal/useLoading';
import { Text } from '@components/typograph/Text';
import { Loading } from '../components/forms/modal/Loading';

const Container = styled.div`
width: 100%;
Expand Down Expand Up @@ -145,12 +150,15 @@ export default function NewArticle() {
const [category, setCategory] = useState('');
const ref = useRef(null);

const { openAlert } = useAlert();

const navigate = useNavigate();

const { data: adminData, isLoading } = useQuery('admin', async () => {
const res = await API.GET('/admin');
return res.data;
});
const {
data: adminData,
isLoading,
isError,
} = useQuery('admin', () => API.GET('/admin'));

const handleSubmit = async () => {
API.POST('/posts', {
Expand Down Expand Up @@ -192,13 +200,23 @@ export default function NewArticle() {
}
}, [theme]);

if (!isLoading && !adminData) {
return <div>권한이 없습니다</div>;
}
const { showLoading, hideLoading } = useLoading();

useEffect(() => {
if (isLoading) {
showLoading({ message: '권한 검증 중' });
} else {
hideLoading();
}

if (!adminData && !isLoading) {
navigate('/board');
}
}, [isLoading, adminData]);

return (
<Container>
{isLoading ? (
{!isLoading && adminData && (
<>
<ArticleHeader>
<CategorySelect
Expand Down Expand Up @@ -251,9 +269,10 @@ export default function NewArticle() {
</BottomBarContainer>
</BottomBarWrapper>
</>
) : (
<div>불러오는 중</div>
)}

<Alert />
<Loading />
</Container>
);
}

0 comments on commit 617cef2

Please sign in to comment.