Manos Chorianopoulos

add createUnifiedCoupon functionality at UnifiedCouponsViewController

......@@ -37,7 +37,9 @@ import SwiftEventBus
DispatchQueue.main.async {
self.unifiedCoupons = swiftApi().getUnifiedCouponList()
self.tableView.reloadData()
// self.tableView.reloadData()
// Reload the Unified Coupons section only
self.tableView.reloadSections(IndexSet(integer: 0), with: .automatic)
if (self.unifiedCoupons.count == 0 && self.smCoupons.count == 0) {
self.emptyView.isHidden = false
......@@ -53,7 +55,9 @@ import SwiftEventBus
DispatchQueue.main.async {
self.smCoupons = swiftApi().getSMCouponList()
self.tableView.reloadData()
// self.tableView.reloadData()
// Reload the SM Coupons section only
self.tableView.reloadSections(IndexSet(integer: 1), with: .automatic)
if (self.unifiedCoupons.count == 0 && self.smCoupons.count == 0) {
self.emptyView.isHidden = false
......@@ -183,12 +187,70 @@ import SwiftEventBus
}
}
func showSuccessDialog() -> Void {
let alert = UIAlertController(title: "Δημιουργία Κουπονιού", message: "Το ενιαίο κουπόνι σου δημιουργήθηκε επιτυχώς.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default")
// self.navigationController?.popViewController(animated: true)
// self.dismiss(animated: true, completion: {})
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}
}))
self.present(alert, animated: true, completion: nil)
}
func showFailureDialog() -> Void {
let alert = UIAlertController(title: "Αποτυχία Δημιουργίας Κουπονιού", message: "Το ενιαίο κουπόνι σου δεν δημιουργήθηκε. Προσπάθησε ξανά.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}
}))
self.present(alert, animated: true, completion: nil)
}
// MARK: - Actions
@IBAction func submitButtonAction(_ sender: Any) {
// let smCouponsString = self.smCouponsSelected.map { $0.coupon ?? "" }.joined(separator: ",")
// swiftApi().logTrackersEvent("click", ("UnifySMCoupons:" + (smCouponsString)))
// TODO: Add action
let smCouponCodes = self.smCouponsSelected.map { $0.coupon ?? "" }
swiftApi().createUnifiedCouponAsync(couponCodes: smCouponCodes) { responseData in
if (responseData != nil) {
DispatchQueue.main.async {
if (responseData?.getStatus == 1) {
self.smCouponsSelected = []
self.circleImageView.image = UIImage(named: "circle_unchecked", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) // Unselected image
self.handleSubmitButtonUI()
// Reload the SM Coupons section only
self.tableView.reloadSections(IndexSet(integer: 1), with: .automatic)
self.showSuccessDialog()
}
}
}
} failureCallback: { errorCode in
self.showFailureDialog()
}
}
}
......