Skip to content

Commit e5ac6f0

Browse files
committed
Share logic for unsaved changes for "Update" CTA visibility and whether to show discard changes action sheet on back navigation.
1 parent 16148dc commit e5ac6f0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

WooCommerce/Classes/ViewRelated/Products/Edit Product/ProductFormViewController.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ final class ProductFormViewController: UIViewController {
2020
private var product: Product {
2121
didSet {
2222
defer {
23-
let isUpdateEnabled = product != originalProduct ||
24-
productImageActionHandler.productImageStatuses.hasImagesPendingUpload
23+
let isUpdateEnabled = hasUnsavedChanges(product: product)
2524
updateNavigationBar(isUpdateEnabled: isUpdateEnabled)
2625
}
2726

@@ -409,7 +408,7 @@ private extension ProductFormViewController {
409408
//
410409
extension ProductFormViewController {
411410
override func shouldPopOnBackButton() -> Bool {
412-
if product != originalProduct {
411+
if hasUnsavedChanges(product: product) {
413412
presentBackNavigationActionSheet()
414413
return false
415414
}
@@ -421,6 +420,10 @@ extension ProductFormViewController {
421420
self?.navigationController?.popViewController(animated: true)
422421
})
423422
}
423+
424+
private func hasUnsavedChanges(product: Product) -> Bool {
425+
return product != originalProduct || productImageActionHandler.productImageStatuses.hasImagesPendingUpload
426+
}
424427
}
425428

426429

0 commit comments

Comments
 (0)