import { h, Fragment } from 'preact';
import PropTypes from 'prop-types';
import { useState } from 'preact/hooks';
import { reportAbuse, blockUser } from '../actions/requestActions';
import { addSnackbarItem } from '../../Snackbar';
import { Button, FormField, RadioButton } from '@crayons';
/**
* This component render the report abuse
*
* @param {object} props
* @param {object} props.data
* @param {function} props.closeReportAbuseForm
*
* @component
*
* @example
*
*
*
*/
export function ReportAbuse({ data, closeReportAbuseForm }) {
const [category, setCategory] = useState(null);
const handleChange = (e) => {
setCategory(e.target.value);
};
const handleSubmit = async () => {
const response = await reportAbuse(
data.message,
'connect',
category,
data.user_id,
);
const { success, message } = response;
if (success) {
const confirmBlock = window.confirm(
`The message will be reported.\n\nWould you like to block this person as well?\n\nThis will:
- prevent them from commenting on your posts
- block all notifications from them
- prevent them from messaging you via chat`,
);
if (confirmBlock) {
const response = await blockUser(data.user_id);
if (response.result === 'blocked') {
addSnackbarItem({
message:
'Your report has been submitted and the user has been blocked',
});
}
} else {
addSnackbarItem({ message: 'Your report has been submitted.' });
}
closeReportAbuseForm();
} else {
addSnackbarItem({ message });
}
};
return (
Report Abuse
Thank you for reporting any abuse that violates our{' '}
code of conduct or{' '}
terms and conditions. We continue to try to make
this environment a great one for everybody.