signal-desktop/ts/state/smart/SendAnywayDialog.tsx
Jamie Kyle 27b55e472d
Refactor smart components
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
2024-03-13 13:44:13 -07:00

86 lines
3 KiB
TypeScript

// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { memo } from 'react';
import { useSelector } from 'react-redux';
import * as SingleServePromise from '../../services/singleServePromise';
import {
SafetyNumberChangeDialog,
SafetyNumberChangeSource,
} from '../../components/SafetyNumberChangeDialog';
import { SmartSafetyNumberViewer } from './SafetyNumberViewer';
import { getByDistributionListConversationsStoppingSend } from '../selectors/conversations-extra';
import { getIntl, getTheme } from '../selectors/user';
import { getPreferredBadgeSelector } from '../selectors/badges';
import { useConversationsActions } from '../ducks/conversations';
import { useGlobalModalActions } from '../ducks/globalModals';
import { useStoryDistributionListsActions } from '../ducks/storyDistributionLists';
import { getSafetyNumberChangedBlockingData } from '../selectors/globalModals';
export const SmartSendAnywayDialog = memo(
function SmartSendAnywayDialog(): JSX.Element {
const { hideBlockingSafetyNumberChangeDialog } = useGlobalModalActions();
const { removeMembersFromDistributionList } =
useStoryDistributionListsActions();
const { cancelConversationVerification, verifyConversationsStoppingSend } =
useConversationsActions();
const getPreferredBadge = useSelector(getPreferredBadgeSelector);
const i18n = useSelector(getIntl);
const theme = useSelector(getTheme);
const contacts = useSelector(
getByDistributionListConversationsStoppingSend
);
const safetyNumberChangedBlockingData = useSelector(
getSafetyNumberChangedBlockingData
);
const explodedPromise = safetyNumberChangedBlockingData
? SingleServePromise.get<boolean>(
safetyNumberChangedBlockingData.promiseUuid
)
: undefined;
let confirmText: string | undefined = i18n(
'icu:safetyNumberChangeDialog__pending-messages'
);
if (
safetyNumberChangedBlockingData?.source ===
SafetyNumberChangeSource.InitiateCall
) {
confirmText = i18n('icu:callAnyway');
} else if (
safetyNumberChangedBlockingData?.source ===
SafetyNumberChangeSource.JoinCall
) {
confirmText = i18n('icu:joinAnyway');
} else {
confirmText = undefined;
}
return (
<SafetyNumberChangeDialog
confirmText={confirmText}
contacts={contacts}
getPreferredBadge={getPreferredBadge}
i18n={i18n}
onCancel={() => {
cancelConversationVerification();
explodedPromise?.resolve(false);
hideBlockingSafetyNumberChangeDialog();
}}
onConfirm={() => {
verifyConversationsStoppingSend();
explodedPromise?.resolve(true);
hideBlockingSafetyNumberChangeDialog();
}}
removeFromStory={removeMembersFromDistributionList}
renderSafetyNumber={({ contactID, onClose }) => (
<SmartSafetyNumberViewer contactID={contactID} onClose={onClose} />
)}
theme={theme}
/>
);
}
);