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 ErrorComponent from '../Error/ErrorComponent'; interface Props { post: PostNonAuth | PostAuth; } const Post: FC = ({ post }) => { const [open, setOpen] = useState(false); 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)} /> {post.content} {Api.isAdmin() && ( <> setOpen(false)}> {t('Confirm post delete title')} {t('Confirm post delete body', { name: post.user.username })} )} deleteMutation.reset()}> {deleteMutation.isError && } ); }; export default Post;