Skip to content

Commit

Permalink
Merge pull request #8591 from ever-co/fix/#8562-duplicate-employee-level
Browse files Browse the repository at this point in the history
[Fix] Users Can Add Duplicate Employee Level && Duplicate Positions
  • Loading branch information
rahul-rocket authored Dec 18, 2024
2 parents a57a8b5 + 5c48e4a commit 8772856
Show file tree
Hide file tree
Showing 18 changed files with 176 additions and 64 deletions.
28 changes: 16 additions & 12 deletions apps/gauzy/src/app/pages/departments/departments.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,17 @@ export class DepartmentsComponent extends PaginationFilterBaseComponent implemen

public async addOrEditDepartment(input: IOrganizationDepartmentCreateInput) {
if (input.name) {
const existingNames = this.departments
.filter((department) => !this.selectedDepartment || department.id !== this.selectedDepartment.id)
.map((department) => department.name);

if (validateUniqueString(existingNames, input.name)) {
this.toastrService.danger(
this.getTranslation('NOTES.ORGANIZATIONS.EDIT_ORGANIZATIONS_DEPARTMENTS.ALREADY_EXISTS'),
this.getTranslation('TOASTR.MESSAGE.DUPLICATE_DEPARTMENT_NAME')
);
return;
}
const existingNames = this.departments
.filter((department) => !this.selectedDepartment || department.id !== this.selectedDepartment.id)
.map((department) => department.name);

if (validateUniqueString(existingNames, input.name)) {
this.toastrService.danger(
this.getTranslation('NOTES.ORGANIZATIONS.EDIT_ORGANIZATIONS_DEPARTMENTS.ALREADY_EXISTS'),
input.name
);
return;
}

this.selectedDepartment
? await this.organizationDepartmentsService.update(this.selectedDepartment.id, input)
Expand Down Expand Up @@ -301,7 +300,11 @@ export class DepartmentsComponent extends PaginationFilterBaseComponent implemen
return department;
},
finalize: () => {
if (this._isGridLayout) this.departments.push(...this.smartTableSource.getData());
if (this._isGridLayout) {
this.departments.push(...this.smartTableSource.getData());
} else {
this.departments = this.smartTableSource.getData();
}
this.setPagination({
...this.getPagination(),
totalItems: this.smartTableSource.count()
Expand All @@ -323,6 +326,7 @@ export class DepartmentsComponent extends PaginationFilterBaseComponent implemen

if (this._isGridLayout) {
await this.smartTableSource.getElements();

this.setPagination({
...this.getPagination(),
totalItems: this.smartTableSource.count()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { debounceTime, firstValueFrom, Subject } from 'rxjs';
import { filter, tap } from 'rxjs/operators';
import { LocalDataSource } from 'angular2-smart-table';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { ComponentEnum, distinctUntilChange } from '@gauzy/ui-core/common';
import { ComponentEnum, distinctUntilChange, validateUniqueString } from '@gauzy/ui-core/common';
import {
PaginationFilterBaseComponent,
IPaginationBase,
Expand Down Expand Up @@ -172,7 +172,15 @@ export class EmployeeLevelComponent extends PaginationFilterBaseComponent implem
if (level) {
const { tenantId } = this.store.user;
const { id: organizationId } = this.organization;
const existingNames = this.employeeLevels.map((employeeLevel) => employeeLevel.level);

if (validateUniqueString(existingNames,level)) {
this.toastrService.danger(
this.getTranslation('NOTES.ORGANIZATIONS.EDIT_ORGANIZATIONS_EMPLOYEE_LEVELS.ALREADY_EXISTS'),
level
);
return;
}
await this.employeeLevelService.create({
level,
organizationId,
Expand All @@ -181,7 +189,7 @@ export class EmployeeLevelComponent extends PaginationFilterBaseComponent implem
});

this.toastrService.success('NOTES.ORGANIZATIONS.EDIT_ORGANIZATIONS_EMPLOYEE_LEVELS.ADD_EMPLOYEE_LEVEL', {
name: level
level
});
this._refresh$.next(true);
this.subject$.next(true);
Expand All @@ -197,6 +205,15 @@ export class EmployeeLevelComponent extends PaginationFilterBaseComponent implem
async editEmployeeLevel(id: string, employeeLevelName: string) {
const { tenantId } = this.store.user;
const { id: organizationId } = this.organization;
const existingNames = this.employeeLevels.map((employeeLevel) => employeeLevel.level);

if (validateUniqueString(existingNames,employeeLevelName)) {
this.toastrService.danger(
this.getTranslation('NOTES.ORGANIZATIONS.EDIT_ORGANIZATIONS_EMPLOYEE_LEVELS.ALREADY_EXISTS'),
employeeLevelName
);
return;
}

const employeeLevel = {
level: employeeLevelName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { takeUntil } from 'rxjs/operators';
import { NbDialogService } from '@nebular/theme';
import { OrganizationEmploymentTypesService, Store } from '@gauzy/ui-core/core';
import { ComponentEnum, distinctUntilChange } from '@gauzy/ui-core/common';
import { ComponentEnum, distinctUntilChange,validateUniqueString} from '@gauzy/ui-core/common';
import { Subject, firstValueFrom, filter, debounceTime, tap } from 'rxjs';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import {
Expand Down Expand Up @@ -206,9 +206,9 @@ export class EmploymentTypesComponent extends PaginationFilterBaseComponent impl
private async addEmploymentType() {
if (!this.form.invalid) {
const name: string = this.form.get('name').value;
const existingNames = this.organizationEmploymentTypes.map((type) => type.name.toLowerCase());
const existingNames = this.organizationEmploymentTypes.map((type) => type.name);

if (this.validateUniqueName(existingNames, name)) {
if (validateUniqueString(existingNames, name)) {
this.toastrService.error('NOTES.ORGANIZATIONS.EDIT_ORGANIZATIONS_EMPLOYMENT_TYPES.ALREADY_EXISTS', name);
return;
}
Expand Down Expand Up @@ -289,9 +289,9 @@ export class EmploymentTypesComponent extends PaginationFilterBaseComponent impl

const existingNames = this.organizationEmploymentTypes
.filter((type) => type.id !== id)
.map((type) => type.name.toLowerCase());
.map((type) => type.name);

if (this.validateUniqueName(existingNames, name.toLowerCase())) {
if (validateUniqueString(existingNames, name)) {
this.toastrService.error('NOTES.ORGANIZATIONS.EDIT_ORGANIZATIONS_EMPLOYMENT_TYPES.ALREADY_EXISTS', name );
return;
}
Expand Down Expand Up @@ -347,7 +347,5 @@ export class EmploymentTypesComponent extends PaginationFilterBaseComponent impl
this.selected.employmentType = orgEmpType;
this.selectedOrgEmpType = this.selected.employmentType;
}
validateUniqueName(existingNames: string[], value: string) {
return existingNames.includes(value.trim().toLowerCase());
}

}
25 changes: 24 additions & 1 deletion apps/gauzy/src/app/pages/positions/positions.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LocalDataSource } from 'angular2-smart-table';
import { firstValueFrom, filter, tap, Subject, debounceTime } from 'rxjs';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { OrganizationPositionsService, Store, ToastrService } from '@gauzy/ui-core/core';
import { ComponentEnum, distinctUntilChange } from '@gauzy/ui-core/common';
import { ComponentEnum, distinctUntilChange, validateUniqueString } from '@gauzy/ui-core/common';
import {
PaginationFilterBaseComponent,
IPaginationBase,
Expand Down Expand Up @@ -174,6 +174,19 @@ export class PositionsComponent extends PaginationFilterBaseComponent implements
if (!this.organization) {
return;
}

const existingNames = this.positions
.filter((position) => !this.selectedPosition || position.id !== this.selected.position.id)
.map((position) => position.name);

if (validateUniqueString(existingNames, name)) {
this.toastrService.danger(
this.getTranslation('NOTES.ORGANIZATIONS.EDIT_ORGANIZATIONS_POSITIONS.ALREADY_EXISTS'),
name
);
return;
}

const { id: organizationId } = this.organization;
const { tenantId } = this.store.user;

Expand All @@ -194,6 +207,16 @@ export class PositionsComponent extends PaginationFilterBaseComponent implements
if (!this.organization) {
return;
}
const existingNames = this.positions.map((position) => position.name);

if (validateUniqueString(existingNames, name)) {
this.toastrService.danger(
this.getTranslation('NOTES.ORGANIZATIONS.EDIT_ORGANIZATIONS_POSITIONS.ALREADY_EXISTS'),
name
);
return;
}

const { id: organizationId } = this.organization;
const { tenantId } = this.store.user;

Expand Down
11 changes: 8 additions & 3 deletions packages/ui-core/i18n/assets/i18n/ach.json
Original file line number Diff line number Diff line change
Expand Up @@ -3450,7 +3450,9 @@
"EDIT_ORGANIZATIONS_EMPLOYEE_LEVELS": {
"ADD_EMPLOYEE_LEVEL": "crwdns8950:0{{ name }}crwdne8950:0",
"REMOVE_EMPLOYEE_LEVEL": "crwdns8952:0{{ name }}crwdne8952:0",
"INVALID_EMPLOYEE_LEVEL": "crwdns3490:0crwdne3490:0"
"INVALID_EMPLOYEE_LEVEL": "crwdns3490:0crwdne3490:0",
"ALREADY_EXISTS": "Kombedi me Employee tye ka bino."

},
"EDIT_ORGANIZATIONS_VENDOR": {
"ADD_VENDOR": "crwdns8954:0{{ name }}crwdne8954:0",
Expand All @@ -3468,12 +3470,15 @@
"ADD_POSITION": "crwdns8966:0{{ name }}crwdne8966:0",
"UPDATED_POSITION": "crwdns8968:0{{ name }}crwdne8968:0",
"REMOVE_POSITION": "crwdns8970:0{{ name }}crwdne8970:0",
"INVALID_POSITION_NAME": "crwdns2825:0crwdne2825:0"
"INVALID_POSITION_NAME": "crwdns2825:0crwdne2825:0",
"ALREADY_EXISTS": "Kombedi me Position tye ka bino."

},
"EDIT_ORGANIZATIONS_DEPARTMENTS": {
"ADD_DEPARTMENT": "crwdns8972:0{{ name }}crwdne8972:0",
"REMOVE_DEPARTMENT": "crwdns8974:0{{ name }}crwdne8974:0",
"INVALID_DEPARTMENT_NAME": "crwdns2831:0crwdne2831:0"
"INVALID_DEPARTMENT_NAME": "crwdns2831:0crwdne2831:0",
"ALREADY_EXISTS": "Dyero me tye ka bino."
},
"EDIT_ORGANIZATIONS_CLIENTS": {
"ADD_CLIENT": "crwdns9896:0{{ name }}crwdne9896:0",
Expand Down
11 changes: 8 additions & 3 deletions packages/ui-core/i18n/assets/i18n/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3706,7 +3706,9 @@
"EDIT_ORGANIZATIONS_EMPLOYEE_LEVELS": {
"ADD_EMPLOYEE_LEVEL": "تمت إضافة مستوى الموظف '{{ name }}'",
"REMOVE_EMPLOYEE_LEVEL": "تمت إزالة مستوى الموظف '{{ name }}'",
"INVALID_EMPLOYEE_LEVEL": "يرجى إضافة مستوى الموظف"
"INVALID_EMPLOYEE_LEVEL": "يرجى إضافة مستوى الموظف",
"ALREADY_EXISTS": "المستوى الوظيفي موجود بالفعل."

},
"EDIT_ORGANIZATIONS_VENDOR": {
"ADD_VENDOR": "تمت إضافة المورد '{{ name }}'",
Expand All @@ -3724,12 +3726,15 @@
"ADD_POSITION": "تمت إضافة الموقع '{{ name }}'",
"UPDATED_POSITION": "تم تغيير الموقف '{{ name }}'",
"REMOVE_POSITION": "تم إزالة الوظيفة '{{ name }}'",
"INVALID_POSITION_NAME": "يرجى إضافة اسم المنصب"
"INVALID_POSITION_NAME": "يرجى إضافة اسم المنصب",
"ALREADY_EXISTS": "الوظيفة موجودة بالفعل."

},
"EDIT_ORGANIZATIONS_DEPARTMENTS": {
"ADD_DEPARTMENT": "تم حفظ القسم '{{ name }}'",
"REMOVE_DEPARTMENT": "تمت إزالة القسم '{{ name }}'",
"INVALID_DEPARTMENT_NAME": "يرجى إضافة اسم القسم"
"INVALID_DEPARTMENT_NAME": "يرجى إضافة اسم القسم",
"ALREADY_EXISTS": "القسم موجود بالفعل."
},
"EDIT_ORGANIZATIONS_CLIENTS": {
"ADD_CLIENT": "تمت إضافة العميل الجديد '{{ name }}' بنجاح!",
Expand Down
11 changes: 8 additions & 3 deletions packages/ui-core/i18n/assets/i18n/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3757,7 +3757,9 @@
"EDIT_ORGANIZATIONS_EMPLOYEE_LEVELS": {
"ADD_EMPLOYEE_LEVEL": "Employee Level '{{ name }}' was added",
"REMOVE_EMPLOYEE_LEVEL": "Employee Level '{{ name }}' was removed",
"INVALID_EMPLOYEE_LEVEL": "Please add an Employee Level"
"INVALID_EMPLOYEE_LEVEL": "Please add an Employee Level",
"ALREADY_EXISTS": "Нивото на служител вече съществува."

},
"EDIT_ORGANIZATIONS_VENDOR": {
"ADD_VENDOR": "vendor '{{ name }}' was added",
Expand All @@ -3775,12 +3777,15 @@
"ADD_POSITION": "Position '{{ name }}' was added",
"UPDATED_POSITION": "Position '{{ name }}' was changed",
"REMOVE_POSITION": "Position '{{ name }}' was removed",
"INVALID_POSITION_NAME": "Please add a Position name"
"INVALID_POSITION_NAME": "Please add a Position name",
"ALREADY_EXISTS": "Позицията вече съществува."

},
"EDIT_ORGANIZATIONS_DEPARTMENTS": {
"ADD_DEPARTMENT": "Department '{{ name }}' was saved",
"REMOVE_DEPARTMENT": "Department '{{ name }}' was removed",
"INVALID_DEPARTMENT_NAME": "Please add a Department name"
"INVALID_DEPARTMENT_NAME": "Please add a Department name",
"ALREADY_EXISTS": "Отделът вече съществува."
},
"EDIT_ORGANIZATIONS_CLIENTS": {
"ADD_CLIENT": "New client '{{ name }}' successfully added!",
Expand Down
11 changes: 8 additions & 3 deletions packages/ui-core/i18n/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -3704,7 +3704,9 @@
"EDIT_ORGANIZATIONS_EMPLOYEE_LEVELS": {
"ADD_EMPLOYEE_LEVEL": "Mitarbeiter-Stufe '{{ name }}' wurde hinzugefügt.",
"REMOVE_EMPLOYEE_LEVEL": "Der Mitarbeiter mit dem Level '{{ name }}' wurde entfernt.",
"INVALID_EMPLOYEE_LEVEL": "Bitte fügen Sie eine Mitarbeiterstufe hinzu."
"INVALID_EMPLOYEE_LEVEL": "Bitte fügen Sie eine Mitarbeiterstufe hinzu.",
"ALREADY_EXISTS": "Diese Mitarbeiterebene existiert bereits."

},
"EDIT_ORGANIZATIONS_VENDOR": {
"ADD_VENDOR": "Anbieter '{{ name }}' wurde hinzugefügt.",
Expand All @@ -3722,12 +3724,15 @@
"ADD_POSITION": "Die Position '{{ name }}' wurde hinzugefügt.",
"UPDATED_POSITION": "Die Position '{{ name }}' wurde geändert.",
"REMOVE_POSITION": "Die Position '{{ name }}' wurde entfernt.",
"INVALID_POSITION_NAME": "Bitte fügen Sie einen Positionsnamen hinzu."
"INVALID_POSITION_NAME": "Bitte fügen Sie einen Positionsnamen hinzu.",
"ALREADY_EXISTS": "Diese Position existiert bereits."

},
"EDIT_ORGANIZATIONS_DEPARTMENTS": {
"ADD_DEPARTMENT": "Das Department '{{ name }}' wurde gespeichert.",
"REMOVE_DEPARTMENT": "Abteilung '{{ name }}' wurde entfernt.",
"INVALID_DEPARTMENT_NAME": "Bitte fügen Sie einen Abteilungsnamen hinzu."
"INVALID_DEPARTMENT_NAME": "Bitte fügen Sie einen Abteilungsnamen hinzu.",
"ALREADY_EXISTS": "Diese Abteilung existiert bereits."
},
"EDIT_ORGANIZATIONS_CLIENTS": {
"ADD_CLIENT": "Neuer Kunde '{{ name }}' erfolgreich hinzugefügt!",
Expand Down
12 changes: 9 additions & 3 deletions packages/ui-core/i18n/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3837,7 +3837,10 @@
"EDIT_ORGANIZATIONS_EMPLOYEE_LEVELS": {
"ADD_EMPLOYEE_LEVEL": "Employee Level '{{ name }}' was added",
"REMOVE_EMPLOYEE_LEVEL": "Employee Level '{{ name }}' was removed",
"INVALID_EMPLOYEE_LEVEL": "Please add an Employee Level"
"INVALID_EMPLOYEE_LEVEL": "Please add an Employee Level",
"ALREADY_EXISTS": "This Employee Level already exists."


},
"EDIT_ORGANIZATIONS_VENDOR": {
"ADD_VENDOR": "vendor '{{ name }}' was added",
Expand All @@ -3855,12 +3858,15 @@
"ADD_POSITION": "Position '{{ name }}' was added",
"UPDATED_POSITION": "Position '{{ name }}' was changed",
"REMOVE_POSITION": "Position '{{ name }}' was removed",
"INVALID_POSITION_NAME": "Please add a Position name"
"INVALID_POSITION_NAME": "Please add a Position name",
"ALREADY_EXISTS": "This Position already exists."

},
"EDIT_ORGANIZATIONS_DEPARTMENTS": {
"ADD_DEPARTMENT": "Department '{{ name }}' was saved",
"REMOVE_DEPARTMENT": "Department '{{ name }}' was removed",
"INVALID_DEPARTMENT_NAME": "Please add a Department name"
"INVALID_DEPARTMENT_NAME": "Please add a Department name",
"ALREADY_EXISTS": "This Department already exists."
},
"EDIT_ORGANIZATIONS_CLIENTS": {
"ADD_CLIENT": "New client '{{ name }}' successfully added!",
Expand Down
11 changes: 8 additions & 3 deletions packages/ui-core/i18n/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -3710,7 +3710,9 @@
"EDIT_ORGANIZATIONS_EMPLOYEE_LEVELS": {
"ADD_EMPLOYEE_LEVEL": "Se agregó el nivel de empleado '{{ name }}'",
"REMOVE_EMPLOYEE_LEVEL": "El nivel de empleo '{{ name }}' fue eliminado.",
"INVALID_EMPLOYEE_LEVEL": "Por favor añadir un Nivel de Empleado."
"INVALID_EMPLOYEE_LEVEL": "Por favor añadir un Nivel de Empleado.",
"ALREADY_EXISTS": "Este nivel de empleado ya existe."

},
"EDIT_ORGANIZATIONS_VENDOR": {
"ADD_VENDOR": "El proveedor '{{ name }}' fue agregado.",
Expand All @@ -3728,12 +3730,15 @@
"ADD_POSITION": "La posición '{{ name }}' fue agregada",
"UPDATED_POSITION": "La posición '{{ name }}' ha sido cambiada.",
"REMOVE_POSITION": "La posición '{{ name }}' fue eliminada.",
"INVALID_POSITION_NAME": "Por favor, añade un nombre de posición"
"INVALID_POSITION_NAME": "Por favor, añade un nombre de posición",
"ALREADY_EXISTS": "Este puesto ya existe."

},
"EDIT_ORGANIZATIONS_DEPARTMENTS": {
"ADD_DEPARTMENT": "El departamento '{{ name }}' fue guardado.",
"REMOVE_DEPARTMENT": "El departamento '{{ name }}' fue eliminado.",
"INVALID_DEPARTMENT_NAME": "Por favor, agregue un nombre de departamento."
"INVALID_DEPARTMENT_NAME": "Por favor, agregue un nombre de departamento.",
"ALREADY_EXISTS": "Este departamento '{{ name }}' ya existe."
},
"EDIT_ORGANIZATIONS_CLIENTS": {
"ADD_CLIENT": "¡Nuevo cliente '{{name}}' agregado exitosamente!",
Expand Down
7 changes: 5 additions & 2 deletions packages/ui-core/i18n/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3727,12 +3727,15 @@
"ADD_POSITION": "La position '{{ name }}' a été ajoutée.",
"UPDATED_POSITION": "La position '{{ name }}' a été modifiée.",
"REMOVE_POSITION": "La position '{{ name }}' a été supprimée.",
"INVALID_POSITION_NAME": "Veuillez ajouter un nom de poste"
"INVALID_POSITION_NAME": "Veuillez ajouter un nom de poste",
"ALREADY_EXISTS": "La position existe déjà."

},
"EDIT_ORGANIZATIONS_DEPARTMENTS": {
"ADD_DEPARTMENT": "Le département '{{ name }}' a été enregistré.",
"REMOVE_DEPARTMENT": "Le département '{{ name }}' a été supprimé.",
"INVALID_DEPARTMENT_NAME": "Veuillez ajouter un nom de département."
"INVALID_DEPARTMENT_NAME": "Veuillez ajouter un nom de département.",
"ALREADY_EXISTS": "Ce département existe déjà."
},
"EDIT_ORGANIZATIONS_CLIENTS": {
"ADD_CLIENT": "Nouveau client '{{ name }}' ajouté avec succès !",
Expand Down
Loading

0 comments on commit 8772856

Please sign in to comment.