/* * Wire * Copyright (C) 2022 Wire Swiss GmbH * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. * */ import {FC, useState} from 'react'; import {FadingScrollbar} from 'Components/FadingScrollbar'; import {PrimaryModal} from 'Components/Modals/PrimaryModal'; import {useKoSubscribableChildren} from 'Util/ComponentUtil'; import {t} from 'Util/LocalizerUtil'; import {GuestOptions} from './components/GuestOptions'; import {ServicesOptions} from './components/ServicesOptions'; import {toggleFeature} from '../../../conversation/ConversationAccessPermission'; import {ConversationRepository} from '../../../conversation/ConversationRepository'; import {Conversation} from '../../../entity/Conversation'; import {TeamRepository} from '../../../team/TeamRepository'; import {TeamState} from '../../../team/TeamState'; import {PanelHeader} from '../PanelHeader'; interface GuestServicesOptionsProps { activeConversation: Conversation; conversationRepository: ConversationRepository; teamRepository: TeamRepository; onBack: () => void; onClose: () => void; teamState: TeamState; isGuest?: boolean; isPasswordSupported?: boolean; } const GuestServicesOptions: FC = ({ activeConversation, conversationRepository, teamRepository, onBack, onClose, teamState, isGuest = false, isPasswordSupported = false, }) => { const [isRequestOngoing, setIsRequestOngoing] = useState(false); const {accessState, inTeam, isTeamOnly} = useKoSubscribableChildren(activeConversation, [ 'accessState', 'inTeam', 'isTeamOnly', ]); const {isGuestLinkEnabled: isTeamStateGuestLinkEnabled} = useKoSubscribableChildren(teamState, [ 'isGuestLinkEnabled', ]); const isToggleDisabled = isRequestOngoing || !inTeam; const toggleAccessState = async (feature: number, message: string, willAffectMembers: boolean) => { if (inTeam) { const newAccessState = toggleFeature(feature, accessState); const changeAccessState = async () => { if (!isRequestOngoing) { setIsRequestOngoing(true); await conversationRepository.stateHandler.changeAccessState(activeConversation, newAccessState); setIsRequestOngoing(false); } }; if (isTeamOnly || !willAffectMembers) { return changeAccessState(); } PrimaryModal.show(PrimaryModal.type.CONFIRM, { preventClose: true, primaryAction: { action: changeAccessState, text: t('modalConversationRemoveGuestsOrServicesAction'), }, text: { message, title: isGuest ? t('modalConversationRemoveGuestsHeadline') : t('modalConversationRemoveServicesHeadline'), }, }); } }; return (
{isGuest ? ( ) : ( )}
); }; export {GuestServicesOptions};