import { FC, useEffect, useState } from 'react'; import { Modal } from '../../../../components/modal/Modal'; import { PrimaryButton } from '../../../../components/button/PrimaryButton'; import { SecondaryButton } from '../../../../components/button/SecondaryButton'; import { useAppDispatch, useAppSelector } from '../../../../redux/hooks'; import MarkdownEditor, { MarkDownPattern } from '../../../articleeditor/Editor'; import { deletePost, fetchPostById, setGroupFeedStatus, updatePost, } from '../../../../redux/slices/groupfeed'; import { ReverseButton } from '../../../../components/button/ReverseButton'; import { cn } from '../../../../lib/cn'; interface ModalUpdateProps { groupId: number; postId: number; active: boolean; setActive: (value: boolean) => void; } const ModalUpdate: FC = ({ active, setActive, groupId, postId, }) => { // const [name, setName] = useState(''); const [content, setContent] = useState(''); const status = useAppSelector((state) => state.groupfeed.updatePost.status); const statusDelete = useAppSelector( (state) => state.groupfeed.deletePost.status, ); const { post, status: statusPost } = useAppSelector( (state) => state.groupfeed.fetchPostById, ); const dispatch = useAppDispatch(); useEffect(() => { if (status == 'successful') { setActive(false); dispatch(setGroupFeedStatus({ key: 'updatePost', status: 'idle' })); } }, [status]); useEffect(() => { if (statusDelete == 'successful') { setActive(false); dispatch(setGroupFeedStatus({ key: 'deletePost', status: 'idle' })); } }, [statusDelete]); useEffect(() => { if (postId) dispatch(fetchPostById({ groupId, postId })); }, [postId]); return (
Обновить пост #{post?.id}
Загрузка...
{ setContent(v); }} />
{ dispatch( updatePost({ name: '', content, groupId, postId, }), ); }} text={status == 'idle' ? 'Сохранить' : 'Загрузка...'} disabled={ status == 'loading' || statusPost != 'successful' } /> { dispatch(deletePost({ groupId, postId })); }} color="error" text={ statusDelete == 'idle' ? 'Удалить' : 'Загрузка...' } disabled={ statusDelete == 'loading' || statusPost != 'successful' } /> { setActive(false); }} text="Отмена" />
); }; export default ModalUpdate;