import { Person } from '@mui/icons-material'; import { Alert, Avatar, Button, Card, CardActions, CardContent, CardHeader, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Link as MUILink, Snackbar, Typography, } from '@mui/material'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import { Link } from '@tanstack/react-router'; import { FC, useState } from 'react'; import { useTranslation } from 'react-i18next'; import Api from '../../api/Api'; import { PostAuth, PostNonAuth } from '../../types/Post'; import convertDate from '../../utils/date'; import PostEditDialog from '../Dialogs/PostEdit/PostEditDialog'; import ErrorComponent from '../Error/ErrorComponent'; interface Props { post: PostNonAuth | PostAuth; } const Post: FC = ({ post }) => { const [deleteOpen, setDeleteOpen] = useState(false); const [editOpen, setEditOpen] = useState(false); //eslint-disable-next-line @typescript-eslint/no-explicit-any const [error, setError] = useState(); const deleteMutation = useMutation({ mutationFn: (id: number) => { return Api.deletePost(id); }, }); const queryClient = useQueryClient(); const { t } = useTranslation(); return ( ) : ( ) ) : ( ) } title={ 'id' in post.user ? ( post.user.id !== Api.getAuthenticatedUser()?.id ? ( {post.user.username} ) : ( {post.user.username} ) ) : ( post.user.username ) } subheader={convertDate(post.postedAt)} /> {(Api.isAdmin() || ('id' in post.user && post.user.id === Api.getAuthenticatedUser()?.id)) && ( <> setEditOpen(false)} /> )} {Api.isAdmin() && ( <> setDeleteOpen(false)}> {t('Confirm post delete title')} {t('Confirm post delete body', { name: post.user.username })} )} { deleteMutation.reset(); }} TransitionProps={{ onExited: () => setError(undefined), }} > {error && } ); }; export default Post;