import type { ChangeEvent } from 'react'; import type { FC } from '../../lib/teact/teact'; import React, { memo, useMemo, useState } from '../../lib/teact/teact'; import { getActions } from '../../global'; import type { ApiPhoto, ApiReportReason } from '../../api/types'; import buildClassName from '../../util/buildClassName'; import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; import Button from '../ui/Button'; import InputText from '../ui/InputText'; import Modal from '../ui/Modal'; import RadioGroup from '../ui/RadioGroup'; export type OwnProps = { isOpen: boolean; subject?: 'peer' | 'messages' | 'media' | 'story'; peerId?: string; photo?: ApiPhoto; messageIds?: number[]; storyId?: number; onClose: () => void; onCloseAnimationEnd?: () => void; }; const ReportModal: FC = ({ isOpen, subject = 'messages', peerId, photo, messageIds, storyId, onClose, onCloseAnimationEnd, }) => { const { reportMessages, reportPeer, reportProfilePhoto, reportStory, exitMessageSelectMode, } = getActions(); const [selectedReason, setSelectedReason] = useState('spam'); const [description, setDescription] = useState(''); const handleReport = useLastCallback(() => { switch (subject) { case 'messages': reportMessages({ messageIds: messageIds!, reason: selectedReason, description }); exitMessageSelectMode(); break; case 'peer': reportPeer({ chatId: peerId, reason: selectedReason, description }); break; case 'media': reportProfilePhoto({ chatId: peerId, photo, reason: selectedReason, description, }); break; case 'story': reportStory({ peerId: peerId!, storyId: storyId!, reason: selectedReason, description, }); } onClose(); }); const handleSelectReason = useLastCallback((value: string) => { setSelectedReason(value as ApiReportReason); }); const handleDescriptionChange = useLastCallback((e: ChangeEvent) => { setDescription(e.target.value); }); const lang = useOldLang(); const REPORT_OPTIONS: { value: ApiReportReason; label: string }[] = useMemo(() => [ { value: 'spam', label: lang('lng_report_reason_spam') }, { value: 'violence', label: lang('lng_report_reason_violence') }, { value: 'pornography', label: lang('lng_report_reason_pornography') }, { value: 'childAbuse', label: lang('lng_report_reason_child_abuse') }, { value: 'copyright', label: lang('ReportPeer.ReasonCopyright') }, { value: 'illegalDrugs', label: 'Illegal Drugs' }, { value: 'personalDetails', label: 'Personal Details' }, { value: 'other', label: lang('lng_report_reason_other') }, ], [lang]); if ( (subject === 'messages' && !messageIds) || (subject === 'peer' && !peerId) || (subject === 'media' && (!peerId || !photo)) || (subject === 'story' && (!storyId || !peerId)) ) { return undefined; } const title = subject === 'messages' ? lang('lng_report_message_title') : lang('ReportPeer.Report'); return (
); }; export default memo(ReportModal);