From 921ce7989157f7c80f0426233172c0a855380fa2 Mon Sep 17 00:00:00 2001 From: Andrew Simachev Date: Fri, 29 Mar 2024 14:19:51 +0100 Subject: [PATCH] JS-4229: fix --- src/json/text.json | 3 +++ src/ts/lib/action.ts | 30 +++++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/json/text.json b/src/json/text.json index 24f68de49b..77f37cd1ca 100644 --- a/src/json/text.json +++ b/src/json/text.json @@ -1666,6 +1666,9 @@ "spaceDeleteWarningTitle": "Delete \"%s\" space", "spaceDeleteWarningText": "This space will be deleted irrevocably. You can't undo this action.", "spaceDeleteToast": "Space \"%s\" was deleted", + "spaceLeaveWarningTitle": "Leave a space", + "spaceLeaveWarningText": "\"%s\" will be removed from your devices and you will no longer have access to it", + "spaceLeaveToast": "You have left the \"%s\" space", "quickOption0": "Exact date", "quickOption1": "Yesterday", diff --git a/src/ts/lib/action.ts b/src/ts/lib/action.ts index 4a954b80e3..6b3dc5187f 100644 --- a/src/ts/lib/action.ts +++ b/src/ts/lib/action.ts @@ -543,23 +543,31 @@ class Action { }; removeSpace (id: string, route: string, callBack?: (message: any) => void) { - const { accountSpaceId } = authStore; - const space = UtilSpace.getSpaceview(); const deleted = UtilSpace.getSpaceviewBySpaceId(id); if (!deleted) { return; }; - analytics.event('ClickDeleteSpace', { route }); + const { accountSpaceId } = authStore; + const { space } = commonStore; + const isOwner = UtilSpace.isOwner(id); + const name = UtilCommon.shorten(deleted.name, 32); + const suffix = isOwner ? 'Delete' : 'Leave'; + const title = UtilCommon.sprintf(translate(`space${suffix}WarningTitle`), name); + const text = UtilCommon.sprintf(translate(`space${suffix}WarningText`), name); + const toast = UtilCommon.sprintf(translate(`space${suffix}Toast`), name); + const confirm = isOwner ? translate('commonDelete') : translate('commonLeaveSpace'); + + analytics.event(`Click${suffix}Space`, { route }); popupStore.open('confirm', { data: { - title: UtilCommon.sprintf(translate('spaceDeleteWarningTitle'), deleted.name), - text: translate('spaceDeleteWarningText'), - textConfirm: translate('commonDelete'), + title, + text, + textConfirm: confirm, onConfirm: () => { - analytics.event('ClickDeleteSpaceWarning', { type: 'Delete', route }); + analytics.event(`Click${suffix}SpaceWarning`, { type: suffix, route }); const cb = () => { C.SpaceDelete(id, (message: any) => { @@ -568,20 +576,20 @@ class Action { }; if (!message.error.code) { - Preview.toastShow({ text: UtilCommon.sprintf(translate('spaceDeleteToast'), deleted.name) }); - analytics.event('DeleteSpace', { type: deleted.spaceAccessType, route }); + Preview.toastShow({ text: toast }); + analytics.event(`${suffix}Space`, { type: deleted.spaceAccessType, route }); }; }); }; - if (space.id == deleted.id) { + if (space == id) { UtilRouter.switchSpace(accountSpaceId, '', cb); } else { cb(); }; }, onCancel: () => { - analytics.event('ClickDeleteSpaceWarning', { type: 'Cancel', route }); + analytics.event(`Click${suffix}SpaceWarning`, { type: 'Cancel', route }); } }, });