import { h, render } from 'preact'; import { useState, useRef } from 'preact/hooks'; import PropTypes from 'prop-types'; import { request } from '../utilities/http'; import { Button } from '@crayons/Button/Button'; async function confirmFlagUser({ reactableType, category, reactableId }) { const body = JSON.stringify({ reactable_type: reactableType, category, reactable_id: reactableId, }); try { const response = await request('/reactions', { method: 'POST', body, }); const outcome = await response.json(); if (outcome.result === 'create') { top.addSnackbarItem({ message: 'All posts by this author will be less visible.', addCloseButton: true, }); } else if (outcome.result === null) { top.addSnackbarItem({ message: "It seems you've already reduced the visibility of this author's posts.", addCloseButton: true, }); } else { top.addSnackbarItem({ message: `Response from server: ${JSON.stringify(outcome)}`, addCloseButton: true, }); } } catch (error) { top.addSnackbarItem({ message: error, addCloseButton: true, }); } toggleFlagUserModal(); } /** * Shows or hides the flag user modal. */ export function toggleFlagUserModal() { const modalContainer = document.querySelector('.flag-user-modal-container'); modalContainer.classList.toggle('hidden'); if (!modalContainer.classList.contains('hidden')) { window.scrollTo(0, 0); document.body.style.height = '100vh'; document.body.style.overflowY = 'hidden'; } else { document.body.style.height = 'inherit'; document.body.style.overflowY = 'inherit'; } } /** * Initializes the flag user modal for the given author ID. * * @param {number} authorId */ export function initializeFlagUserModal(authorId) { // Check whether context is ModCenter or Friday-Night-Mode const modContainer = document.getElementById('mod-container'); if (!modContainer) { return; } render( , document.querySelector('.flag-user-modal-container'), ); modContainer.addEventListener('load', () => { modContainer.contentWindow.document .getElementById('open-flag-user-modal') .addEventListener('click', toggleFlagUserModal); }); } /** * A modal for flagging a user and their content. This can be used in the moderation * or on an article page. * * @param {string} props.modCenterUrl (optional) The article URL loaded when in the moderation center. * @param {number} props.authorId The author ID associated to the content being moderated. */ export function FlagUserModal({ modCenterArticleUrl, authorId }) { const [isConfirmButtonEnabled, enableConfirmButton] = useState(false); const vomitAllRef = useRef(null); return (

Flag User

Thanks for keeping DEV safe. Here is what you can do to flag this user:

{ const { target } = event; enableConfirmButton(target.checked); }} />

Report other inappropriate conduct

); } FlagUserModal.displayName = 'FlagUserModal'; FlagUserModal.propTypes = { moderationUrl: PropTypes.string, authorId: PropTypes.number.isRequired, };