show edit button only if currentUser is present and don't updateArticle if currentUser is not present
This commit is contained in:
@@ -6,6 +6,7 @@ import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackRounded';
|
||||
import EditRoundedIcon from '@mui/icons-material/EditRounded';
|
||||
import { ArticleMeta } from "../ArticleMeta";
|
||||
import { ArticleProps } from '../../types/props';
|
||||
import {useAuth} from "../../providers/Author";
|
||||
|
||||
const ArticleContainer = styled(Box)(({ theme }) => ({
|
||||
maxWidth: '800px',
|
||||
@@ -30,6 +31,7 @@ export default function ArticleView({
|
||||
onEdit,
|
||||
}: ArticleProps) {
|
||||
|
||||
const { currentUser } = useAuth();
|
||||
return (
|
||||
<ArticleContainer>
|
||||
<IconButton onClick={onBack} sx={{ mb: 2 }}>
|
||||
@@ -43,9 +45,11 @@ export default function ArticleView({
|
||||
sx={{ mb: 2, textTransform: 'uppercase', fontWeight: 500 }}
|
||||
/>
|
||||
|
||||
<IconButton onClick={onEdit} sx={{ mb: 2 }}>
|
||||
<EditRoundedIcon />
|
||||
</IconButton>
|
||||
{currentUser && (
|
||||
<IconButton onClick={onEdit} sx={{ mb: 2 }}>
|
||||
<EditRoundedIcon />
|
||||
</IconButton>
|
||||
)}
|
||||
|
||||
<Typography variant="h3" component="h1" gutterBottom fontWeight="bold">
|
||||
{article.title}
|
||||
|
||||
@@ -66,6 +66,10 @@ export const ArticleProvider: React.FC<{ children: React.ReactNode }> = ({ child
|
||||
console.error('updateArticle called without _id');
|
||||
return;
|
||||
}
|
||||
if (!currentUser) {
|
||||
console.error('updateArticle called without logged in user');
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedArticleData = normalizeArticleForApi(articleData);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user