fixed bug on appointments where spinners was not populating the correct data

This commit is contained in:
Alex
2026-04-11 22:02:06 -06:00
parent e7a4e2be7a
commit 6245fa88da

View File

@@ -44,6 +44,7 @@ public class AppointmentDetailViewModel extends ViewModel {
private long appointmentId = -1;
private boolean isOriginallyCancel = false;
private boolean isOriginallyCompletedOrMissed = false;
private Long currentCustomerId;
private Long currentStoreId;
private Long currentPetId;
@@ -233,6 +234,8 @@ public class AppointmentDetailViewModel extends ViewModel {
if (resource != null && resource.status == Resource.Status.SUCCESS && resource.data != null) {
AppointmentDTO a = resource.data;
isOriginallyCancel = "CANCELLED".equalsIgnoreCase(a.getAppointmentStatus());
isOriginallyCompletedOrMissed = "COMPLETED".equalsIgnoreCase(a.getAppointmentStatus())
|| "MISSED".equalsIgnoreCase(a.getAppointmentStatus());
currentCustomerId = a.getCustomerId();
currentStoreId = a.getStoreId();
currentPetId = a.getPetId();
@@ -284,21 +287,18 @@ public class AppointmentDetailViewModel extends ViewModel {
public void onDateOrTimeChanged(String date, String time, String currentStatus) {
updateViewState(s -> {
s.availableStatuses = calculateAvailableStatuses(s.isEditing, date, time, currentStatus);
// Keep selectedStatus if still valid; prefer explicit currentStatus from UI if valid
java.util.List<String> available = java.util.Arrays.asList(s.availableStatuses);
if (!currentStatus.isEmpty() && available.contains(currentStatus)) {
s.selectedStatus = currentStatus;
} else if (!available.contains(s.selectedStatus) && s.availableStatuses.length > 0) {
s.selectedStatus = s.availableStatuses[0];
}
boolean isPast = DateTimeUtils.isDateTimeInPast(date, time);
if (isOriginallyCancel) {
s.isPast = true;
setAllFieldsEnabled(s, false);
s.isStatusEnabled = false;
s.isSaveVisible = false;
} else if (isPast) {
} else if (isOriginallyCompletedOrMissed) {
s.isPast = true;
setAllFieldsEnabled(s, false);
s.isStatusEnabled = true;
@@ -324,7 +324,7 @@ public class AppointmentDetailViewModel extends ViewModel {
if (!isEditing) return new String[]{"Booked"};
if (date == null || date.isEmpty()) return new String[]{};
if (isOriginallyCancel) return new String[]{"Cancelled"};
if (DateTimeUtils.isDateTimeInPast(date, currentTime)) return new String[]{"Completed", "Missed"};
if (isOriginallyCompletedOrMissed) return new String[]{"Completed", "Missed"};
return new String[]{"Booked", "Cancelled"};
}
@@ -357,8 +357,8 @@ public class AppointmentDetailViewModel extends ViewModel {
s.isCustomerEnabled = true;
s.isStoreEnabled = true;
s.isServiceEnabled = true;
s.isPetEnabled = false; // until customer selected
s.isStaffEnabled = false; // until store selected
s.isPetEnabled = false;
s.isStaffEnabled = false;
s.availableStatuses = new String[]{"Booked"};
s.selectedStatus = "Booked";
}