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.
session-desktop/ts/components/dialog/DeleteAccountModal.tsx

150 lines
4.5 KiB
TypeScript

import { useCallback, useState } from 'react';
import { useDispatch } from 'react-redux';
import { updateDeleteAccountModal } from '../../state/ducks/modalDialog';
import { SessionWrapperModal } from '../SessionWrapperModal';
import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton';
import { SpacerLG } from '../basic/Text';
import { SessionSpinner } from '../loading';
import {
deleteEverythingAndNetworkData,
sendConfigMessageAndDeleteEverything,
} from '../../util/accountManager';
import { SessionRadioGroup } from '../basic/SessionRadioGroup';
const DEVICE_ONLY = 'device_only';
const DEVICE_AND_NETWORK = 'device_and_network';
type DeleteModes = typeof DEVICE_ONLY | typeof DEVICE_AND_NETWORK;
const DescriptionBeforeAskingConfirmation = (props: {
deleteMode: DeleteModes;
setDeleteMode: (deleteMode: DeleteModes) => void;
}) => {
const { deleteMode, setDeleteMode } = props;
return (
<>
<span className="session-confirm-main-message">{window.i18n('clearDataAllDescription')}</span>
<SpacerLG />
<SessionRadioGroup
group="delete_account"
initialItem={deleteMode}
onClick={value => {
if (value === DEVICE_ONLY || value === DEVICE_AND_NETWORK) {
setDeleteMode(value);
}
}}
items={[
{ label: window.i18n('clearDeviceOnly'), value: DEVICE_ONLY },
{ label: window.i18n('clearDeviceAndNetwork'), value: 'device_and_network' },
]}
/>
</>
);
};
Merge branch 'unstable' into standardised_strings_merge # Conflicts: # .gitignore # _locales/en/messages.json # ts/components/DebugLogView.tsx # ts/components/SessionWrapperModal.tsx # ts/components/basic/SessionHTMLRenderer.tsx # ts/components/basic/SessionRadio.tsx # ts/components/buttons/MenuButton.tsx # ts/components/conversation/SessionConversation.tsx # ts/components/conversation/SubtleNotification.tsx # ts/components/conversation/TimerNotification.tsx # ts/components/conversation/composition/CompositionBox.tsx # ts/components/conversation/message/message-content/MessageText.tsx # ts/components/conversation/message/message-item/InteractionNotification.tsx # ts/components/conversation/message/reactions/ReactionPopup.tsx # ts/components/conversation/right-panel/overlay/OverlayRightPanelSettings.tsx # ts/components/conversation/right-panel/overlay/disappearing-messages/DisappearingModes.tsx # ts/components/conversation/right-panel/overlay/disappearing-messages/OverlayDisappearingMessages.tsx # ts/components/dialog/BanOrUnbanUserDialog.tsx # ts/components/dialog/DeleteAccountModal.tsx # ts/components/dialog/EditProfileDialog.tsx # ts/components/dialog/ModeratorsAddDialog.tsx # ts/components/dialog/OnionStatusPathDialog.tsx # ts/components/dialog/ReactListModal.tsx # ts/components/dialog/SessionSeedModal.tsx # ts/components/dialog/SessionSetPasswordDialog.tsx # ts/components/dialog/UserDetailsDialog.tsx # ts/components/leftpane/LeftPaneSectionHeader.tsx # ts/components/leftpane/LeftPaneSettingSection.tsx # ts/components/leftpane/conversation-list-item/InteractionItem.tsx # ts/components/leftpane/overlay/OverlayClosedGroup.tsx # ts/components/leftpane/overlay/OverlayCommunity.tsx # ts/components/leftpane/overlay/OverlayMessage.tsx # ts/components/leftpane/overlay/SessionJoinableDefaultRooms.tsx # ts/components/leftpane/overlay/choose-action/ContactsListWithBreaks.tsx # ts/components/leftpane/overlay/choose-action/OverlayChooseAction.tsx # ts/components/menu/Menu.tsx # ts/components/registration/RegistrationStages.tsx # ts/components/registration/RegistrationUserDetails.tsx # ts/components/registration/SignInTab.tsx # ts/components/registration/SignUpTab.tsx # ts/components/settings/SessionSettings.tsx # ts/components/settings/SessionSettingsHeader.tsx # ts/components/settings/ZoomingSessionSlider.tsx # ts/components/settings/section/CategoryAppearance.tsx # ts/components/settings/section/CategoryHelp.tsx # ts/components/settings/section/CategoryPermissions.tsx # ts/components/settings/section/CategoryPrivacy.tsx # ts/hooks/useParamSelector.ts # ts/mains/main_renderer.tsx # ts/models/message.ts # ts/node/menu.ts # ts/node/tray_icon.ts # ts/session/constants.ts # ts/session/disappearing_messages/timerOptions.ts # ts/session/utils/Toast.tsx # ts/state/selectors/search.ts # ts/test/session/unit/selectors/conversations_test.ts # ts/types/LocalizerKeys.ts # ts/types/Util.ts # ts/window.d.ts # yarn.lock
9 months ago
// NODE: strings - check merge conflict
const DescriptionWhenAskingConfirmation = (props: { deleteMode: DeleteModes }) => {
return (
<span className="session-confirm-main-message">
{props.deleteMode === 'device_and_network'
? window.i18n('clearDeviceAndNetworkConfirm')
: window.i18n('clearDeviceDescription')}
</span>
);
};
export const DeleteAccountModal = () => {
const [isLoading, setIsLoading] = useState(false);
const [askingConfirmation, setAskingConfirmation] = useState(false);
const [deleteMode, setDeleteMode] = useState<DeleteModes>(DEVICE_ONLY);
const dispatch = useDispatch();
const onDeleteEverythingLocallyOnly = async () => {
if (!isLoading) {
setIsLoading(true);
try {
window.log.warn('Deleting everything on device but keeping network data');
await sendConfigMessageAndDeleteEverything();
} catch (e) {
window.log.warn(e);
} finally {
setIsLoading(false);
}
}
};
const onDeleteEverythingAndNetworkData = async () => {
if (!isLoading) {
setIsLoading(true);
try {
window.log.warn('Deleting everything including network data');
await deleteEverythingAndNetworkData();
} catch (e) {
window.log.warn(e);
} finally {
setIsLoading(false);
}
}
};
/**
* Performs specified on close action then removes the modal.
*/
const onClickCancelHandler = useCallback(() => {
dispatch(updateDeleteAccountModal(null));
}, [dispatch]);
return (
<SessionWrapperModal
title={window.i18n('clearDataAll')}
onClose={onClickCancelHandler}
showExitIcon={true}
>
{askingConfirmation ? (
<DescriptionWhenAskingConfirmation deleteMode={deleteMode} />
) : (
<DescriptionBeforeAskingConfirmation
deleteMode={deleteMode}
setDeleteMode={setDeleteMode}
/>
)}
<div className="session-modal__centered">
<div className="session-modal__button-group">
<SessionButton
text={window.i18n('clear')}
buttonColor={SessionButtonColor.Danger}
buttonType={SessionButtonType.Simple}
onClick={() => {
if (!askingConfirmation) {
setAskingConfirmation(true);
return;
}
if (deleteMode === 'device_only') {
void onDeleteEverythingLocallyOnly();
} else if (deleteMode === 'device_and_network') {
void onDeleteEverythingAndNetworkData();
}
}}
disabled={isLoading}
/>
<SessionButton
text={window.i18n('cancel')}
buttonType={SessionButtonType.Simple}
onClick={() => {
dispatch(updateDeleteAccountModal(null));
}}
disabled={isLoading}
/>
</div>
<SpacerLG />
<SessionSpinner loading={isLoading} />
</div>
</SessionWrapperModal>
);
};