import { h } from 'preact'; import { PropTypes } from 'prop-types'; // eslint-disable-next-line import/no-unresolved import twitterImage from 'images/twitter-logo.svg'; // eslint-disable-next-line import/no-unresolved import githubImage from 'images/github-logo.svg'; // eslint-disable-next-line import/no-unresolved import websiteImage from 'images/external-link-logo.svg'; function blockUser(blockedUserId) { const body = { user_block: { blocked_id: blockedUserId, }, }; getCsrfToken().then(sendFetch('block-user', JSON.stringify(body))); } const setUpButton = ({ modalId = '', otherModalId = '', btnName = '' }) => { return ( ); }; setUpButton.propTypes = { modalId: PropTypes.string.isRequired, otherModalId: PropTypes.string.isRequired, btnName: PropTypes.string.isRequired, }; const userDetailsConfig = { twitter_username: { hostUrl: 'https://twitter.com/', srcImage: twitterImage, imageAltText: 'twitter logo', }, github_username: { hostUrl: 'https://github.com/', srcImage: githubImage, imageAltText: 'github logo', }, website_url: { className: 'external-link-img', hostUrl: '', srcImage: websiteImage, imageAltText: 'external link icon', }, }; const UserDetails = ({ user, activeChannelId, activeChannel }) => { const channelId = activeChannelId; const channel = activeChannel || {}; const socialIcons = []; const userMeta = ['twitter_username', 'github_username', 'website_url']; userMeta.forEach(metaProp => { if (user[metaProp]) { const { className, hostUrl, srcImage, imageAltText } = userDetailsConfig[ metaProp ]; socialIcons.push( {imageAltText} , ); } }); let userLocation = ''; if (user.location && user.location.length > 0) { userLocation = (
location
{user.location}
); } let blockButton = ''; if (channel.channel_type === 'direct' && window.currentUser.id !== user.id) { blockButton = setUpButton({ modalId: 'userdetails__blockmsg', otherModalId: 'userdetails__reportabuse', btnName: 'Block User', }); } let reportButton = ''; if (window.currentUser.id !== user.id) { reportButton = setUpButton({ modalId: 'userdetails__reportabuse', otherModalId: 'userdetails__blockmsg', btnName: 'Report Abuse', }); } return (
{`${user.username}

{user.name}

{socialIcons}
{user.summary}
{userLocation}
joined
{user.joined_at}
{blockButton} {reportButton}

Reporting abuse will:

  • close this chat and prevent this user from re-opening chat with you
  • give the DEV team your consent to read messages in this chat to understand your report and take appropriate action

Blocking is only on Connect right now and has not been implemented across DEV yet.

Are you sure?
{ blockUser(channelId); }} > Yes, Report {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} { document.getElementById( 'userdetails__reportabuse', ).style.display = 'none'; window.location.href = `#`; }} onKeyUp={e => { if (e.keyCode === 13) { document.getElementById( 'userdetails__reportabuse', ).style.display = 'none'; window.location.href = `#`; } }} > No

Blocking on connect will:

  • close this chat and prevent this user from re-opening chat with you
  • NOT notify the user you will block--this channel will become inaccessible for both users

Blocking is only on Connect right now and has not been implemented across DEV yet. Consider reporting abuse to the DEV team if this user is spamming or harassing elsewhere on dev.to, so we can take further action.

Are you sure?
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} { blockUser(user.id); window.location.href = `/connect`; }} onKeyUp={e => { if (e.keyCode === 13) { blockUser(user.id); window.location.href = `/connect`; } }} > Yes, Block {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} { document.getElementById('userdetails__blockmsg').style.display = 'none'; window.location.href = `#`; }} onKeyUp={e => { if (e.keyCode === 13) { document.getElementById('userdetails__blockmsg').style.display = 'none'; window.location.href = `#`; } }} > No
); }; UserDetails.propTypes = { user: PropTypes.objectOf().isRequired, activeChannelId: PropTypes.string.isRequired, activeChannel: PropTypes.objectOf().isRequired, }; export default UserDetails;