Manos Chorianopoulos

add createUnifiedCoupon functionality at UnifiedCouponsViewController

...@@ -37,7 +37,9 @@ import SwiftEventBus ...@@ -37,7 +37,9 @@ import SwiftEventBus
37 37
38 DispatchQueue.main.async { 38 DispatchQueue.main.async {
39 self.unifiedCoupons = swiftApi().getUnifiedCouponList() 39 self.unifiedCoupons = swiftApi().getUnifiedCouponList()
40 - self.tableView.reloadData() 40 + // self.tableView.reloadData()
41 + // Reload the Unified Coupons section only
42 + self.tableView.reloadSections(IndexSet(integer: 0), with: .automatic)
41 43
42 if (self.unifiedCoupons.count == 0 && self.smCoupons.count == 0) { 44 if (self.unifiedCoupons.count == 0 && self.smCoupons.count == 0) {
43 self.emptyView.isHidden = false 45 self.emptyView.isHidden = false
...@@ -53,7 +55,9 @@ import SwiftEventBus ...@@ -53,7 +55,9 @@ import SwiftEventBus
53 55
54 DispatchQueue.main.async { 56 DispatchQueue.main.async {
55 self.smCoupons = swiftApi().getSMCouponList() 57 self.smCoupons = swiftApi().getSMCouponList()
56 - self.tableView.reloadData() 58 + // self.tableView.reloadData()
59 + // Reload the SM Coupons section only
60 + self.tableView.reloadSections(IndexSet(integer: 1), with: .automatic)
57 61
58 if (self.unifiedCoupons.count == 0 && self.smCoupons.count == 0) { 62 if (self.unifiedCoupons.count == 0 && self.smCoupons.count == 0) {
59 self.emptyView.isHidden = false 63 self.emptyView.isHidden = false
...@@ -183,13 +187,71 @@ import SwiftEventBus ...@@ -183,13 +187,71 @@ import SwiftEventBus
183 } 187 }
184 } 188 }
185 189
190 + func showSuccessDialog() -> Void {
191 +
192 + let alert = UIAlertController(title: "Δημιουργία Κουπονιού", message: "Το ενιαίο κουπόνι σου δημιουργήθηκε επιτυχώς.", preferredStyle: .alert)
193 + alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
194 + switch action.style{
195 + case .default:
196 + print("default")
197 +// self.navigationController?.popViewController(animated: true)
198 + // self.dismiss(animated: true, completion: {})
199 +
200 + case .cancel:
201 + print("cancel")
202 +
203 + case .destructive:
204 + print("destructive")
205 +
206 + }
207 + }))
208 + self.present(alert, animated: true, completion: nil)
209 + }
210 +
211 + func showFailureDialog() -> Void {
212 +
213 + let alert = UIAlertController(title: "Αποτυχία Δημιουργίας Κουπονιού", message: "Το ενιαίο κουπόνι σου δεν δημιουργήθηκε. Προσπάθησε ξανά.", preferredStyle: .alert)
214 + alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
215 + switch action.style{
216 + case .default:
217 + print("default")
218 +
219 + case .cancel:
220 + print("cancel")
221 +
222 + case .destructive:
223 + print("destructive")
224 +
225 + }
226 + }))
227 + self.present(alert, animated: true, completion: nil)
228 + }
229 +
186 // MARK: - Actions 230 // MARK: - Actions
187 @IBAction func submitButtonAction(_ sender: Any) { 231 @IBAction func submitButtonAction(_ sender: Any) {
188 // let smCouponsString = self.smCouponsSelected.map { $0.coupon ?? "" }.joined(separator: ",") 232 // let smCouponsString = self.smCouponsSelected.map { $0.coupon ?? "" }.joined(separator: ",")
189 // swiftApi().logTrackersEvent("click", ("UnifySMCoupons:" + (smCouponsString))) 233 // swiftApi().logTrackersEvent("click", ("UnifySMCoupons:" + (smCouponsString)))
190 234
191 - // TODO: Add action 235 + let smCouponCodes = self.smCouponsSelected.map { $0.coupon ?? "" }
192 - 236 + swiftApi().createUnifiedCouponAsync(couponCodes: smCouponCodes) { responseData in
237 + if (responseData != nil) {
238 + DispatchQueue.main.async {
239 + if (responseData?.getStatus == 1) {
240 + self.smCouponsSelected = []
241 + self.circleImageView.image = UIImage(named: "circle_unchecked", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) // Unselected image
242 + self.handleSubmitButtonUI()
243 + // Reload the SM Coupons section only
244 + self.tableView.reloadSections(IndexSet(integer: 1), with: .automatic)
245 +
246 + self.showSuccessDialog()
247 + }
248 +
249 + }
250 + }
251 + } failureCallback: { errorCode in
252 + self.showFailureDialog()
253 + }
254 +
193 } 255 }
194 } 256 }
195 257
......