/
dedaMazai
/
TestServer
Обзор
Документация
Войти
/
dedaMazai
/
TestServer
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/features/addCommentForm/ui/AddCommentForm/AddCommentForm.tsx
78 строк
3 KB
Andrey Chipizubov
fix
23 апр 2023, 17:32
23 апр 2023, 17:32
cc424e9
Код
Авторство
О чём код?
import { useTranslation } from 'react-i18next'; import { memo, useCallback } from 'react'; import { useSelector } from 'react-redux'; import { classNames } from '@/shared/lib/classNames/classNames'; import { Input } from '@/shared/ui/Input'; import { Button, ButtonTheme } from '@/shared/ui/Button'; import { useAppDispatch } from '@/shared/lib/hooks/useAppDispatch/useAppDispatch'; import { DynamicModuleLoader, ReducersList, } from '@/shared/lib/components/DynamicModuleLoader/DynamicModuleLoader'; import { HStack } from '@/shared/ui/Stack'; import { addCommentFormActions, addCommentFormReducer, } from '../../model/slices/addCommentFormSlice'; import { getAddCommentFormError, getAddCommentFormText, } from '../../model/selectors/addCommentFormSelectors'; import cls from './AddCommentForm.module.scss'; export interface AddCommentFormProps { className?: string; onSendComment: (text: string) => void; } const reducers: ReducersList = { addCommentForm: addCommentFormReducer, }; const AddCommentForm = memo((props: AddCommentFormProps) => { const { className, onSendComment } = props; const { t } = useTranslation(); const text = useSelector(getAddCommentFormText); const error = useSelector(getAddCommentFormError); const dispatch = useAppDispatch(); const onCommentTextChange = useCallback( (value: string) => { dispatch(addCommentFormActions.setText(value)); }, [dispatch], ); const onSendHandler = useCallback(() => { onSendComment(text || ''); onCommentTextChange(''); }, [onCommentTextChange, onSendComment, text]); return ( <DynamicModuleLoader reducers={reducers}> <HStack data-testid="AddCommentForm" justify="between" max className={classNames(cls.AddCommentForm, {}, [className])} > <Input className={cls.input} placeholder={t('Введите текст комментария')} value={text} data-testid="AddCommentForm.Input" onChange={onCommentTextChange} /> <Button data-testid="AddCommentForm.Button" theme={ButtonTheme.OUTLINE} onClick={onSendHandler} > {t('Отправить')} </Button> </HStack> </DynamicModuleLoader> ); }); export default AddCommentForm;