Skip to content

Commit

Permalink
fix: fixed the buttons for payment methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MatheaGjerde committed Mar 30, 2026
1 parent d1c9f2b commit b841bb5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class DonationPageView extends BorderPane {
private final Map<Object, BigDecimal> elementAmounts = new HashMap<>();
private final Map<Object, String> elementPaymentMethods = new HashMap<>();

private BigDecimal selectedAmount = null;
private String selectedPaymentMethod = null;
private Button donateBtn;

public DonationPageView(AppState appState, NavigationController nav, DonationController donationController) {
this.appState = appState;
this.nav = nav;
Expand Down Expand Up @@ -106,7 +110,12 @@ private VBox createCustomButton() {

box.setOnMouseClicked(e -> {
try {
BigDecimal amount = new BigDecimal(amountField.getText().trim());
String text = amountField.getText().trim();
if (text.isEmpty()) {
return;
}
BigDecimal amount = new BigDecimal(text);

elementAmounts.put(box, amount);
selectDonationElement(box);
} catch (NumberFormatException exception) {
Expand Down Expand Up @@ -136,18 +145,21 @@ public HBox createPaymentMethodSection() {

HBox sectionPm = new HBox(appleBtn, vippsBtn, visaBtn);
sectionPm.setAlignment(Pos.CENTER);
sectionPm.setSpacing(20);
sectionPm.setPadding(new Insets(20, 20, 20, 20));
return sectionPm;
}

private HBox createDonateSection() {
Button donateBtn = new Button("Donate");
donateBtn = new Button("Donate");
donateBtn.getStyleClass().add("donate-button");

donateBtn.setDisable(true);

donateBtn.setOnAction(e -> donationController.handleDonate());

HBox section = new HBox(donateBtn);
section.setAlignment(Pos.CENTER);
section.setPadding(new Insets(20, 0, 30, 0));
return section;
}

Expand All @@ -174,18 +186,18 @@ private void selectPaymentMethod(Node element) {
private void extractAndStoreAmount(Node element) {
BigDecimal amount = elementAmounts.get(element);
if (amount != null) {
selectedAmount = amount;
appState.setCurrentDonationAmount(amount);
} else {
System.err.println("Error: No amount found for selected element");
updateDonationButtonState();
}
}

private void extractAndStorePaymentMethod(Node element) {
String paymentMethod = elementPaymentMethods.get(element);
if (paymentMethod != null) {
selectedPaymentMethod = paymentMethod;
appState.setCurrentPaymentMethod(paymentMethod);
} else {
System.err.println("Error: No amount found for selected element");
updateDonationButtonState();
}
}

Expand All @@ -196,5 +208,8 @@ private BigDecimal parseAmount(String amountStr) {
return BigDecimal.ZERO;
}
}
private void updateDonationButtonState() {
donateBtn.setDisable(selectedAmount == null || selectedPaymentMethod == null);
}

}
39 changes: 35 additions & 4 deletions src/main/resources/donationpage/donation.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@
-fx-text-fill: white;
-fx-border-color: #111;
}
.donation-button-selected:hover {
-fx-background-color: #222;
-fx-border-color: #222;
}

.donation-button-selected Text,
.donation-button-selected .donation-input {
-fx-fill: white;
-fx-border-color: transparent transparent white transparent;
-fx-text-fill: white;
-fx-prompt-text-fill: #ccc;
}

.donation-title {
-fx-font-size: 18px;
-fx-font-weight: bold;
-fx-fill: #111;
}
.donation-amount {
-fx-font-size: 18px;
-fx-fill: #111;
}
.donation-input {
-fx-font-size:16px;
-fx-pref-width: 140px;
Expand All @@ -51,3 +60,25 @@
-fx-background-color: #c02020;
}

.payment-method-button {
-fx-background-color: #111;
-fx-text-fill: white;
-fx-font-size: 16px;
-fx-font-weight: bold;
-fx-pref-width: 180px;
-fx-pref-height: 45px;
-fx-background-radius: 6;
-fx-border-radius: 6;
-fx-cursor: hand;
}
.payment-method-button:hover {
-fx-background-color: #222;
}
.payment-method-selected,
.payment-method-selected:hover {
-fx-background-color: #e03030;
}
.donation-button-selected .donation-title,
.donation-button-selected .donation-amount {
-fx-fill: white;
}

0 comments on commit b841bb5

Please sign in to comment.