2024-06-25 18:56:28 +00:00
|
|
|
// Copyright 2024 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
import React, { memo, useCallback, useMemo } from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { useCallingActions } from '../ducks/calling';
|
|
|
|
import { getCallLinkSelector } from '../selectors/calling';
|
|
|
|
import * as log from '../../logging/log';
|
|
|
|
import { getIntl } from '../selectors/user';
|
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
|
|
|
import { getCallLinkAddNameModalRoomId } from '../selectors/globalModals';
|
|
|
|
import { strictAssert } from '../../util/assert';
|
2024-08-06 19:29:13 +00:00
|
|
|
import { isCallLinksCreateEnabled } from '../../util/callLinks';
|
|
|
|
import { isCallLinkAdmin } from '../../types/CallLink';
|
2024-06-25 18:56:28 +00:00
|
|
|
import { CallLinkAddNameModal } from '../../components/CallLinkAddNameModal';
|
|
|
|
|
|
|
|
export const SmartCallLinkAddNameModal = memo(
|
|
|
|
function SmartCallLinkAddNameModal(): JSX.Element | null {
|
|
|
|
strictAssert(isCallLinksCreateEnabled(), 'Call links creation is disabled');
|
|
|
|
|
|
|
|
const roomId = useSelector(getCallLinkAddNameModalRoomId);
|
|
|
|
strictAssert(roomId, 'Expected roomId to be set');
|
|
|
|
|
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const callLinkSelector = useSelector(getCallLinkSelector);
|
|
|
|
|
|
|
|
const { updateCallLinkName } = useCallingActions();
|
|
|
|
const { toggleCallLinkAddNameModal } = useGlobalModalActions();
|
|
|
|
|
|
|
|
const callLink = useMemo(() => {
|
|
|
|
return callLinkSelector(roomId);
|
|
|
|
}, [callLinkSelector, roomId]);
|
|
|
|
|
|
|
|
const handleClose = useCallback(() => {
|
|
|
|
toggleCallLinkAddNameModal(null);
|
|
|
|
}, [toggleCallLinkAddNameModal]);
|
|
|
|
|
|
|
|
const handleUpdateCallLinkName = useCallback(
|
|
|
|
(newName: string) => {
|
|
|
|
updateCallLinkName(roomId, newName);
|
|
|
|
},
|
|
|
|
[roomId, updateCallLinkName]
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!callLink) {
|
|
|
|
log.error(
|
|
|
|
'SmartCallLinkEditModal: No call link found for roomId',
|
|
|
|
roomId
|
|
|
|
);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-07-30 18:39:24 +00:00
|
|
|
strictAssert(isCallLinkAdmin(callLink), 'User is not an admin');
|
|
|
|
|
2024-06-25 18:56:28 +00:00
|
|
|
return (
|
|
|
|
<CallLinkAddNameModal
|
|
|
|
i18n={i18n}
|
|
|
|
callLink={callLink}
|
|
|
|
onClose={handleClose}
|
|
|
|
onUpdateCallLinkName={handleUpdateCallLinkName}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|