From 3f548009b00f424912926381bd1f886f0cc66a82 Mon Sep 17 00:00:00 2001 From: cstock123 Date: Mon, 1 Oct 2018 23:05:12 -0700 Subject: [PATCH] resolved #196 join Ministry team button functionality to send a text to leaders of the team --- .../MinistryTeams/MinistryTeamDetailsVC.swift | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/CruCentralCoast/Community/MinistryTeams/MinistryTeamDetailsVC.swift b/CruCentralCoast/Community/MinistryTeams/MinistryTeamDetailsVC.swift index 73b32db2..642eb2da 100644 --- a/CruCentralCoast/Community/MinistryTeams/MinistryTeamDetailsVC.swift +++ b/CruCentralCoast/Community/MinistryTeams/MinistryTeamDetailsVC.swift @@ -7,8 +7,9 @@ // import UIKit +import MessageUI -class MinistryTeamDetailsVC: UIViewController { +class MinistryTeamDetailsVC: UIViewController, MFMessageComposeViewControllerDelegate{ @IBOutlet weak var bannerImageView: UIImageView! @IBOutlet weak var nameLabel: UILabel! @@ -16,6 +17,8 @@ class MinistryTeamDetailsVC: UIViewController { @IBOutlet weak var leaderNamesLabel: UILabel! @IBOutlet weak var summaryLabel: UILabel! + var leaderPhoneNumbers : [String] = [] + override var prefersStatusBarHidden: Bool { return true } override func viewDidLoad() { @@ -29,8 +32,23 @@ class MinistryTeamDetailsVC: UIViewController { } @IBAction func joinMinistryTeam() { - // TODO - self.presentAlert(title: "Join Ministry Team", message: "Coming Soon...") + if MFMessageComposeViewController.canSendText() { + if self.leaderPhoneNumbers.isEmpty { + self.presentAlert(title: "Can't contact Leader", message: "Sorry, there is no phone number listed for this Ministry Team") + } else { + let controller = MFMessageComposeViewController() + controller.body = "Hey I'm interested in joining your Ministry Team!" + controller.recipients = self.leaderPhoneNumbers + controller.messageComposeDelegate = self + self.present(controller, animated: true, completion: nil) + } + } else { + print("error can't send text") + } + } + + func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) { + controller.dismiss(animated: true, completion: nil) } func configure(with ministryTeam: MinistryTeam) { @@ -40,6 +58,8 @@ class MinistryTeamDetailsVC: UIViewController { self.leaderNamesLabel.text = "Leaders: \(ministryTeam.leaderNames ?? "N/A")" self.summaryLabel.text = ministryTeam.summary self.bannerImageView.downloadedFrom(link: ministryTeam.imageLink, contentMode: .scaleAspectFill) + + self.leaderPhoneNumbers = ministryTeam.leaders.filter({ $0.phone != nil }).compactMap({ $0.phone! }) } } }