Skip to content

Commit

Permalink
Re-add logic for disabling card button prior to validation pass
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewc committed Jan 26, 2024
1 parent 2326c4b commit db727e8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ class PrimerCardDataErrorsModel: PrimerBaseCardDataModel {
self.cardholderName = ""
self.selectedCardNetwork = .unknown
}

var hasErrors: Bool {
!(
cardNumber.isEmpty &&
expiryDate.isEmpty &&
cvvNumber.isEmpty &&
cardholderName.isEmpty
)
}
}

extension PrimerCardDataErrorsModel: PrimerDataServiceErrorsDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class PrimerCardDataModel: PrimerBaseCardDataModel {
}
}.store(in: &cancellables)
}

var isEmpty: Bool {
cardNumber.isEmpty &&
expiryDate.isEmpty &&
cvvNumber.isEmpty &&
cardholderName.isEmpty
}
}

extension PrimerCardDataModel: PrimerDataServiceModelsDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ struct CardDetailsFormView: View {
)

VStack(spacing: 12) {
PrimerButton(action: onSubmit, labelText: "Pay")
PrimerButton(
action: onSubmit,
labelText: "Pay",
isEnabled: !errors.hasErrors && !model.isEmpty
)
}
.padding([.leading, .trailing], 6)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct PrimerButton: View {

let labelText: String

let isEnabled: Bool

@State var isWaitingForActionToComplete: Bool = false

var body: some View {
Expand All @@ -31,6 +33,6 @@ struct PrimerButton: View {
}
}
.primerButtonStyle()
.disabled(isWaitingForActionToComplete)
.disabled(isWaitingForActionToComplete || !isEnabled)
}
}

0 comments on commit db727e8

Please sign in to comment.