From 2efae49f2cb3a5ef5f212f048e759f0233778487 Mon Sep 17 00:00:00 2001 From: samuelmbabhazi Date: Thu, 19 Sep 2024 16:43:30 +0200 Subject: [PATCH 1/6] Feature: Convert user to employee feature for users page --- .../src/app/pages/users/users.component.html | 14 +++++++ .../src/app/pages/users/users.component.ts | 39 ++++++++++++++++++- packages/contracts/src/user.model.ts | 1 + 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/apps/gauzy/src/app/pages/users/users.component.html b/apps/gauzy/src/app/pages/users/users.component.html index 98dcd1c6499..73bcef289e5 100644 --- a/apps/gauzy/src/app/pages/users/users.component.html +++ b/apps/gauzy/src/app/pages/users/users.component.html @@ -30,6 +30,20 @@

[isDisable]="disableButton" > + + + + + diff --git a/apps/gauzy/src/app/pages/users/users.component.ts b/apps/gauzy/src/app/pages/users/users.component.ts index 2ee1717aa08..ca09c7c70d3 100644 --- a/apps/gauzy/src/app/pages/users/users.component.ts +++ b/apps/gauzy/src/app/pages/users/users.component.ts @@ -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, @@ -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(); @@ -547,5 +555,32 @@ export class UsersComponent extends PaginationFilterBaseComponent implements OnI return `${day} ${month} ${year}`; } + /** + * Registers the user as an employee during the initial onboarding process. + * + * @param {IOrganizationCreateInput} organization - The organization input data required for registration. + * @param {IOrganization} createdOrganization - The created organization entity. + */ + async registerEmployeeFeature(): Promise { + if (!this.selectedUser || !this.organization || this.selectedUser.employeeId) { + return; + } + + const { id: organizationId } = this.organization; + const { id: userId, tenantId } = this.selectedUser; + + try { + await firstValueFrom( + this.employeesService.create({ + startedWorkOn: null, + userId, + organizationId, + tenantId + }) + ); + } catch (error) { + console.error('Error while registering employee:', error); + } + } ngOnDestroy() {} } diff --git a/packages/contracts/src/user.model.ts b/packages/contracts/src/user.model.ts index 61c6a544e1a..c0c876af008 100644 --- a/packages/contracts/src/user.model.ts +++ b/packages/contracts/src/user.model.ts @@ -227,6 +227,7 @@ export enum ProviderEnum { export interface IUserViewModel extends IBasePerTenantEntityModel { fullName: string; email: string; + employeeId?: string; bonus?: number; endWork?: any; id: string; From f9b64abf9f10247758df0d57d1111a36db4984a7 Mon Sep 17 00:00:00 2001 From: samuelmbabhazi Date: Thu, 19 Sep 2024 17:07:56 +0200 Subject: [PATCH 2/6] Feature: Convert user to employee feature for users page --- .../src/app/pages/users/users.component.html | 2 +- .../src/app/pages/users/users.component.ts | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/apps/gauzy/src/app/pages/users/users.component.html b/apps/gauzy/src/app/pages/users/users.component.html index 73bcef289e5..40127ecc1ac 100644 --- a/apps/gauzy/src/app/pages/users/users.component.html +++ b/apps/gauzy/src/app/pages/users/users.component.html @@ -38,7 +38,7 @@

size="small" *ngIf="organizationInvitesAllowed" status="primary" - (click)="registerEmployeeFeature()" + (click)="convertUserToEmployee()" > Convert to employee diff --git a/apps/gauzy/src/app/pages/users/users.component.ts b/apps/gauzy/src/app/pages/users/users.component.ts index ca09c7c70d3..a9ff3b2003a 100644 --- a/apps/gauzy/src/app/pages/users/users.component.ts +++ b/apps/gauzy/src/app/pages/users/users.component.ts @@ -556,12 +556,21 @@ export class UsersComponent extends PaginationFilterBaseComponent implements OnI } /** - * Registers the user as an employee during the initial onboarding process. + * Converts a selected user to an employee on the users page. * - * @param {IOrganizationCreateInput} organization - The organization input data required for registration. - * @param {IOrganization} createdOrganization - The created organization entity. + * 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} Resolves when the user is successfully registered as an employee or does nothing if preconditions aren't met. */ - async registerEmployeeFeature(): Promise { + async convertUserToEmployee(): Promise { if (!this.selectedUser || !this.organization || this.selectedUser.employeeId) { return; } @@ -572,15 +581,18 @@ export class UsersComponent extends PaginationFilterBaseComponent implements OnI try { await firstValueFrom( this.employeesService.create({ - startedWorkOn: null, + startedWorkOn: null, // Default start date is null (can be updated later) userId, organizationId, tenantId }) ); + this.toastrService.success('User successfully converted to employee.'); } catch (error) { - console.error('Error while registering employee:', error); + console.error('Error while converting user to employee:', error); + this.toastrService.danger(error); } } + ngOnDestroy() {} } From cef9f8d5402ce965ace6d7887de338412be9ca9f Mon Sep 17 00:00:00 2001 From: samuelmbabhazi Date: Fri, 20 Sep 2024 13:39:58 +0200 Subject: [PATCH 3/6] onvert user to employee --- .../src/app/pages/users/users.component.html | 24 ++++++++----------- .../src/app/pages/users/users.component.ts | 2 +- packages/ui-core/i18n/assets/i18n/ach.json | 2 ++ packages/ui-core/i18n/assets/i18n/ar.json | 2 ++ packages/ui-core/i18n/assets/i18n/bg.json | 2 ++ packages/ui-core/i18n/assets/i18n/de.json | 2 ++ packages/ui-core/i18n/assets/i18n/en.json | 2 ++ packages/ui-core/i18n/assets/i18n/es.json | 2 ++ packages/ui-core/i18n/assets/i18n/fr.json | 2 ++ packages/ui-core/i18n/assets/i18n/he.json | 2 ++ packages/ui-core/i18n/assets/i18n/it.json | 2 ++ packages/ui-core/i18n/assets/i18n/nl.json | 2 ++ packages/ui-core/i18n/assets/i18n/pl.json | 2 ++ packages/ui-core/i18n/assets/i18n/pt.json | 2 ++ packages/ui-core/i18n/assets/i18n/ru.json | 2 ++ packages/ui-core/i18n/assets/i18n/zh.json | 2 ++ 16 files changed, 39 insertions(+), 15 deletions(-) diff --git a/apps/gauzy/src/app/pages/users/users.component.html b/apps/gauzy/src/app/pages/users/users.component.html index 40127ecc1ac..6b6f7308ad7 100644 --- a/apps/gauzy/src/app/pages/users/users.component.html +++ b/apps/gauzy/src/app/pages/users/users.component.html @@ -30,20 +30,6 @@

[isDisable]="disableButton" > - - - - - @@ -109,6 +95,16 @@

> {{ 'BUTTONS.EDIT' | translate }} +