-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #465 from Infomaniak/logout-alert
Logout alert
- Loading branch information
Showing
5 changed files
with
88 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import InfomaniakLogin | |
import MailCore | ||
import RealmSwift | ||
import SwiftUI | ||
import InfomaniakCore | ||
|
||
struct PreviewHelper { | ||
static let sampleMailboxManager = MailboxManager(mailbox: sampleMailbox, apiFetcher: MailApiFetcher()) | ||
|
@@ -122,4 +123,6 @@ struct PreviewHelper { | |
) | ||
|
||
static let sampleMergedContact = MergedContact(email: "[email protected]", remote: nil, local: nil) | ||
|
||
static let sampleAccount = Account(apiToken: ApiToken(accessToken: "", expiresIn: 0, refreshToken: "", scope: "", tokenType: "", userId: 0, expirationDate: Date())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
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 SwiftUI | ||
import MailResources | ||
import MailCore | ||
import InfomaniakCore | ||
|
||
struct LogoutConfirmationView: View { | ||
|
||
@Environment(\.window) private var window | ||
|
||
let account: Account | ||
|
||
let state: AccountAlert | ||
|
||
var body: some View { | ||
VStack(alignment: .leading, spacing: 24) { | ||
Text( MailResourcesStrings.Localizable.confirmLogoutTitle(account.user.email)) | ||
.textStyle(.header5) | ||
Text(MailResourcesStrings.Localizable.confirmLogoutDescription) | ||
.textStyle(.bodySecondary) | ||
BottomSheetButtonsView(primaryButtonTitle: MailResourcesStrings.Localizable.buttonLogout, | ||
secondaryButtonTitle: MailResourcesStrings.Localizable.buttonCancel, | ||
primaryButtonAction: logout, | ||
secondaryButtonAction: cancel) | ||
} | ||
} | ||
|
||
private func cancel() { | ||
state.state = nil | ||
} | ||
|
||
private func logout() { | ||
AccountManager.instance.removeTokenAndAccount(token: account.token) | ||
if let nextAccount = AccountManager.instance.accounts.first { | ||
(window?.windowScene?.delegate as? SceneDelegate)?.switchAccount(nextAccount) | ||
} else { | ||
(window?.windowScene?.delegate as? SceneDelegate)?.showLoginView() | ||
} | ||
AccountManager.instance.saveAccounts() | ||
state.state = nil | ||
} | ||
} | ||
|
||
struct LogoutConfirmationView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
LogoutConfirmationView(account: PreviewHelper.sampleAccount, state: AccountAlert()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.