Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Alert on detachAddress #865

Merged
merged 11 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Mail/Views/Alerts/DetachMailboxConfirmationView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Infomaniak Mail - iOS App
Copyright (C) 2022 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import InfomaniakCoreUI
import InfomaniakDI
import MailCore
import MailResources
import SwiftUI

struct DetachMailboxConfirmationView: View {
@EnvironmentObject private var navigationState: NavigationState

let mailbox: Mailbox

var body: some View {
VStack(alignment: .leading, spacing: 24) {
Text(MailResourcesStrings.Localizable.popupDetachMailboxTitle)
.textStyle(.bodyMedium)
Text(attributedString())
.textStyle(.bodySecondary)
ModalButtonsView(primaryButtonTitle: MailResourcesStrings.Localizable.buttonConfirm, primaryButtonAction: detach)
}
}

func attributedString() -> AttributedString {
do {
var text = try AttributedString(markdown: MailResourcesStrings.Localizable
.popupDetachMailboxDescription("**\(mailbox.email)**"))

if let range = text.range(of: mailbox.email) {
text[range].foregroundColor = MailResourcesAsset.textPrimaryColor.swiftUIColor
}

return text
} catch {
return ""
}
}

private func detach() {
@InjectService var matomo: MatomoUtils
matomo.track(eventWithCategory: .invalidPasswordMailbox, name: "detachMailboxConfirm")

Task {
await tryOrDisplayError {
try await AccountManager.instance.detachMailbox(mailbox: mailbox)
navigationState.transitionToRootViewDestination(.mainView)
}
}
}
}

struct DetachMailboxConfirmationView_Previews: PreviewProvider {
static var previews: some View {
DetachMailboxConfirmationView(mailbox: PreviewHelper.sampleMailbox)
}
}
2 changes: 1 addition & 1 deletion Mail/Views/Switch User/AddMailboxView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct AddMailboxView: View {
}
.padding(.bottom, 4)

Text(MailResourcesStrings.Localizable.errorAttachAddressInput)
Text(MailResourcesStrings.Localizable.attachAddressInputHelper)
.textStyle(showError ? .labelError : .labelSecondary)
.padding(.bottom, 8)

Expand Down
29 changes: 13 additions & 16 deletions Mail/Views/Unavailable Mailbox/UpdateMailboxPasswordView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ struct UpdateMailboxPasswordView: View {
@State private var updatedMailboxPassword = ""
@State private var isShowingError = false
@State private var isLoading = false
@State private var isShowingDetachMailboxAlertView = false

private var disableButton: Bool {
Ambrdctr marked this conversation as resolved.
Show resolved Hide resolved
return isLoading || showPasswordLengthWarning
}

private var showPasswordLengthWarning: Bool {
return !updatedMailboxPassword.isEmpty && (updatedMailboxPassword.count < 5 || updatedMailboxPassword.count > 80)
return updatedMailboxPassword.count < 5 || updatedMailboxPassword.count > 80
}

let mailbox: Mailbox
Expand All @@ -49,7 +50,7 @@ struct UpdateMailboxPasswordView: View {
.textStyle(.bodySecondary)
MailButton(label: MailResourcesStrings.Localizable.buttonDetachMailbox) {
matomo.track(eventWithCategory: .invalidPasswordMailbox, name: "detachMailbox")
detachAddress()
isShowingDetachMailboxAlertView = true
}
.mailButtonStyle(.link)
.disabled(isLoading)
Expand Down Expand Up @@ -84,7 +85,7 @@ struct UpdateMailboxPasswordView: View {
updateMailboxPassword()
}
.mailButtonFullWidth(true)
.disabled(isLoading)
.disabled(disableButton)

MailButton(label: MailResourcesStrings.Localizable.buttonPasswordForgotten) {
// Empty for now, WIP
Expand All @@ -95,11 +96,19 @@ struct UpdateMailboxPasswordView: View {

Spacer()
}
.onChange(of: updatedMailboxPassword) { newValue in
if !newValue.isEmpty {
isShowingError = false
}
}
.padding()
.navigationBarTitleDisplayMode(.inline)
.navigationTitle(MailResourcesStrings.Localizable.enterPasswordTitle)
.sheetViewStyle()
.matomoView(view: ["UpdateMailboxPasswordView"])
.customAlert(isPresented: $isShowingDetachMailboxAlertView) {
DetachMailboxConfirmationView(mailbox: mailbox)
}
}

func updateMailboxPassword() {
Expand All @@ -110,19 +119,7 @@ struct UpdateMailboxPasswordView: View {
navigationState.transitionToRootViewDestination(.mainView)
} catch {
isShowingError = true
}
isLoading = false
}
}

func detachAddress() {
Task {
isLoading = true
do {
try await AccountManager.instance.detachMailbox(mailbox: mailbox)
navigationState.transitionToRootViewDestination(.mainView)
} catch {
isShowingError = true
updatedMailboxPassword = ""
}
isLoading = false
}
Expand Down
Binary file modified MailResources/Localizable/de.lproj/Localizable.strings
Binary file not shown.
Binary file modified MailResources/Localizable/en.lproj/Localizable.strings
Binary file not shown.
Binary file modified MailResources/Localizable/es.lproj/Localizable.strings
Binary file not shown.
Binary file modified MailResources/Localizable/fr.lproj/Localizable.strings
Binary file not shown.
Binary file modified MailResources/Localizable/it.lproj/Localizable.strings
Binary file not shown.
Loading