You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { useConvoIdFromContext } from '../../../../contexts/ConvoIdContext';
|
|
import {
|
|
useConversationUsername,
|
|
useIsKickedFromGroup,
|
|
useIsClosedGroup,
|
|
useIsPublic,
|
|
useIsGroupDestroyed,
|
|
} from '../../../../hooks/useParamSelector';
|
|
import { showLeaveGroupByConvoId } from '../../../../interactions/conversationInteractions';
|
|
import { useIsMessageRequestOverlayShown } from '../../../../state/selectors/section';
|
|
import { ItemWithDataTestId } from '../MenuItemWithDataTestId';
|
|
import { showLeaveGroupItem } from './guard';
|
|
import { Localizer } from '../../../basic/Localizer';
|
|
|
|
export const LeaveGroupMenuItem = () => {
|
|
const convoId = useConvoIdFromContext();
|
|
const isGroup = useIsClosedGroup(convoId);
|
|
const isPublic = useIsPublic(convoId);
|
|
const username = useConversationUsername(convoId) || convoId;
|
|
const isMessageRequestShown = useIsMessageRequestOverlayShown();
|
|
const isKickedFromGroup = useIsKickedFromGroup(convoId) || false;
|
|
const isGroupDestroyed = useIsGroupDestroyed(convoId);
|
|
|
|
const showLeave = showLeaveGroupItem({
|
|
isGroup,
|
|
isMessageRequestShown,
|
|
isKickedFromGroup,
|
|
isPublic,
|
|
isGroupDestroyed,
|
|
});
|
|
|
|
if (!showLeave) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<ItemWithDataTestId
|
|
onClick={() => {
|
|
void showLeaveGroupByConvoId(convoId, username);
|
|
}}
|
|
>
|
|
<Localizer token="groupLeave" />
|
|
</ItemWithDataTestId>
|
|
);
|
|
};
|