avatar on staff register

This commit is contained in:
2026-04-15 16:06:09 -06:00
parent b4d31b13af
commit b5b529841b
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);

View File

@@ -6,6 +6,7 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.VBox?>
@@ -24,6 +25,23 @@
<Label fx:id="lblError" text="" textFill="#FF6B6B" wrapText="true" />
<HBox alignment="CENTER_LEFT" spacing="15.0">
<children>
<ImageView fx:id="imgAvatarPreview" fitHeight="90.0" fitWidth="90.0" pickOnBounds="true" preserveRatio="true" />
<VBox spacing="8.0">
<children>
<Label fx:id="lblAvatarStatus" text="No avatar" textFill="#2c3e50" />
<HBox spacing="8.0">
<children>
<Button fx:id="btnChangeAvatar" mnemonicParsing="false" text="Change Avatar" />
<Button fx:id="btnRemoveAvatar" mnemonicParsing="false" text="Remove Avatar" />
</children>
</HBox>
</children>
</VBox>
</children>
</HBox>
<HBox spacing="10.0">
<children>
<VBox spacing="6.0" HBox.hgrow="ALWAYS">