Skip to content

Commit

Permalink
Check label limits, handle new unsubscribe reason
Browse files Browse the repository at this point in the history
close: #7943

Co-authored-by: ivk <ivk@tutao.de>
  • Loading branch information
BijinDev and charlag committed Nov 21, 2024
1 parent 307688a commit 2b72c9a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/common/api/common/TutanotaConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ export const enum UnsubscribeFailureReason {
INVOICE_NOT_PAID = "unsubscribe.invoice_not_paid",
HAS_CONTACT_LIST_GROUP = "unsubscribe.has_contact_list_group",
ACTIVE_APPSTORE_SUBSCRIPTION = "unsubscribe.active_appstore_subscription",
LABEL_LIMIT_EXCEEDED = "unsubscribe.label_limit_exceeded",
}

// legacy, should be deleted after clients older than 3.114 have been disabled.
Expand Down
1 change: 1 addition & 0 deletions src/common/misc/TranslationKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1802,3 +1802,4 @@ export type TranslationKeyType =
| "emptyString_msg"
| "editLabel_action"
| "importantLabel_label"
| "labelLimitExceeded_msg"
3 changes: 3 additions & 0 deletions src/common/subscription/SwitchSubscriptionDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ function handleSwitchAccountPreconditionFailed(e: PreconditionFailedError): Prom
return showManageThroughAppStoreDialog()
}

case UnsubscribeFailureReason.LABEL_LIMIT_EXCEEDED:
return Dialog.message("labelLimitExceeded_msg")
default:
throw e
}
Expand Down Expand Up @@ -377,6 +379,7 @@ async function switchSubscription(targetSubscription: PlanType, dialog: Dialog,
} catch (e) {
if (e instanceof PreconditionFailedError) {
await handleSwitchAccountPreconditionFailed(e)

return currentPlanInfo.planType
}
throw e
Expand Down
92 changes: 52 additions & 40 deletions src/mail-app/mail/view/EditLabelDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,62 @@ import { TextField, TextFieldAttrs } from "../../../common/gui/base/TextField"
import m from "mithril"
import type { MailBox, MailFolder } from "../../../common/api/entities/tutanota/TypeRefs"
import { isOfflineError } from "../../../common/api/common/utils/ErrorUtils"
import { LockedError } from "../../../common/api/common/error/RestError"
import { LockedError, PreconditionFailedError } from "../../../common/api/common/error/RestError"
import { MailViewModel } from "./MailViewModel"
import { lang } from "../../../common/misc/LanguageViewModel"
import { ColorPickerView } from "../../../common/gui/base/colorPicker/ColorPickerView"
import { showNotAvailableForFreeDialog } from "../../../common/misc/SubscriptionDialogs"

export async function showEditLabelDialog(mailbox: MailBox | null, mailViewModel: MailViewModel, label: MailFolder | null): Promise<void> {
return new Promise((resolve) => {
let name = label ? label.name : ""
let color = label && label.color ? label.color : ""
Dialog.showActionDialog({
title: lang.get(label ? "editLabel_action" : "addLabel_action"),
allowCancel: true,
okAction: async (dialog: Dialog) => {
dialog.close()
try {
if (label) {
// editing a label
await mailViewModel.editLabel(label, { name, color })
} else if (mailbox) {
// adding a label
await mailViewModel.createLabel(mailbox, { name, color })
}
} catch (error) {
if (isOfflineError(error) || !(error instanceof LockedError)) {
throw error
}
const LIMIT_EXCEEDED_ERROR = "limitReached"

export async function showEditLabelDialog(mailbox: MailBox | null, mailViewModel: MailViewModel, label: MailFolder | null) {
let name = label ? label.name : ""
let color = label && label.color ? label.color : ""

async function onOkClicked(dialog: Dialog) {
dialog.close()
try {
if (label) {
// editing a label
await mailViewModel.editLabel(label, { name, color })
} else if (mailbox) {
// adding a label
await mailViewModel.createLabel(mailbox, { name, color })
}
} catch (error) {
if (error instanceof PreconditionFailedError) {
if (error.data === LIMIT_EXCEEDED_ERROR) {
showNotAvailableForFreeDialog()
} else {
Dialog.message("unknownError_msg")
}
},
child: () =>
m(".flex.col.gap-vpad", [
m(TextField, {
label: "name_label",
value: name,
oninput: (newName) => {
name = newName
},
} satisfies TextFieldAttrs),
m(ColorPickerView, {
value: color,
onselect: (newColor: string) => {
color = newColor
},
}),
]),
})
} else if (isOfflineError(error) || !(error instanceof LockedError)) {
throw error
}
}
}

Dialog.showActionDialog({
title: lang.get(label ? "editLabel_action" : "addLabel_action"),
allowCancel: true,
okAction: (dialog: Dialog) => {
onOkClicked(dialog)
},
child: () =>
m(".flex.col.gap-vpad", [
m(TextField, {
label: "name_label",
value: name,
oninput: (newName) => {
name = newName
},
} satisfies TextFieldAttrs),
m(ColorPickerView, {
value: color,
onselect: (newColor: string) => {
color = newColor
},
}),
]),
})
}

0 comments on commit 2b72c9a

Please sign in to comment.