Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Adding Issue selection as second step and forcing user to add the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel committed Aug 8, 2023
1 parent 0582b5d commit 781f6da
Showing 1 changed file with 36 additions and 45 deletions.
81 changes: 36 additions & 45 deletions Sources/BraveVPN/BraveVPNContactFormViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,59 +207,27 @@ class BraveVPNContactFormViewController: TableViewController {
}
})), cellClass: MultilineSubtitleCell.self)

var section = Section(rows: [
let section = Section(rows: [
hostnameRow, tunnelProtocolRow, subscriptionTypeRow, receiptRow,
appVersionRow, timezoneRow, networkTypeRow, carrierRow, errorLogs
])

// MARK: Issue
var issueRow =
Row(
text: Strings.VPN.contactFormIssue, detailText: IssueType.other.displayString,
accessory: .disclosureIndicator, cellClass: MultilineSubtitleCell.self)

let optionChanged = {
[weak self]
(vc: OptionSelectionViewController<IssueType>, option: IssueType) -> Void in
self?.dataSource.reloadCell(row: issueRow, section: section, displayText: option.displayString)
self?.contactForm.issue = option.displayString ?? IssueType.other.displayString
}

issueRow.selection = { [weak self] in
let optionsVC =
OptionSelectionViewController<IssueType>(
options: IssueType.allCases,
optionChanged: optionChanged)

self?.navigationController?.pushViewController(optionsVC, animated: true)
}

section.rows.append(issueRow)

let sendButton = Row(
text: Strings.VPN.contactFormSendButton,
selection: { [weak self] in
guard let self = self else { return }
if !MFMailComposeViewController.canSendMail() {
Logger.module.error("Can't send email on this device")
let alert = UIAlertController(
title: Strings.genericErrorTitle,
message: Strings.VPN.contactFormEmailNotConfiguredBody,
preferredStyle: .alert)
let okAction = UIAlertAction(title: Strings.OKString, style: .default)
alert.addAction(okAction)
self.present(alert, animated: true)
return
}

let mail = MFMailComposeViewController().then {
$0.mailComposeDelegate = self
$0.setToRecipients([self.supportEmail])
}

mail.setSubject(Strings.VPN.contactFormTitle)
mail.setMessageBody(self.composeEmailBody(with: self.contactForm), isHTML: false)
self.present(mail, animated: true)
let optionChanged = { [weak self] (vc: OptionSelectionViewController<IssueType>, option: IssueType) -> Void in
self?.contactForm.issue = option.displayString
self?.createEmailOutline()
}

let optionsVC =
OptionSelectionViewController<IssueType>(
options: IssueType.allCases,
optionChanged: optionChanged)

self.navigationController?.pushViewController(optionsVC, animated: true)

}, cellClass: CenteredButtonCell.self)

let footerText =
Expand All @@ -268,6 +236,29 @@ class BraveVPNContactFormViewController: TableViewController {

dataSource.sections = [section, buttonSection]
}

private func createEmailOutline() {
if !MFMailComposeViewController.canSendMail() {
Logger.module.error("Can't send email on this device")
let alert = UIAlertController(
title: Strings.genericErrorTitle,
message: Strings.VPN.contactFormEmailNotConfiguredBody,
preferredStyle: .alert)
let okAction = UIAlertAction(title: Strings.OKString, style: .default)
alert.addAction(okAction)
present(alert, animated: true)
return
}

let mail = MFMailComposeViewController().then {
$0.mailComposeDelegate = self
$0.setToRecipients([self.supportEmail])
}

mail.setSubject(Strings.VPN.contactFormTitle)
mail.setMessageBody(self.composeEmailBody(with: self.contactForm), isHTML: false)
present(mail, animated: true)
}

private var getNetworkType: String {
let status = Reach().connectionStatus()
Expand Down

0 comments on commit 781f6da

Please sign in to comment.