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

[Fix] Users Can Add Duplicate Employment Types #8587

Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit, OnDestroy, TemplateRef, ViewChild } from '@angular/core';
import { UntypedFormGroup, UntypedFormBuilder, Validators } from '@angular/forms';
import { UntypedFormGroup, UntypedFormBuilder, Validators, ValidationErrors, AbstractControl } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { LocalDataSource } from 'angular2-smart-table';
Expand Down Expand Up @@ -205,8 +205,16 @@ 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());

if (this.validateUniqueName(existingNames, name)) {
this.toastrService.error('NOTES.ORGANIZATIONS.EDIT_ORGANIZATIONS_EMPLOYMENT_TYPES.ALREADY_EXISTS', name);
return;
}

const newEmploymentType = {
name: this.form.get('name').value,
name,
organizationId: this.organization.id,
tenantId: this.organization.tenantId,
tags: this.tags
Expand Down Expand Up @@ -278,6 +286,15 @@ export class EmploymentTypesComponent extends PaginationFilterBaseComponent impl
}

async editOrgEmpType(id: string, name: string) {

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

if (this.validateUniqueName(existingNames, name.toLowerCase())) {
this.toastrService.error('NOTES.ORGANIZATIONS.EDIT_ORGANIZATIONS_EMPLOYMENT_TYPES.ALREADY_EXISTS', name );
return;
}
const orgEmpTypeForEdit = {
name: name,
tags: this.tags
Expand Down Expand Up @@ -330,4 +347,7 @@ 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());
}
}
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/ach.json
Original file line number Diff line number Diff line change
Expand Up @@ -3496,7 +3496,8 @@
"ADD_EMPLOYMENT_TYPE": "crwdns8984:0{{ name }}crwdne8984:0",
"UPDATE_EMPLOYMENT_TYPE": "crwdns8986:0{{ name }}crwdne8986:0",
"INVALID_EMPLOYMENT_TYPE": "crwdns3067:0crwdne3067:0",
"DELETE_EMPLOYMENT_TYPE": "crwdns8988:0{{ name }}crwdne8988:0"
"DELETE_EMPLOYMENT_TYPE": "crwdns8988:0{{ name }}crwdne8988:0",
"ALREADY_EXISTS": "Kit me jami me tic eni kiyero acel."
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "crwdns8990:0{{ name }}crwdne8990:0",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3752,7 +3752,8 @@
"ADD_EMPLOYMENT_TYPE": "تمت إضافة نوع التوظيف '{{ name }}'",
"UPDATE_EMPLOYMENT_TYPE": "تم تغيير نوع التوظيف '{{ name }}'",
"INVALID_EMPLOYMENT_TYPE": "يرجى التحقق من الاسم المدخل لنوع التوظيف",
"DELETE_EMPLOYMENT_TYPE": "تمت إزالة نوع الوظيفة '{{ name }}'"
"DELETE_EMPLOYMENT_TYPE": "تمت إزالة نوع الوظيفة '{{ name }}'",
"ALREADY_EXISTS": "هذا النوع من التوظيف موجود بالفعل."
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "تم إضافة مصروف متكرر لـ `{{ name }}`",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3803,7 +3803,8 @@
"ADD_EMPLOYMENT_TYPE": "Employment type '{{ name }}' was added",
"UPDATE_EMPLOYMENT_TYPE": "Employment type '{{ name }}' was changed",
"INVALID_EMPLOYMENT_TYPE": "Please check the Name for Employment type input",
"DELETE_EMPLOYMENT_TYPE": "Employment type '{{ name }}' was removed"
"DELETE_EMPLOYMENT_TYPE": "Employment type '{{ name }}' was removed",
"ALREADY_EXISTS": "Този вид заетост вече съществува."
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "Recurring expense was added for `{{ name }}`",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -3750,7 +3750,8 @@
"ADD_EMPLOYMENT_TYPE": "Beschäftigungsart '{{ name }}' wurde hinzugefügt.",
"UPDATE_EMPLOYMENT_TYPE": "Der Beschäftigungstyp '{{ name }}' wurde geändert.",
"INVALID_EMPLOYMENT_TYPE": "Bitte überprüfen Sie den Namen für die Eingabe zur Art der Beschäftigung.",
"DELETE_EMPLOYMENT_TYPE": "Beschäftigungsart '{{ name }}' wurde entfernt."
"DELETE_EMPLOYMENT_TYPE": "Beschäftigungsart '{{ name }}' wurde entfernt.",
"ALREADY_EXISTS": "Dieser Beschäftigungstyp existiert bereits."
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "Wiederkehrende Ausgabe wurde für `{{ name }}` hinzugefügt.",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3883,7 +3883,8 @@
"ADD_EMPLOYMENT_TYPE": "Employment type '{{ name }}' was added",
"UPDATE_EMPLOYMENT_TYPE": "Employment type '{{ name }}' was changed",
"INVALID_EMPLOYMENT_TYPE": "Please check the Name for Employment type input",
"DELETE_EMPLOYMENT_TYPE": "Employment type '{{ name }}' was removed"
"DELETE_EMPLOYMENT_TYPE": "Employment type '{{ name }}' was removed",
"ALREADY_EXISTS": "This employment type already exists."
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "Recurring expense was added for `{{ name }}`",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -3756,7 +3756,8 @@
"ADD_EMPLOYMENT_TYPE": "Se añadió el tipo de empleo '{{ name }}'.",
"UPDATE_EMPLOYMENT_TYPE": "El tipo de empleo '{{ name }}' fue cambiado.",
"INVALID_EMPLOYMENT_TYPE": "Por favor, verifica el nombre para el tipo de empleo ingresado.",
"DELETE_EMPLOYMENT_TYPE": "El tipo de empleo '{{ name }}' fue eliminado."
"DELETE_EMPLOYMENT_TYPE": "El tipo de empleo '{{ name }}' fue eliminado.",
"ALREADY_EXISTS": "Este tipo de empleo ya existe."
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "Se añadió un gasto recurrente para `{{ name }}`.",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3755,7 +3755,8 @@
"ADD_EMPLOYMENT_TYPE": "Le type d'emploi \"{{ name }}\" a été ajouté.",
"UPDATE_EMPLOYMENT_TYPE": "Le type d'emploi '{{ name }}' a été modifié.",
"INVALID_EMPLOYMENT_TYPE": "Veuillez vérifier le nom de l'entrée du type d'emploi.",
"DELETE_EMPLOYMENT_TYPE": "Le type d'emploi '{{ name }}' a été supprimé."
"DELETE_EMPLOYMENT_TYPE": "Le type d'emploi '{{ name }}' a été supprimé.",
"ALREADY_EXISTS": "Ce type d'emploi existe déjà."
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "La dépense récurrente a été ajoutée pour `{{ name }}`.",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -3767,7 +3767,8 @@
"ADD_EMPLOYMENT_TYPE": "Employment type '{{ name }}' was added",
"UPDATE_EMPLOYMENT_TYPE": "Employment type '{{ name }}' was changed",
"INVALID_EMPLOYMENT_TYPE": "Please check the Name for Employment type input",
"DELETE_EMPLOYMENT_TYPE": "Employment type '{{ name }}' was removed"
"DELETE_EMPLOYMENT_TYPE": "Employment type '{{ name }}' was removed",
"ALREADY_EXISTS": "סוג התעסוקה הזה כבר קיים."
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "Recurring expense was added for `{{ name }}`",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -3754,7 +3754,8 @@
"ADD_EMPLOYMENT_TYPE": "Il tipo di impiego '{{ name }}' è stato aggiunto",
"UPDATE_EMPLOYMENT_TYPE": "Il tipo di occupazione '{{ name }}' è stato cambiato",
"INVALID_EMPLOYMENT_TYPE": "Si prega di verificare il Nome per l'input del tipo di impiego",
"DELETE_EMPLOYMENT_TYPE": "Il tipo di impiego '{{ name }}' è stato rimosso"
"DELETE_EMPLOYMENT_TYPE": "Il tipo di impiego '{{ name }}' è stato rimosso",
"ALREADY_EXISTS": "Questo tipo di impiego esiste già."
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "La spesa ricorrente è stata aggiunta per `{{ name }}`",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -3754,7 +3754,8 @@
"ADD_EMPLOYMENT_TYPE": "Type dienstverband '{{ name }}' is toegevoegd",
"UPDATE_EMPLOYMENT_TYPE": "Werkgelegenheidstype '{{ name }}' is gewijzigd",
"INVALID_EMPLOYMENT_TYPE": "Controleer alstublieft de naam voor het invoerveld 'Type dienstverband'",
"DELETE_EMPLOYMENT_TYPE": "Dienstverbandtype '{{ name }}' is verwijderd"
"DELETE_EMPLOYMENT_TYPE": "Dienstverbandtype '{{ name }}' is verwijderd",
"ALREADY_EXISTS": "Dit type werk bestaat al."
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "Herhalende kosten werden toegevoegd voor `{{ name }}`.",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -3754,7 +3754,8 @@
"ADD_EMPLOYMENT_TYPE": "Typ zatrudnienia '{{ name }}' został dodany",
"UPDATE_EMPLOYMENT_TYPE": "Zmieniono rodzaj zatrudnienia na '{{ name }}'",
"INVALID_EMPLOYMENT_TYPE": "Proszę sprawdzić nazwę wprowadzoną w polu Rodzaj zatrudnienia",
"DELETE_EMPLOYMENT_TYPE": "Typ zatrudnienia '{{ name }}' został usunięty"
"DELETE_EMPLOYMENT_TYPE": "Typ zatrudnienia '{{ name }}' został usunięty",
"ALREADY_EXISTS": "Ten typ zatrudnienia już istnieje."
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "Powtarzający się wydatek został dodany dla `{{ name }}`",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -3754,7 +3754,8 @@
"ADD_EMPLOYMENT_TYPE": "O tipo de emprego '{{ name }}' foi adicionado.",
"UPDATE_EMPLOYMENT_TYPE": "O tipo de emprego '{{ name }}' foi alterado.",
"INVALID_EMPLOYMENT_TYPE": "Por favor, verifique o nome para a entrada do tipo de emprego.",
"DELETE_EMPLOYMENT_TYPE": "O tipo de emprego '{{ name }}' foi removido."
"DELETE_EMPLOYMENT_TYPE": "O tipo de emprego '{{ name }}' foi removido.",
"ALREADY_EXISTS": "Este tipo de emprego já existe."
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "A despesa recorrente foi adicionada para `{{ name }}`.",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -3773,7 +3773,8 @@
"ADD_EMPLOYMENT_TYPE": "Добавлен тип занятости '{{ name }}' '",
"UPDATE_EMPLOYMENT_TYPE": "Изменен тип занятости '{{ name }}' '",
"INVALID_EMPLOYMENT_TYPE": "Пожалуйста, проверьте входные данные по типу занятости",
"DELETE_EMPLOYMENT_TYPE": "Тип занятости '{{ name }}' ' был удален"
"DELETE_EMPLOYMENT_TYPE": "Тип занятости '{{ name }}' ' был удален",
"ALREADY_EXISTS": "Этот тип занятости уже существует."
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "Повторяющиеся расходы были добавлены для `{{ name }}`",
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-core/i18n/assets/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -3754,7 +3754,8 @@
"ADD_EMPLOYMENT_TYPE": "職業類型'{{ name }}'已被添加",
"UPDATE_EMPLOYMENT_TYPE": "雇佣类型“{{ name }}”已变更。",
"INVALID_EMPLOYMENT_TYPE": "请检查“雇佣类型”输入框中的名称。",
"DELETE_EMPLOYMENT_TYPE": "雇佣类型“{{ name }}”已被删除。"
"DELETE_EMPLOYMENT_TYPE": "雇佣类型“{{ name }}”已被删除。",
"ALREADY_EXISTS": "该就业类型已存在。"
},
"EDIT_ORGANIZATIONS_RECURRING_EXPENSES": {
"ADD_RECURRING_EXPENSE": "为 `{{ name }}` 添加了重复支出。",
Expand Down
Loading