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