| 2838 |
stevensc |
1 |
import React, { useState } from 'react'
|
|
|
2 |
import { useDispatch, useSelector } from 'react-redux'
|
|
|
3 |
import { Box, Button, styled, Typography } from '@mui/material'
|
|
|
4 |
import { ChatOutlined, SendOutlined, ShareOutlined } from '@mui/icons-material'
|
|
|
5 |
|
| 2864 |
stevensc |
6 |
import { withReactions } from '@hocs'
|
| 2838 |
stevensc |
7 |
import { feedTypes } from '@app/redux/feed/feed.types'
|
|
|
8 |
import { openShareModal } from '@app/redux/share-modal/shareModal.actions'
|
|
|
9 |
import { shareModalTypes } from '@app/redux/share-modal/shareModal.types'
|
|
|
10 |
import withExternalShare from '../linkedin/withExternalShare'
|
|
|
11 |
|
|
|
12 |
import Widget from '@components/UI/Widget'
|
| 2846 |
stevensc |
13 |
import Comments from '../linkedin/comments/comments'
|
| 2899 |
stevensc |
14 |
import Reactions from '../reactions/reactions'
|
| 2838 |
stevensc |
15 |
|
|
|
16 |
const Row = styled(Box)(({ theme }) => ({
|
|
|
17 |
display: 'flex',
|
|
|
18 |
padding: theme.spacing(0.5),
|
|
|
19 |
justifyContent: 'space-between',
|
|
|
20 |
alignItems: 'center',
|
|
|
21 |
gap: theme.spacing(0.5)
|
|
|
22 |
}))
|
|
|
23 |
|
|
|
24 |
export default function FeedActions({ id }) {
|
|
|
25 |
const {
|
|
|
26 |
comments,
|
| 2846 |
stevensc |
27 |
comment_add_url: commentAddUrl,
|
|
|
28 |
owner_comments: ownerComments,
|
| 2838 |
stevensc |
29 |
feed_reactions_url: reactionsUrl,
|
|
|
30 |
feed_content_type: contentType,
|
|
|
31 |
owner_shared: totalShared,
|
|
|
32 |
feed_share_external_url: shareExternalUrl,
|
|
|
33 |
feed_save_reaction_url: saveReactionUrl,
|
|
|
34 |
feed_delete_reaction_url: deleteReactionUrl,
|
|
|
35 |
feed_increment_external_counter_url: incrementExternalCounterUrl,
|
|
|
36 |
feed_my_reaction: feedMyReaction,
|
|
|
37 |
feed_reactions: feedReactions,
|
|
|
38 |
owner_external_shared: ownerExternalShared,
|
|
|
39 |
feed_share_url: feedShareUrl,
|
|
|
40 |
feed_unique: feedUnique
|
|
|
41 |
} = useSelector(({ feed }) => feed.feeds.byId[id])
|
|
|
42 |
const labels = useSelector(({ intl }) => intl.labels)
|
|
|
43 |
const dispatch = useDispatch()
|
|
|
44 |
|
| 2846 |
stevensc |
45 |
const [totalComments, setTotalComments] = useState(ownerComments)
|
| 2838 |
stevensc |
46 |
const [reaction, setReaction] = useState(feedMyReaction)
|
|
|
47 |
const [ownerReactions, setOwnerReactions] = useState(feedReactions)
|
|
|
48 |
const [externalShare, setExternalShare] = useState(ownerExternalShared)
|
|
|
49 |
const [showComments, setShowComments] = useState(false)
|
|
|
50 |
|
|
|
51 |
const setTotalShares = (value) => setExternalShare(value)
|
|
|
52 |
|
|
|
53 |
const toggleComments = () => setShowComments((prev) => !prev)
|
|
|
54 |
|
|
|
55 |
const updateReactions = ({ reactions }, currentReaction) => {
|
|
|
56 |
setOwnerReactions(reactions)
|
|
|
57 |
setReaction(currentReaction)
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
const shareFeed = () => {
|
|
|
61 |
dispatch(
|
|
|
62 |
openShareModal(
|
|
|
63 |
feedShareUrl,
|
|
|
64 |
shareModalTypes.SHARE,
|
|
|
65 |
feedTypes.DASHBOARD,
|
|
|
66 |
feedUnique
|
|
|
67 |
)
|
|
|
68 |
)
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
const ExternalShareButton = withExternalShare(Button, shareExternalUrl)
|
|
|
72 |
const ReactionButton = withReactions(Button)
|
|
|
73 |
|
|
|
74 |
return (
|
|
|
75 |
<>
|
|
|
76 |
<Row>
|
| 2899 |
stevensc |
77 |
<Reactions reactions={ownerReactions} reactionsUrl={reactionsUrl} />
|
| 2838 |
stevensc |
78 |
|
|
|
79 |
<Row>
|
| 2893 |
stevensc |
80 |
{totalComments ? (
|
| 2917 |
stevensc |
81 |
<Typography variant='overline'>
|
| 2893 |
stevensc |
82 |
{`${totalComments} ${labels.comments?.toLowerCase()}`}
|
|
|
83 |
</Typography>
|
|
|
84 |
) : null}
|
| 2838 |
stevensc |
85 |
|
| 2893 |
stevensc |
86 |
{totalShared ? (
|
| 2917 |
stevensc |
87 |
<Typography variant='overline'>
|
| 2893 |
stevensc |
88 |
{`${totalShared} ${labels.shared?.toLowerCase()}`}
|
|
|
89 |
</Typography>
|
|
|
90 |
) : null}
|
| 2838 |
stevensc |
91 |
|
| 2893 |
stevensc |
92 |
{externalShare ? (
|
| 2917 |
stevensc |
93 |
<Typography variant='overline'>
|
| 2893 |
stevensc |
94 |
{`${externalShare} ${labels.sends?.toLowerCase()}`}
|
|
|
95 |
</Typography>
|
|
|
96 |
) : null}
|
| 2838 |
stevensc |
97 |
</Row>
|
|
|
98 |
</Row>
|
|
|
99 |
<Widget.Actions
|
|
|
100 |
styles={{ display: contentType === 'fast-survey' ? 'none' : 'flex' }}
|
|
|
101 |
>
|
|
|
102 |
<ReactionButton
|
|
|
103 |
currentReactionType={reaction}
|
|
|
104 |
saveUrl={saveReactionUrl}
|
|
|
105 |
deleteUrl={deleteReactionUrl}
|
|
|
106 |
onReaction={updateReactions}
|
|
|
107 |
/>
|
|
|
108 |
<Button onClick={toggleComments}>
|
|
|
109 |
<ChatOutlined />
|
|
|
110 |
{labels.comment}
|
|
|
111 |
</Button>
|
|
|
112 |
<Button onClick={shareFeed}>
|
|
|
113 |
<ShareOutlined />
|
|
|
114 |
{labels.share}
|
|
|
115 |
</Button>
|
|
|
116 |
<ExternalShareButton
|
|
|
117 |
shorterUrl={incrementExternalCounterUrl}
|
|
|
118 |
setValue={setTotalShares}
|
|
|
119 |
>
|
|
|
120 |
<SendOutlined />
|
|
|
121 |
{labels.send}
|
|
|
122 |
</ExternalShareButton>
|
|
|
123 |
</Widget.Actions>
|
|
|
124 |
<Box
|
|
|
125 |
sx={{
|
| 2843 |
stevensc |
126 |
display: showComments ? 'block' : 'none',
|
|
|
127 |
padding: 0.5
|
| 2838 |
stevensc |
128 |
}}
|
|
|
129 |
>
|
| 2846 |
stevensc |
130 |
<Comments
|
|
|
131 |
comments={comments}
|
|
|
132 |
addUrl={commentAddUrl}
|
|
|
133 |
onAdd={({ totalComments }) => setTotalComments(totalComments)}
|
|
|
134 |
/>
|
| 2838 |
stevensc |
135 |
</Box>
|
|
|
136 |
</>
|
|
|
137 |
)
|
|
|
138 |
}
|