Harden appointment dialog

This commit is contained in:
2026-04-04 16:23:28 -06:00
parent 109f967435
commit 1079abf0c5

View File

@@ -19,6 +19,7 @@ import org.example.petshopdesktop.auth.UserSession;
import org.example.petshopdesktop.util.ActivityLogger;
import java.time.LocalTime;
import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
@@ -101,6 +102,11 @@ public class AppointmentDialogController {
cbAppointmentStatus.setItems(statusList);
cbPet.setDisable(true);
cbPet.setPromptText("Select a customer first");
cbCustomer.setPromptText("Select a customer");
cbService.setPromptText("Select a service");
dpAppointmentDate.setValue(LocalDate.now().plusDays(1));
cbAppointmentStatus.setValue("Booked");
// Hours 9 AM - 5 PM
for (int i = 9; i <= 17; i++) {
@@ -161,8 +167,10 @@ public class AppointmentDialogController {
cbPet.setItems(FXCollections.observableArrayList());
cbPet.setDisable(customerId == null);
if (customerId != null) {
cbPet.setPromptText("Loading customer pets...");
loadCustomerPets(customerId);
} else {
cbPet.setPromptText("Select a customer first");
pendingPetSelectionId = null;
}
});
@@ -304,14 +312,25 @@ public class AppointmentDialogController {
List<DropdownOption> pets = DropdownApi.getInstance().getCustomerPets(customerId);
Platform.runLater(() -> {
cbPet.setItems(FXCollections.observableArrayList(pets));
cbPet.setDisable(false);
cbPet.setDisable(pets == null || pets.isEmpty());
cbPet.setPromptText(pets == null || pets.isEmpty() ? "No pets for selected customer" : "Select a pet");
if (pendingPetSelectionId != null) {
boolean matched = false;
for (DropdownOption pet : cbPet.getItems()) {
if (pet.getId() != null && pet.getId().equals(pendingPetSelectionId)) {
cbPet.setValue(pet);
matched = true;
break;
}
}
if (!matched && selectedAppointment != null && selectedAppointment.getPetName() != null && !selectedAppointment.getPetName().isBlank()) {
DropdownOption legacy = new DropdownOption();
legacy.setId(pendingPetSelectionId);
legacy.setLabel(selectedAppointment.getPetName() + " (legacy appointment pet)");
cbPet.getItems().add(0, legacy);
cbPet.setValue(legacy);
cbPet.setDisable(false);
}
pendingPetSelectionId = null;
}
});
@@ -322,6 +341,7 @@ public class AppointmentDialogController {
ex,
"Loading customer pets for appointment dialog");
cbPet.setDisable(true);
cbPet.setPromptText("Unable to load pets");
showError("Error loading pets for selected customer");
});
}