Refactor leave/report chat
This commit is contained in:
parent
0cb0e8af9e
commit
ea5525d02c
|
@ -3,6 +3,7 @@ import * as React from 'react';
|
||||||
import { defineMessages, useIntl } from 'react-intl';
|
import { defineMessages, useIntl } from 'react-intl';
|
||||||
|
|
||||||
import Button from '../button/button';
|
import Button from '../button/button';
|
||||||
|
import { ButtonThemes } from '../button/useButtonStyles';
|
||||||
import IconButton from '../icon-button/icon-button';
|
import IconButton from '../icon-button/icon-button';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
|
@ -39,7 +40,7 @@ interface IModal {
|
||||||
/** Confirmation button text. */
|
/** Confirmation button text. */
|
||||||
confirmationText?: React.ReactNode,
|
confirmationText?: React.ReactNode,
|
||||||
/** Confirmation button theme. */
|
/** Confirmation button theme. */
|
||||||
confirmationTheme?: 'danger',
|
confirmationTheme?: ButtonThemes,
|
||||||
/** Callback when the modal is closed. */
|
/** Callback when the modal is closed. */
|
||||||
onClose?: () => void,
|
onClose?: () => void,
|
||||||
/** Callback when the secondary action is chosen. */
|
/** Callback when the secondary action is chosen. */
|
||||||
|
|
|
@ -8,6 +8,8 @@ import {
|
||||||
markChatRead,
|
markChatRead,
|
||||||
} from 'soapbox/actions/chats';
|
} from 'soapbox/actions/chats';
|
||||||
import { uploadMedia } from 'soapbox/actions/media';
|
import { uploadMedia } from 'soapbox/actions/media';
|
||||||
|
import { openModal } from 'soapbox/actions/modals';
|
||||||
|
import { initReport } from 'soapbox/actions/reports';
|
||||||
import { Avatar, Button, HStack, Icon, IconButton, Input, Stack, Text, Textarea } from 'soapbox/components/ui';
|
import { Avatar, Button, HStack, Icon, IconButton, Input, Stack, Text, Textarea } from 'soapbox/components/ui';
|
||||||
import UploadProgress from 'soapbox/components/upload-progress';
|
import UploadProgress from 'soapbox/components/upload-progress';
|
||||||
import UploadButton from 'soapbox/features/compose/components/upload_button';
|
import UploadButton from 'soapbox/features/compose/components/upload_button';
|
||||||
|
@ -184,6 +186,23 @@ const ChatBox: React.FC<IChatBox> = ({ chat, onSetInputRef, autosize }) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleLeaveChat = () => {
|
||||||
|
dispatch(openModal('CONFIRM', {
|
||||||
|
heading: 'Leave Chat',
|
||||||
|
message: 'Are you sure you want to leave this chat? This conversation will be removed from your inbox.',
|
||||||
|
confirm: 'Leave Chat',
|
||||||
|
confirmationTheme: 'primary',
|
||||||
|
onConfirm: () => {
|
||||||
|
deleteChat.mutate();
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleReportChat = () => {
|
||||||
|
dispatch(initReport(chat.account));
|
||||||
|
acceptChat.mutate();
|
||||||
|
};
|
||||||
|
|
||||||
const renderAttachment = () => {
|
const renderAttachment = () => {
|
||||||
if (!attachment) return null;
|
if (!attachment) return null;
|
||||||
|
|
||||||
|
@ -244,13 +263,18 @@ const ChatBox: React.FC<IChatBox> = ({ chat, onSetInputRef, autosize }) => {
|
||||||
<Button
|
<Button
|
||||||
theme='accent'
|
theme='accent'
|
||||||
block
|
block
|
||||||
onClick={() => deleteChat.mutate()}
|
onClick={handleLeaveChat}
|
||||||
disabled={deleteChat.isLoading}
|
|
||||||
>
|
>
|
||||||
Leave chat
|
Leave chat
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button theme='secondary' block>Report</Button>
|
<Button
|
||||||
|
theme='secondary'
|
||||||
|
block
|
||||||
|
onClick={handleReportChat}
|
||||||
|
>
|
||||||
|
Report
|
||||||
|
</Button>
|
||||||
</HStack>
|
</HStack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
|
@ -133,14 +133,14 @@ const ChatPane = () => {
|
||||||
className='px-4 py-2 w-full flex flex-col hover:bg-gray-100'
|
className='px-4 py-2 w-full flex flex-col hover:bg-gray-100'
|
||||||
>
|
>
|
||||||
<HStack alignItems='center' space={2}>
|
<HStack alignItems='center' space={2}>
|
||||||
<Avatar src={chat.account.avatar} size={40} />
|
<Avatar src={chat.account?.avatar} size={40} />
|
||||||
|
|
||||||
<Stack alignItems='start'>
|
<Stack alignItems='start'>
|
||||||
<div className='flex items-center space-x-1 flex-grow'>
|
<div className='flex items-center space-x-1 flex-grow'>
|
||||||
<Text weight='semibold' truncate>{chat.account.display_name}</Text>
|
<Text weight='semibold' truncate>{chat.account?.display_name}</Text>
|
||||||
{chat.account.verified && <VerificationBadge />}
|
{chat.account?.verified && <VerificationBadge />}
|
||||||
</div>
|
</div>
|
||||||
<Text theme='muted' truncate>{chat.account.acct}</Text>
|
<Text theme='muted' truncate>{chat.account?.acct}</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
</HStack>
|
</HStack>
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -2,6 +2,7 @@ import React, { useState } from 'react';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
|
||||||
import { Modal, Text } from 'soapbox/components/ui';
|
import { Modal, Text } from 'soapbox/components/ui';
|
||||||
|
import { ButtonThemes } from 'soapbox/components/ui/button/useButtonStyles';
|
||||||
import { SimpleForm, FieldsGroup, Checkbox } from 'soapbox/features/forms';
|
import { SimpleForm, FieldsGroup, Checkbox } from 'soapbox/features/forms';
|
||||||
|
|
||||||
interface IConfirmationModal {
|
interface IConfirmationModal {
|
||||||
|
@ -14,6 +15,7 @@ interface IConfirmationModal {
|
||||||
onSecondary?: () => void,
|
onSecondary?: () => void,
|
||||||
onCancel: () => void,
|
onCancel: () => void,
|
||||||
checkbox?: JSX.Element,
|
checkbox?: JSX.Element,
|
||||||
|
confirmationTheme?: ButtonThemes
|
||||||
}
|
}
|
||||||
|
|
||||||
const ConfirmationModal: React.FC<IConfirmationModal> = ({
|
const ConfirmationModal: React.FC<IConfirmationModal> = ({
|
||||||
|
@ -26,6 +28,7 @@ const ConfirmationModal: React.FC<IConfirmationModal> = ({
|
||||||
onSecondary,
|
onSecondary,
|
||||||
onCancel,
|
onCancel,
|
||||||
checkbox,
|
checkbox,
|
||||||
|
confirmationTheme = 'danger',
|
||||||
}) => {
|
}) => {
|
||||||
const [checked, setChecked] = useState(false);
|
const [checked, setChecked] = useState(false);
|
||||||
|
|
||||||
|
@ -54,7 +57,7 @@ const ConfirmationModal: React.FC<IConfirmationModal> = ({
|
||||||
confirmationAction={handleClick}
|
confirmationAction={handleClick}
|
||||||
confirmationText={confirm}
|
confirmationText={confirm}
|
||||||
confirmationDisabled={checkbox && !checked}
|
confirmationDisabled={checkbox && !checked}
|
||||||
confirmationTheme='danger'
|
confirmationTheme={confirmationTheme}
|
||||||
cancelText={<FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />}
|
cancelText={<FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />}
|
||||||
cancelAction={handleCancel}
|
cancelAction={handleCancel}
|
||||||
secondaryText={secondary}
|
secondaryText={secondary}
|
||||||
|
|
Loading…
Reference in New Issue