avatar on staff register (#315)

This commit is contained in:
2026-04-15 16:06:17 -06:00
committed by GitHub
parent 9a4039680e
commit 8a9e018031
2 changed files with 60 additions and 1 deletions

View File

@@ -11,15 +11,21 @@ import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import org.example.petshopdesktop.Validator;
import org.example.petshopdesktop.api.dto.common.DropdownOption;
import org.example.petshopdesktop.api.dto.employee.EmployeeRequest;
import org.example.petshopdesktop.api.dto.employee.EmployeeResponse;
import org.example.petshopdesktop.api.endpoints.DropdownApi;
import org.example.petshopdesktop.api.endpoints.EmployeeApi;
import org.example.petshopdesktop.api.endpoints.UserApi;
import org.example.petshopdesktop.util.ActivityLogger;
import org.example.petshopdesktop.util.DesktopImageSupport;
import org.example.petshopdesktop.util.FilePickerSupport;
import org.example.petshopdesktop.util.TextFieldFormatSupport;
import java.io.File;
import java.util.List;
public class StaffRegisterDialogController {
@@ -38,6 +44,13 @@ public class StaffRegisterDialogController {
@FXML private Label lblError;
@FXML private Button btnCreate;
@FXML private ImageView imgAvatarPreview;
@FXML private Label lblAvatarStatus;
@FXML private Button btnChangeAvatar;
@FXML private Button btnRemoveAvatar;
private File selectedAvatarFile;
@FXML
void initialize() {
TextFieldFormatSupport.applyPhoneNumberFormat(txtPhone);
@@ -65,6 +78,10 @@ public class StaffRegisterDialogController {
}
});
btnChangeAvatar.setOnMouseClicked(e -> handleChangeAvatar());
btnRemoveAvatar.setOnMouseClicked(e -> handleRemoveAvatar());
btnRemoveAvatar.setDisable(true);
loadStores();
}
@@ -83,6 +100,22 @@ public class StaffRegisterDialogController {
}).start();
}
private void handleChangeAvatar() {
File file = FilePickerSupport.pickImageFile(btnCreate.getScene().getWindow());
if (file == null) return;
selectedAvatarFile = file;
lblAvatarStatus.setText("Selected: " + file.getName());
DesktopImageSupport.loadImageInto(imgAvatarPreview, file.toURI().toString(), 90, 90);
btnRemoveAvatar.setDisable(false);
}
private void handleRemoveAvatar() {
selectedAvatarFile = null;
imgAvatarPreview.setImage(null);
lblAvatarStatus.setText("No avatar");
btnRemoveAvatar.setDisable(true);
}
@FXML
void btnCreateClicked(ActionEvent event) {
lblError.setText("");
@@ -147,6 +180,7 @@ public class StaffRegisterDialogController {
String staffRole = cbStaffRole.getValue();
boolean active = "Active".equals(cbActive.getValue());
Long storeId = cbStore.getValue().getId();
File avatarFile = selectedAvatarFile;
new Thread(() -> {
try {
@@ -163,7 +197,14 @@ public class StaffRegisterDialogController {
request.setActive(active);
request.setPrimaryStoreId(storeId);
EmployeeApi.getInstance().createEmployee(request);
EmployeeResponse created = EmployeeApi.getInstance().createEmployee(request);
if (avatarFile != null && created.getUserId() != null) {
try {
UserApi.getInstance().uploadUserAvatar(created.getUserId(), avatarFile.toPath());
} catch (Exception ignored) {
}
}
Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.INFORMATION);