Skip to content

Commit

Permalink
feat&Update[donationPage]: Add PaymentMethod and backButton from rele…
Browse files Browse the repository at this point in the history
…ase, fixing up upcoming mege conflict
  • Loading branch information
Fredrik Marjoni committed Apr 14, 2026
1 parent 5767aaa commit b1a1fb8
Showing 1 changed file with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javafx.scene.Node;

import java.math.BigDecimal;
import java.util.Objects;

public class DonationPageView extends BorderPane {
private final AppState appState;
Expand All @@ -24,25 +25,38 @@ public class DonationPageView extends BorderPane {

private Node currentlySelected = null;
private TextField customAmountField;
private Node selectedPaymentMethod = null;
private Button donateBtn;

public DonationPageView(AppState appState, NavigationController nav, DonationController donationController) {
this.appState = appState;
this.nav = nav;
this.donationController = donationController;

getStylesheets().add(getClass().getResource("/donationpage/donation.css").toExternalForm());
getStylesheets().add(Objects.requireNonNull(getClass().getResource("/donationpage/donation.css")).toExternalForm());

VBox content = new VBox();
content.getChildren().addAll(createDonationGrid(), createDonateSection());
content.getChildren().addAll(createBackButton(), createDonationGrid(), createPaymentMethodSection(), createDonateSection());

content.setOnMouseClicked(e -> {
if (e.getTarget() == content) {
clearSelection();
clearSelection();
}
});
setCenter(content);

}

private HBox createBackButton() {
Button backBtn = new Button("←");
backBtn.getStyleClass().add("back-button");
backBtn.setOnAction(e -> nav.showOrganizationPage());

HBox container = new HBox(backBtn);
container.setPadding(new Insets(10, 0, 0, 10));
return container;
}

private TilePane createDonationGrid(){
TilePane body = new TilePane();
body.setAlignment(Pos.CENTER);
Expand Down Expand Up @@ -136,8 +150,9 @@ private VBox createCustomButton() {
}

private HBox createDonateSection() {
Button donateBtn = new Button("Donate");
donateBtn = new Button("Donate");
donateBtn.getStyleClass().add("donate-button");
donateBtn.setDisable(true);
donateBtn.setOnAction(e -> donationController.requestDonationConfirmation());

Button clearBtn = new Button("Clear");
Expand All @@ -150,6 +165,23 @@ private HBox createDonateSection() {
return section;
}

public HBox createPaymentMethodSection() {
Button appleBtn = new Button("Apple Pay");
Button vippsBtn = new Button("Vipps");
Button visaBtn = new Button("Visa");

for (Button btn : new Button[]{appleBtn, vippsBtn, visaBtn}) {
btn.getStyleClass().add("payment-method-button");
btn.setOnAction(e -> selectPaymentMethod(btn));
}

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 void selectDonation(Node element) {
if (currentlySelected != null) {
currentlySelected.getStyleClass().remove("donation-button-selected");
Expand All @@ -159,6 +191,16 @@ private void selectDonation(Node element) {

BigDecimal amount = (BigDecimal) element.getUserData();
updateDonationAmount(amount);
updateDonationButtonState();
}

private void selectPaymentMethod(Node element) {
if (selectedPaymentMethod != null) {
selectedPaymentMethod.getStyleClass().remove("payment-method-selected");
}
selectedPaymentMethod = element;
selectedPaymentMethod.getStyleClass().add("payment-method-selected");
updateDonationButtonState();
}

private void clearSelection() {
Expand All @@ -168,9 +210,16 @@ private void clearSelection() {
updateDonationAmount(null);
}

if (selectedPaymentMethod != null) {
selectedPaymentMethod.getStyleClass().remove("payment-method-selected");
selectedPaymentMethod = null;
}

if (customAmountField != null) {
customAmountField.clear();
}

updateDonationButtonState();
}

private void updateDonationAmount(BigDecimal amount) {
Expand All @@ -185,4 +234,8 @@ private BigDecimal parseAmount(String amountStr) {
}
}

private void updateDonationButtonState() {
donateBtn.setDisable(currentlySelected == null || selectedPaymentMethod == null);
}

}

0 comments on commit b1a1fb8

Please sign in to comment.