Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Convert user to employee feature for users page #8234

Merged
merged 6 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/gauzy/src/app/pages/users/users.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ <h4>
</ng-template>
</nb-card-body>
</nb-card>

<ng-template #actionButtons let-selectedItem="selectedItem">
<ng-template ngxPermissionsOnly="ORG_USERS_EDIT">
<div class="actions">
Expand All @@ -95,6 +96,16 @@ <h4>
>
<nb-icon class="mr-1" icon="edit-outline"></nb-icon>{{ 'BUTTONS.EDIT' | translate }}
</button>
<button
nbButton
[disabled]="(!selectedItem && disableButton) || isEmployee()"
(click)="convertUserToEmployee()"
status="basic"
class="action primary"
size="small"
>
<nb-icon class="mr-1" icon="person"></nb-icon> {{ 'BUTTONS.CONVERT_TO_EMPLOYEE' | translate }}
</button>
<button
nbButton
[disabled]="!selectedItem && disableButton"
Expand Down
61 changes: 59 additions & 2 deletions apps/gauzy/src/app/pages/users/users.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import { Cell, LocalDataSource } from 'angular2-smart-table';
import { filter, tap } from 'rxjs/operators';
import { debounceTime, firstValueFrom, Subject } from 'rxjs';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { ErrorHandlingService, Store, ToastrService, UsersOrganizationsService, monthNames } from '@gauzy/ui-core/core';
import {
EmployeesService,
ErrorHandlingService,
Store,
ToastrService,
UsersOrganizationsService,
monthNames
} from '@gauzy/ui-core/core';
import {
InvitationTypeEnum,
PermissionsEnum,
Expand Down Expand Up @@ -70,7 +77,8 @@ export class UsersComponent extends PaginationFilterBaseComponent implements OnI
private readonly errorHandlingService: ErrorHandlingService,
private readonly route: ActivatedRoute,
public readonly translateService: TranslateService,
private readonly userOrganizationsService: UsersOrganizationsService
private readonly userOrganizationsService: UsersOrganizationsService,
private readonly employeesService: EmployeesService
) {
super(translateService);
this.setView();
Expand Down Expand Up @@ -547,5 +555,54 @@ export class UsersComponent extends PaginationFilterBaseComponent implements OnI
return `${day} ${month} ${year}`;
}

/**
* Checks if the user is an employee.
*
* @param user The user to check.
* @returns True if the user is an employee, otherwise false.
*/
private isEmployee(): boolean {
return !!this.selectedUser.employeeId;
}

/**
* Converts a selected user to an employee on the users page.
*
* This method registers the selected user as an employee within the currently selected organization,
* provided the user hasn't already been registered as an employee.
*
* Preconditions:
* - A valid user must be selected.
* - The user must not already have an employee ID.
* - The organization details must be available.
*
* @throws {Error} Logs an error if the employee registration process fails.
*
* @returns {Promise<void>} Resolves when the user is successfully registered as an employee or does nothing if preconditions aren't met.
*/
async convertUserToEmployee(): Promise<void> {
if (!this.selectedUser || !this.organization || this.isEmployee()) {
return;
}

const { id: organizationId } = this.organization;
const { id: userId, tenantId } = this.selectedUser;

try {
await firstValueFrom(
this.employeesService.create({
startedWorkOn: null, // Default start date is null (can be updated later)
userId,
organizationId,
tenantId
})
);
this.toastrService.success('USERS_PAGE.CONVERT_USER_TO_EMPLOYEE');
} catch (error) {
console.error('Error while converting user to employee:', error);
this.toastrService.danger(error);
}
}

