pleroma/app/soapbox/features/chats/components/chat-message-list-intro.tsx

119 lines
4.1 KiB
TypeScript
Raw Normal View History

2022-08-31 10:24:01 -07:00
import classNames from 'clsx';
2022-08-17 12:48:04 -07:00
import React from 'react';
2022-09-14 07:35:32 -07:00
import { defineMessages, useIntl } from 'react-intl';
2022-08-17 12:48:04 -07:00
import { openModal } from 'soapbox/actions/modals';
import { initReport } from 'soapbox/actions/reports';
import { Avatar, Button, HStack, Icon, Stack, Text } from 'soapbox/components/ui';
import { useChatContext } from 'soapbox/contexts/chat-context';
import { useAppDispatch } from 'soapbox/hooks';
2022-09-28 13:20:59 -07:00
import { useChatActions } from 'soapbox/queries/chats';
2022-08-17 12:48:04 -07:00
2022-09-14 07:35:32 -07:00
const messages = defineMessages({
leaveChatHeading: { id: 'chat_message_list_intro.leave_chat.heading', defaultMessage: 'Leave Chat' },
2022-09-27 07:18:12 -07:00
leaveChatMessage: { id: 'chat_message_list_intro.leave_chat.message', defaultMessage: 'Are you sure you want to leave this chat? Messages will be deleted for you and this chat will be removed from your inbox.' },
2022-09-14 07:35:32 -07:00
leaveChatConfirm: { id: 'chat_message_list_intro.leave_chat.confirm', defaultMessage: 'Leave Chat' },
intro: { id: 'chat_message_list_intro.intro', defaultMessage: 'wants to start a chat with you' },
accept: { id: 'chat_message_list_intro.actions.accept', defaultMessage: 'Accept' },
leaveChat: { id: 'chat_message_list_intro.actions.leave_chat', defaultMessage: 'Leave chat' },
report: { id: 'chat_message_list_intro.actions.report', defaultMessage: 'Report' },
messageLifespan: { id: 'chat_message_list_intro.actions.message_lifespan', defaultMessage: 'Messages older than 15 days are deleted.' },
});
2022-08-17 12:48:04 -07:00
const ChatMessageListIntro = () => {
const dispatch = useAppDispatch();
2022-09-14 07:35:32 -07:00
const intl = useIntl();
2022-08-17 12:48:04 -07:00
const { chat, needsAcceptance } = useChatContext();
2022-09-28 13:20:59 -07:00
const { acceptChat, deleteChat } = useChatActions(chat?.id as string);
2022-08-17 12:48:04 -07:00
const handleLeaveChat = () => {
dispatch(openModal('CONFIRM', {
2022-09-14 07:35:32 -07:00
heading: intl.formatMessage(messages.leaveChatHeading),
message: intl.formatMessage(messages.leaveChatMessage),
confirm: intl.formatMessage(messages.leaveChatConfirm),
2022-08-17 12:48:04 -07:00
confirmationTheme: 'primary',
2022-09-14 07:35:32 -07:00
onConfirm: () => deleteChat.mutate(),
2022-08-17 12:48:04 -07:00
}));
};
const handleReportChat = () => {
2022-09-08 09:47:19 -07:00
dispatch(initReport(chat?.account as any));
2022-08-17 12:48:04 -07:00
acceptChat.mutate();
};
if (!chat) {
return null;
}
return (
<Stack
2022-09-12 11:42:15 -07:00
data-testid='chat-message-list-intro'
2022-08-17 12:48:04 -07:00
justifyContent='center'
alignItems='center'
space={4}
className={
classNames({
'w-3/4 mx-auto': needsAcceptance,
'mt-6': true,
})
}
>
<Stack alignItems='center' space={2}>
<Avatar src={chat.account.avatar_static} size={75} />
<Text size='lg' align='center'>
{needsAcceptance ? (
<>
<Text tag='span' weight='semibold'>@{chat.account.acct}</Text>
{' '}
2022-09-14 07:35:32 -07:00
<Text tag='span'>{intl.formatMessage(messages.intro)}</Text>
2022-08-17 12:48:04 -07:00
</>
) : (
<Text tag='span' weight='semibold'>@{chat.account.acct}</Text>
)}
</Text>
</Stack>
{needsAcceptance ? (
<Stack space={2} className='w-full'>
<Button
theme='primary'
block
2022-09-14 07:35:32 -07:00
onClick={() => acceptChat.mutate()}
2022-08-17 12:48:04 -07:00
disabled={acceptChat.isLoading}
>
2022-09-14 07:35:32 -07:00
{intl.formatMessage(messages.accept)}
2022-08-17 12:48:04 -07:00
</Button>
<HStack alignItems='center' space={2} className='w-full'>
<Button
2022-09-22 09:39:52 -07:00
theme='secondary'
2022-08-17 12:48:04 -07:00
block
2022-09-22 09:39:52 -07:00
onClick={handleReportChat}
2022-08-17 12:48:04 -07:00
>
2022-09-22 09:39:52 -07:00
{intl.formatMessage(messages.report)}
2022-08-17 12:48:04 -07:00
</Button>
<Button
2022-09-22 09:39:52 -07:00
theme='danger'
2022-08-17 12:48:04 -07:00
block
2022-09-22 09:39:52 -07:00
onClick={handleLeaveChat}
2022-08-17 12:48:04 -07:00
>
2022-09-22 09:39:52 -07:00
{intl.formatMessage(messages.leaveChat)}
2022-08-17 12:48:04 -07:00
</Button>
</HStack>
</Stack>
) : (
<HStack justifyContent='center' alignItems='center' space={1} className='flex-shrink-0'>
<Icon src={require('@tabler/icons/clock.svg')} className='text-gray-600 w-4 h-4' />
<Text size='sm' theme='muted'>
2022-09-14 07:35:32 -07:00
{intl.formatMessage(messages.messageLifespan)}
2022-08-17 12:48:04 -07:00
</Text>
</HStack>
)}
</Stack>
);
};
export default ChatMessageListIntro;