2019-08-31 04:07:25 +05:00
|
|
|
import React, { useCallback } from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2022-07-29 17:40:18 +02:00
|
|
|
import { Button, Comment, Icon, Loader, Visibility } from 'semantic-ui-react';
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
import { ActivityTypes } from '../../../constants/Enums';
|
2020-08-04 01:32:46 +05:00
|
|
|
import CommentAdd from './CommentAdd';
|
2019-08-31 04:07:25 +05:00
|
|
|
import Item from './Item';
|
|
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
import styles from './Activities.module.scss';
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
const Activities = React.memo(
|
2019-08-31 04:07:25 +05:00
|
|
|
({
|
|
|
|
|
items,
|
|
|
|
|
isFetching,
|
|
|
|
|
isAllFetched,
|
2022-07-29 17:40:18 +02:00
|
|
|
isDetailsVisible,
|
|
|
|
|
isDetailsFetching,
|
2021-06-24 01:05:22 +05:00
|
|
|
canEdit,
|
|
|
|
|
canEditAllComments,
|
2019-08-31 04:07:25 +05:00
|
|
|
onFetch,
|
2022-07-29 17:40:18 +02:00
|
|
|
onDetailsToggle,
|
2019-08-31 04:07:25 +05:00
|
|
|
onCommentCreate,
|
|
|
|
|
onCommentUpdate,
|
|
|
|
|
onCommentDelete,
|
|
|
|
|
}) => {
|
|
|
|
|
const [t] = useTranslation();
|
|
|
|
|
|
2022-07-29 17:40:18 +02:00
|
|
|
const handleToggleDetailsClick = useCallback(() => {
|
|
|
|
|
onDetailsToggle(!isDetailsVisible);
|
|
|
|
|
}, [isDetailsVisible, onDetailsToggle]);
|
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
const handleCommentUpdate = useCallback(
|
|
|
|
|
(id, data) => {
|
|
|
|
|
onCommentUpdate(id, data);
|
|
|
|
|
},
|
|
|
|
|
[onCommentUpdate],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const handleCommentDelete = useCallback(
|
2020-03-25 00:15:47 +05:00
|
|
|
(id) => {
|
2019-08-31 04:07:25 +05:00
|
|
|
onCommentDelete(id);
|
|
|
|
|
},
|
|
|
|
|
[onCommentDelete],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
2022-07-29 17:40:18 +02:00
|
|
|
<div className={styles.contentModule}>
|
|
|
|
|
<div className={styles.moduleWrapper}>
|
|
|
|
|
<Icon name="list ul" className={styles.moduleIcon} />
|
|
|
|
|
<div className={styles.moduleHeader}>
|
|
|
|
|
{t('common.actions')}
|
|
|
|
|
<Button
|
|
|
|
|
content={isDetailsVisible ? t('action.hideDetails') : t('action.showDetails')}
|
|
|
|
|
className={styles.toggleButton}
|
|
|
|
|
onClick={handleToggleDetailsClick}
|
|
|
|
|
/>
|
2019-08-31 04:07:25 +05:00
|
|
|
</div>
|
2022-07-29 17:40:18 +02:00
|
|
|
{canEdit && <CommentAdd onCreate={onCommentCreate} />}
|
|
|
|
|
<div className={styles.wrapper}>
|
|
|
|
|
<Comment.Group>
|
|
|
|
|
{items.map((item) =>
|
2022-08-04 13:31:14 +02:00
|
|
|
item.type === ActivityTypes.COMMENT_CARD ? (
|
2022-07-29 17:40:18 +02:00
|
|
|
<Item.Comment
|
|
|
|
|
key={item.id}
|
|
|
|
|
data={item.data}
|
|
|
|
|
createdAt={item.createdAt}
|
|
|
|
|
isPersisted={item.isPersisted}
|
|
|
|
|
user={item.user}
|
|
|
|
|
canEdit={(item.user.isCurrent && canEdit) || canEditAllComments}
|
|
|
|
|
onUpdate={(data) => handleCommentUpdate(item.id, data)}
|
|
|
|
|
onDelete={() => handleCommentDelete(item.id)}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<Item
|
|
|
|
|
key={item.id}
|
|
|
|
|
type={item.type}
|
|
|
|
|
data={item.data}
|
|
|
|
|
createdAt={item.createdAt}
|
|
|
|
|
user={item.user}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
)}
|
|
|
|
|
</Comment.Group>
|
2019-08-31 04:07:25 +05:00
|
|
|
</div>
|
2022-07-29 17:40:18 +02:00
|
|
|
{isFetching || isDetailsFetching ? (
|
|
|
|
|
<Loader active inverted inline="centered" size="small" className={styles.loader} />
|
|
|
|
|
) : (
|
|
|
|
|
!isAllFetched && <Visibility fireOnMount onOnScreen={onFetch} />
|
|
|
|
|
)}
|
2019-08-31 04:07:25 +05:00
|
|
|
</div>
|
2022-07-29 17:40:18 +02:00
|
|
|
</div>
|
2019-08-31 04:07:25 +05:00
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
Activities.propTypes = {
|
2019-08-31 04:07:25 +05:00
|
|
|
items: PropTypes.array.isRequired, // eslint-disable-line react/forbid-prop-types
|
|
|
|
|
isFetching: PropTypes.bool.isRequired,
|
|
|
|
|
isAllFetched: PropTypes.bool.isRequired,
|
2022-07-29 17:40:18 +02:00
|
|
|
isDetailsVisible: PropTypes.bool.isRequired,
|
|
|
|
|
isDetailsFetching: PropTypes.bool.isRequired,
|
2021-06-24 01:05:22 +05:00
|
|
|
canEdit: PropTypes.bool.isRequired,
|
|
|
|
|
canEditAllComments: PropTypes.bool.isRequired,
|
2019-08-31 04:07:25 +05:00
|
|
|
onFetch: PropTypes.func.isRequired,
|
2022-07-29 17:40:18 +02:00
|
|
|
onDetailsToggle: PropTypes.func.isRequired,
|
2019-08-31 04:07:25 +05:00
|
|
|
onCommentCreate: PropTypes.func.isRequired,
|
|
|
|
|
onCommentUpdate: PropTypes.func.isRequired,
|
|
|
|
|
onCommentDelete: PropTypes.func.isRequired,
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
export default Activities;
|