import { FC } from 'react' import { useTranslation } from 'react-i18next' import Td from '../../components/Td' import { useChangeStatusComment, useGetBlogComments } from './hooks/useBlogData' import { BlogCommentType } from './types/BlogTypes' import moment from 'moment-jalaali' import { CloseCircle, TickCircle } from 'iconsax-react' import { ErrorType } from '../../helpers/types' import { toast } from '../../components/Toast'; import { usePermissions } from '../../hooks/usePermissions' const Comments: FC = () => { const { t } = useTranslation('global') const { canUpdate } = usePermissions() const getBlogComments = useGetBlogComments() const changeStatusComment = useChangeStatusComment() const handleChangeStatus = (id: string, status: string) => { changeStatusComment.mutate({ id, status }, { onSuccess: () => { getBlogComments.refetch() }, onError: (error: ErrorType) => { toast(error.response?.data?.error.message[0], 'error') } }) } return (
{t('blog.comments')}
{getBlogComments.data?.data?.comments?.map((item: BlogCommentType) => ( ))}
{ item.status === 'PENDING' && canUpdate('blog_comments') &&
handleChangeStatus(item.id, 'APPROVED')} color='green' size={20} /> handleChangeStatus(item.id, 'REJECTED')} color='red' size={20} />
}
) } export default Comments