docbrown/app/javascript/chat/message.jsx
Nick Taylor 86eb75cee7
Report a Message in Connect (#12229)
* Frontend Ready for Connect Report Abuse

* add feedback api

* js defination fix

* Added Hooks to the Component

* add json response in feedback

* Block popup added

* fix render issue

* Made changes in internal view

* change error message

* Added few design changes =

* add test cases

* Update app/javascript/chat/actions/requestActions.js

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* add PR suggestions

* add backend test cases

* report abuse form close

* Update app/javascript/chat/actions/requestActions.js

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* Update app/javascript/chat/ReportAbuse/index.jsx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* add test cases

* Update app/javascript/chat/ReportAbuse/index.jsx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* Update app/javascript/chat/ReportAbuse/index.jsx

Co-authored-by: Marcy Sutton <holla@marcysutton.com>

* Update app/javascript/chat/ReportAbuse/index.jsx

Co-authored-by: Marcy Sutton <holla@marcysutton.com>

* group the fieldset

* fix report abuse api

* fix test case

* fix request test case

* fix typo

* cleaned up markup in report abuse component.

* Fixed spacing between abuse options.

* Fixed wording in report abuse confirmation.

* Removed unnecessary data-testid and aria-label attributes.

* Added some top margin to the report abuse form.

* Update app/javascript/chat/message.jsx

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Added a legend to the the fieldset.

* Update app/javascript/chat/actions/requestActions.js

Co-authored-by: Michael Kohl <citizen428@dev.to>

Co-authored-by: Sarthak <7lovesharma7@gmail.com>
Co-authored-by: Narender Singh <narender2031@gmail.com>
Co-authored-by: Marcy Sutton <holla@marcysutton.com>
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
Co-authored-by: Michael Kohl <citizen428@dev.to>
2021-01-19 12:07:47 -05:00

172 lines
4.5 KiB
JavaScript

import { h } from 'preact';
import PropTypes from 'prop-types';
// eslint-disable-next-line import/no-unresolved
import ThreeDotsIcon from 'images/overflow-horizontal.svg';
import { adjustTimestamp } from './util';
import ErrorMessage from './messages/errorMessage';
import { Button } from '@crayons';
const Message = ({
currentUserId,
id,
user,
userID,
message,
color,
type,
editedAt,
timestamp,
profileImageUrl,
onContentTrigger,
onDeleteMessageTrigger,
onReportMessageTrigger,
onEditMessageTrigger,
}) => {
const spanStyle = { color };
if (type === 'error') {
return <ErrorMessage message={message} />;
}
const MessageArea = () => {
if (userID === currentUserId) {
message = message.replace(`@${user}`, `<mark>@${user}</mark>`);
}
return (
<span
className="chatmessagebody__message"
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{ __html: message }}
/>
);
};
const dropdown = (
<div className="message__actions">
<span className="ellipsis__menubutton">
<img src={ThreeDotsIcon} alt="dropdown menu icon" />
</span>
<div className="messagebody__dropdownmenu">
<Button variant="ghost" onClick={(_) => onEditMessageTrigger(id)}>
Edit
</Button>
<Button
variant="ghost-danger"
onClick={(_) => onDeleteMessageTrigger(id)}
>
Delete
</Button>
</div>
</div>
);
const dropdownReport = (
<div className="message__actions">
<span className="ellipsis__menubutton">
<img src={ThreeDotsIcon} alt="message actions" />
</span>
<div className="messagebody__dropdownmenu report__abuse__button">
<Button
variant="ghost-danger"
onClick={(_) => onReportMessageTrigger(id)}
>
Report Abuse
</Button>
</div>
</div>
);
return (
<div className="chatmessage">
<div className="chatmessage__profilepic">
<a
href={`/${user}`}
target="_blank"
rel="noopener noreferrer"
data-content="sidecar-user"
onClick={onContentTrigger}
aria-label="View User Profile"
>
<img
className="chatmessagebody__profileimage"
src={profileImageUrl}
alt={`${user} profile`}
data-content="sidecar-user"
/>
</a>
</div>
<div
role="presentation"
className="chatmessage__body"
onClick={onContentTrigger}
>
<div className="message__info__actions">
<div className="message__info">
<span
className="chatmessagebody__username not-dark-theme-text-compatible"
style={spanStyle}
>
<a
className="chatmessagebody__username--link"
href={`/${user}`}
target="_blank"
rel="noopener noreferrer"
data-content="sidecar-user"
onClick={onContentTrigger}
>
{user}
</a>
</span>
{editedAt ? (
<span className="chatmessage__timestamp edited_message">
{`${adjustTimestamp(editedAt)}`}
<i> (edited)</i>
</span>
) : (
' '
)}
{timestamp && !editedAt ? (
<span className="chatmessage__timestamp">
{`${adjustTimestamp(timestamp)}`}
</span>
) : (
' '
)}
</div>
{userID === currentUserId ? dropdown : dropdownReport}
</div>
<div className="chatmessage__bodytext">
<MessageArea />
</div>
</div>
</div>
);
};
Message.propTypes = {
currentUserId: PropTypes.number.isRequired,
id: PropTypes.number.isRequired,
user: PropTypes.string.isRequired,
userID: PropTypes.number.isRequired,
color: PropTypes.string.isRequired,
message: PropTypes.string.isRequired,
type: PropTypes.string,
timestamp: PropTypes.string,
editedAt: PropTypes.number.isRequired,
profileImageUrl: PropTypes.string,
onContentTrigger: PropTypes.func.isRequired,
onDeleteMessageTrigger: PropTypes.func.isRequired,
onEditMessageTrigger: PropTypes.func.isRequired,
onReportMessageTrigger: PropTypes.func.isRequired,
};
Message.defaultProps = {
type: 'normalMessage',
timestamp: null,
profileImageUrl: '',
};
export default Message;