ngOnDestroy() {}
}
1 change: 1 addition & 0 deletions packages/contracts/src/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export enum ProviderEnum {
export interface IUserViewModel extends IBasePerTenantEntityModel {
fullName: string;
email: string;
employeeId?: ID;
bonus?: number;
endWork?: any;
id: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/ach.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"DELETE": "crwdns8:0crwdne8:0",
"REMOVE": "crwdns3152:0crwdne3152:0",
"ADD_EXISTING": "crwdns3154:0crwdne3154:0",
"CONVERT_TO_EMPLOYEE": "Toki ija kw'enja",
"OK": "crwdns10:0crwdne10:0",
"YES": "crwdns8012:0crwdne8012:0",
"NO": "crwdns8014:0crwdne8014:0",
Expand Down Expand Up @@ -2500,6 +2501,7 @@
"ADD_EXISTING_USER": "crwdns3158:0crwdne3158:0",
"ADD_EXISTING_ORGANIZATION": "crwdns8336:0crwdne8336:0",
"ADD_EXISTING_USER_TOOLTIP": "crwdns10813:0crwdne10813:0",
"CONVERT_USER_TO_EMPLOYEE": "Kijuko idano ija kw'enja pwod matye.",
"ROLE": {
"SUPER_ADMIN": "crwdns3448:0crwdne3448:0",
"ADMIN": "crwdns2317:0crwdne2317:0",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"DELETE": "حذف",
"REMOVE": "إزالة",
"ADD_EXISTING": "إضافة موجودة",
"CONVERT_TO_EMPLOYEE": "تحويل إلى موظف",
"OK": "حسنًا",
"YES": "نعم",
"NO": "لا.",
Expand Down Expand Up @@ -2703,6 +2704,7 @@
"ADD_EXISTING_USER": "إضافة مستخدم موجود",
"ADD_EXISTING_ORGANIZATION": "إضافة منظمة موجودة",
"ADD_EXISTING_USER_TOOLTIP": "إضافة مستخدم من مؤسسة أخرى",
"CONVERT_USER_TO_EMPLOYEE": "تم تحويل المستخدم إلى موظف بنجاح.",
"ROLE": {
"SUPER_ADMIN": "المشرف العام",
"ADMIN": "مشرف",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"DELETE": "Изтриване",
"REMOVE": "Премахване",
"ADD_EXISTING": "Добавяне на съществуващ",
"CONVERT_TO_EMPLOYEE": "Преобразуване в служител",
"OK": "Да",
"YES": "Да",
"NO": "Не",
Expand Down Expand Up @@ -2731,6 +2732,7 @@
"ADD_EXISTING_USER": "Add Existing User",
"ADD_EXISTING_ORGANIZATION": "Add Existing Organization",
"ADD_EXISTING_USER_TOOLTIP": "Add user from other organization",
"CONVERT_USER_TO_EMPLOYEE": "Потребителят беше успешно преобразуван в служител.",
"ROLE": {
"SUPER_ADMIN": "Super Admin",
"ADMIN": "Администратор",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"DELETE": "Löschen",
"REMOVE": "Entfernen",
"ADD_EXISTING": "Hinzufügen von vorhandenen",
"CONVERT_TO_EMPLOYEE": "Zu Mitarbeiter konvertieren",
"OK": "In Ordnung",
"YES": "Ja",
"NO": "Nein",
Expand Down Expand Up @@ -2701,6 +2702,7 @@
"ADD_EXISTING_USER": "Benutzer hinzufügen",
"ADD_EXISTING_ORGANIZATION": "Organisation hinzufügen",
"ADD_EXISTING_USER_TOOLTIP": "Benutzer von einer anderen Organisation hinzufügen",
"CONVERT_USER_TO_EMPLOYEE": "Benutzer erfolgreich zu Mitarbeiter konvertiert.",
"ROLE": {
"SUPER_ADMIN": "Super Admin",
"ADMIN": "Verwalter",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"DELETE": "Delete",
"REMOVE": "Remove",
"ADD_EXISTING": "Add Existing",
"CONVERT_TO_EMPLOYEE": "Convert to employee",
"OK": "Ok",
"YES": "Yes",
"NO": "No",
Expand Down Expand Up @@ -2828,6 +2829,7 @@
"ADD_EXISTING_USER": "Add Existing User",
"ADD_EXISTING_ORGANIZATION": "Add Existing Organization",
"ADD_EXISTING_USER_TOOLTIP": "Add user from other organization",
"CONVERT_USER_TO_EMPLOYEE": "User successfully converted to employee.",
"ROLE": {
"SUPER_ADMIN": "Super Admin",
"ADMIN": "Admin",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"DELETE": "Borrar",
"REMOVE": "Eliminar",
"ADD_EXISTING": "Agregar existente",
"CONVERT_TO_EMPLOYEE": "Convertir en empleado",
"OK": "Bien",
"YES": "Sí",
"NO": "No",
Expand Down Expand Up @@ -2707,6 +2708,7 @@
"ADD_EXISTING_USER": "Agregar usuario existente",
"ADD_EXISTING_ORGANIZATION": "Añadir organización existente",
"ADD_EXISTING_USER_TOOLTIP": "Agregar usuario de otra organización",
"CONVERT_USER_TO_EMPLOYEE": "Usuario convertido en empleado con éxito.",
"ROLE": {
"SUPER_ADMIN": "Super Administrador",
"ADMIN": "Administrador",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"DELETE": "Supprimer",
"REMOVE": "Supprimer",
"ADD_EXISTING": "Ajouter existant",
"CONVERT_TO_EMPLOYEE": "Convertir en employé",
"OK": "D'accord",
"YES": "Oui",
"NO": "Non",
Expand Down Expand Up @@ -2706,6 +2707,7 @@
"ADD_EXISTING_USER": "Ajouter un utilisateur existant",
"ADD_EXISTING_ORGANIZATION": "Ajouter une organisation existante",
"ADD_EXISTING_USER_TOOLTIP": "Ajouter un utilisateur provenant d'une autre organisation",
"CONVERT_USER_TO_EMPLOYEE": "Utilisateur converti en employé avec succès.",
"ROLE": {
"SUPER_ADMIN": "Super Administrateur",
"ADMIN": "Administrateur",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"DELETE": "מחק",
"REMOVE": "Remove",
"ADD_EXISTING": "Add Existing",
"CONVERT_TO_EMPLOYEE": "המרה לעובד",
"OK": "בסדר",
"YES": "Yes",
"NO": "No",
Expand Down Expand Up @@ -2723,6 +2724,7 @@
"ADD_EXISTING_USER": "Add Existing User",
"ADD_EXISTING_ORGANIZATION": "Add Existing Organization",
"ADD_EXISTING_USER_TOOLTIP": "Add user from other organization",
"CONVERT_USER_TO_EMPLOYEE": "המשתמש הומר בהצלחה לעובד.",
"ROLE": {
"SUPER_ADMIN": "Super Admin",
"ADMIN": "מנהל",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"DELETE": "Elimina",
"REMOVE": "Rimuovi",
"ADD_EXISTING": "Aggiungi esistente",
"CONVERT_TO_EMPLOYEE": "Converti in dipendente",
"OK": "Ok",
"YES": "Sì",
"NO": "Non",
Expand Down Expand Up @@ -2705,6 +2706,7 @@
"ADD_EXISTING_USER": "Aggiungi Utente Esistente",
"ADD_EXISTING_ORGANIZATION": "Aggiungi Organizzazione Esistente",
"ADD_EXISTING_USER_TOOLTIP": "Aggiungi utente da un'altra organizzazione",
"CONVERT_USER_TO_EMPLOYEE": "Utente convertito in dipendente con successo.",
"ROLE": {
"SUPER_ADMIN": "Super Admin",
"ADMIN": "Amministratore",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"DELETE": "Verwijderen",
"REMOVE": "Verwijderen",
"ADD_EXISTING": "Toevoegen bestaande",
"CONVERT_TO_EMPLOYEE": "Converteren naar werknemer",
"OK": "Ok",
"YES": "Ja",
"NO": "Nee",
Expand Down Expand Up @@ -2705,6 +2706,7 @@
"ADD_EXISTING_USER": "Voeg bestaande gebruiker toe",
"ADD_EXISTING_ORGANIZATION": "Voeg bestaande organisatie toe",
"ADD_EXISTING_USER_TOOLTIP": "Voeg gebruiker toe van andere organisatie",
"CONVERT_USER_TO_EMPLOYEE": "Gebruiker succesvol omgezet naar werknemer.",
"ROLE": {
"SUPER_ADMIN": "Super Admin",
"ADMIN": "Admin",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"DELETE": "Usuń",
"REMOVE": "Usuń",
"ADD_EXISTING": "Dodaj istniejący",
"CONVERT_TO_EMPLOYEE": "Konwertuj na pracownika",
"OK": "Ok",
"YES": "Tak",
"NO": "Nie",
Expand Down Expand Up @@ -2705,6 +2706,7 @@
"ADD_EXISTING_USER": "Dodaj istniejącego użytkownika",
"ADD_EXISTING_ORGANIZATION": "Dodaj istniejącą organizację",
"ADD_EXISTING_USER_TOOLTIP": "Dodaj użytkownika z innej organizacji",
"CONVERT_USER_TO_EMPLOYEE": "Użytkownik został pomyślnie przekonwertowany na pracownika.",
"ROLE": {
"SUPER_ADMIN": "Super Administrator",
"ADMIN": "Administrator",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"DELETE": "Excluir",
"REMOVE": "Remover",
"ADD_EXISTING": "Adicionar Existente",
"CONVERT_TO_EMPLOYEE": "Converter para funcionário",
"OK": "Ok",
"YES": "Sim.",
"NO": "Não.",
Expand Down Expand Up @@ -2705,6 +2706,7 @@
"ADD_EXISTING_USER": "Adicionar Usuário Existente",
"ADD_EXISTING_ORGANIZATION": "Adicionar organização existente",
"ADD_EXISTING_USER_TOOLTIP": "Adicionar usuário de outra organização",
"CONVERT_USER_TO_EMPLOYEE": "Usuário convertido com sucesso em funcionário.",
"ROLE": {
"SUPER_ADMIN": "Super Admin",
"ADMIN": "Administrador",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"DELETE": "Удалить",
"REMOVE": "Удалить",
"ADD_EXISTING": "Добавить существующий",
"CONVERT_TO_EMPLOYEE": "Преобразовать в сотрудника",
"OK": "Ок",
"YES": "Да",
"NO": "Нет",
Expand Down Expand Up @@ -2729,6 +2730,7 @@
"ADD_EXISTING_USER": "Добавить существующего пользователя",
"ADD_EXISTING_ORGANIZATION": "Добавить существующую организацию",
"ADD_EXISTING_USER_TOOLTIP": "Добавить пользователя из другой организации",
"CONVERT_USER_TO_EMPLOYEE": "Пользователь успешно преобразован в сотрудника.",
"ROLE": {
"SUPER_ADMIN": "Супер админ",
"ADMIN": "Администратор",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-core/i18n/assets/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"DELETE": "删除",
"REMOVE": "删除",
"ADD_EXISTING": "添加现有项目",
"CONVERT_TO_EMPLOYEE": "转换为员工",
"OK": "好的",
"YES": "是的",
"NO": "不",
Expand Down Expand Up @@ -2705,6 +2706,7 @@
"ADD_EXISTING_USER": "添加现有用户",
"ADD_EXISTING_ORGANIZATION": "添加现有组织",
"ADD_EXISTING_USER_TOOLTIP": "从其他组织添加用户",
"CONVERT_USER_TO_EMPLOYEE": "用户已成功转换为员工。",
"ROLE": {
"SUPER_ADMIN": "超级管理员",
"ADMIN": "管理员",
Expand Down
Loading