diff --git a/packages/ui-core/i18n/assets/i18n/ach.json b/packages/ui-core/i18n/assets/i18n/ach.json index 64cac49e793..925010691ca 100644 --- a/packages/ui-core/i18n/assets/i18n/ach.json +++ b/packages/ui-core/i18n/assets/i18n/ach.json @@ -3349,7 +3349,10 @@ "TIME_LOG_DELETED": "crwdns11014:0{{ name }}crwdnd11014:0{{ organization }}crwdne11014:0", "TIME_LOGS_DELETED": "crwdns11016:0{{ organization }}crwdne11016:0", "BUCKET_CREATED": "crwdns10996:0{{ bucket }}crwdnd10996:0{{ region }}crwdne10996:0", - "AUTHORIZED_TO_WORK": "crwdns11529:0{{ name }}crwdne11529:0" + "AUTHORIZED_TO_WORK": "crwdns11529:0{{ name }}crwdne11529:0", + "MODULE_CREATED": "Module neno kibalo niber.", + "MODULE_UPDATED": "Module neno me kicari maber.", + "MODULE_SAVE_ERROR": "Kwero module ma neno opire." } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/i18n/assets/i18n/ar.json b/packages/ui-core/i18n/assets/i18n/ar.json index d53b6c7d219..23f1c90c34c 100644 --- a/packages/ui-core/i18n/assets/i18n/ar.json +++ b/packages/ui-core/i18n/assets/i18n/ar.json @@ -3605,7 +3605,10 @@ "AUTHORIZED_TO_WORK": "{{ name }} مصرح له بالعمل", "EMAIL_VERIFICATION_NOT_VALID": "عذراً، رابط التحقق هذا غير صالح.", "EMAIL_VERIFICATION_VALID": "تهانينا! تم التحقق الآن من عنوان بريدك الإلكتروني.", - "SCREEN_CAPTURE_CHANGED": "تم تغيير حالة التقاط الشاشة لـ {{ name }}" + "SCREEN_CAPTURE_CHANGED": "تم تغيير حالة التقاط الشاشة لـ {{ name }}", + "MODULE_CREATED": "تم إنشاء الوحدة بنجاح!", + "MODULE_UPDATED": "تم تحديث الوحدة بنجاح!", + "MODULE_SAVE_ERROR": "فشل في حفظ الوحدة. حاول مرة أخرى." } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/i18n/assets/i18n/bg.json b/packages/ui-core/i18n/assets/i18n/bg.json index fec3bca195e..bbcacbfb3ef 100644 --- a/packages/ui-core/i18n/assets/i18n/bg.json +++ b/packages/ui-core/i18n/assets/i18n/bg.json @@ -3656,7 +3656,10 @@ "TIME_LOG_DELETED": "Времевият запис за '{{ name }}' беше премахнат от '{{ organization }}'", "TIME_LOGS_DELETED": "Времевите записи бяха премахнати от '{{ organization }}'", "BUCKET_CREATED": "'{{ bucket }}' за '{{ region }}' беше успешно създаден", - "AUTHORIZED_TO_WORK": "{{ name }} има право да работи" + "AUTHORIZED_TO_WORK": "{{ name }} има право да работи", + "MODULE_CREATED": "Модулът е създаден успешно!", + "MODULE_UPDATED": "Модулът е актуализиран успешно!", + "MODULE_SAVE_ERROR": "Неуспешно записване на модула. Моля, опитайте отново." } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/i18n/assets/i18n/de.json b/packages/ui-core/i18n/assets/i18n/de.json index 337d6f9125c..02d48f0e288 100644 --- a/packages/ui-core/i18n/assets/i18n/de.json +++ b/packages/ui-core/i18n/assets/i18n/de.json @@ -3603,7 +3603,10 @@ "AUTHORIZED_TO_WORK": "{{ name }} ist berechtigt zu arbeiten.", "EMAIL_VERIFICATION_NOT_VALID": "Entschuldigung, dieser Bestätigungslink ist ungültig.", "EMAIL_VERIFICATION_VALID": "Herzlichen Glückwunsch! Deine E-Mail ist jetzt verifiziert.", - "SCREEN_CAPTURE_CHANGED": "Bildschirmaufnahme-Status geändert für {{ name }}" + "SCREEN_CAPTURE_CHANGED": "Bildschirmaufnahme-Status geändert für {{ name }}", + "MODULE_CREATED": "Modul erfolgreich erstellt!", + "MODULE_UPDATED": "Modul erfolgreich aktualisiert!", + "MODULE_SAVE_ERROR": "Das Speichern des Moduls ist fehlgeschlagen. Bitte versuchen Sie es erneut." } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/i18n/assets/i18n/en.json b/packages/ui-core/i18n/assets/i18n/en.json index 7c280dd460e..764283815c0 100644 --- a/packages/ui-core/i18n/assets/i18n/en.json +++ b/packages/ui-core/i18n/assets/i18n/en.json @@ -3734,7 +3734,10 @@ "AUTHORIZED_TO_WORK": "{{ name }} is authorized to work", "EMAIL_VERIFICATION_NOT_VALID": "Sorry, this verification link is not valid.", "EMAIL_VERIFICATION_VALID": "Congrats! Your email is now verified.", - "SCREEN_CAPTURE_CHANGED": "Screen capture status changed for {{ name }}" + "SCREEN_CAPTURE_CHANGED": "Screen capture status changed for {{ name }}", + "MODULE_CREATED": "Module created successfully!", + "MODULE_UPDATED": "Module updated successfully!", + "MODULE_SAVE_ERROR": "Failed to save the module. Please try again." } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/i18n/assets/i18n/es.json b/packages/ui-core/i18n/assets/i18n/es.json index 6298e707c88..213dc070798 100644 --- a/packages/ui-core/i18n/assets/i18n/es.json +++ b/packages/ui-core/i18n/assets/i18n/es.json @@ -3609,7 +3609,10 @@ "AUTHORIZED_TO_WORK": "{{ name }} está autorizado para trabajar.", "EMAIL_VERIFICATION_NOT_VALID": "Disculpa, este enlace de verificación no es válido.", "EMAIL_VERIFICATION_VALID": "¡Felicidades! Tu correo electrónico ahora está verificado.", - "SCREEN_CAPTURE_CHANGED": "Estado del capturador de pantalla cambiado para {{ name }}" + "SCREEN_CAPTURE_CHANGED": "Estado del capturador de pantalla cambiado para {{ name }}", + "MODULE_CREATED": "¡Módulo creado con éxito!", + "MODULE_UPDATED": "¡Módulo actualizado con éxito!", + "MODULE_SAVE_ERROR": "Error al guardar el módulo. Por favor, inténtelo de nuevo." } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/i18n/assets/i18n/fr.json b/packages/ui-core/i18n/assets/i18n/fr.json index 7b2abddf2e1..75113c10131 100644 --- a/packages/ui-core/i18n/assets/i18n/fr.json +++ b/packages/ui-core/i18n/assets/i18n/fr.json @@ -3608,7 +3608,10 @@ "AUTHORIZED_TO_WORK": "{{ name }} est autorisé à travailler.", "EMAIL_VERIFICATION_NOT_VALID": "Désolé, ce lien de vérification n'est pas valide.", "EMAIL_VERIFICATION_VALID": "Félicitations ! Votre adresse e-mail est désormais vérifiée.", - "SCREEN_CAPTURE_CHANGED": "Statut de capture d'écran modifié pour {{ name }}." + "SCREEN_CAPTURE_CHANGED": "Statut de capture d'écran modifié pour {{ name }}.", + "MODULE_CREATED": "Module créé avec succès !", + "MODULE_UPDATED": "Module mis à jour avec succès !", + "MODULE_SAVE_ERROR": "Échec de l'enregistrement du module. Veuillez réessayer." } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/i18n/assets/i18n/he.json b/packages/ui-core/i18n/assets/i18n/he.json index 217f75e862f..0ec851a9a4c 100644 --- a/packages/ui-core/i18n/assets/i18n/he.json +++ b/packages/ui-core/i18n/assets/i18n/he.json @@ -3620,7 +3620,10 @@ "TIME_LOG_DELETED": "Time log for '{{ name }}' removed from '{{ organization }}'", "TIME_LOGS_DELETED": "Time logs removed from '{{ organization }}'", "BUCKET_CREATED": "'{{ bucket }}' for '{{ region }}' has been created successfully", - "AUTHORIZED_TO_WORK": "{{ name }} is authorized to work" + "AUTHORIZED_TO_WORK": "{{ name }} is authorized to work", + "MODULE_CREATED": "המודול נוצר בהצלחה!", + "MODULE_UPDATED": "המודול עודכן בהצלחה!", + "MODULE_SAVE_ERROR": "שמירת המודול נכשלה. אנא נסה שוב." } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/i18n/assets/i18n/it.json b/packages/ui-core/i18n/assets/i18n/it.json index 4df668ef4ff..9d06aa7282b 100644 --- a/packages/ui-core/i18n/assets/i18n/it.json +++ b/packages/ui-core/i18n/assets/i18n/it.json @@ -3607,7 +3607,10 @@ "AUTHORIZED_TO_WORK": "{{ name }} è autorizzato a lavorare", "EMAIL_VERIFICATION_NOT_VALID": "Mi dispiace, questo link di verifica non è valido", "EMAIL_VERIFICATION_VALID": "Congratulazioni! La tua email è ora verificata", - "SCREEN_CAPTURE_CHANGED": "Stato cattura schermo modificato per {{ name }}" + "SCREEN_CAPTURE_CHANGED": "Stato cattura schermo modificato per {{ name }}", + "MODULE_CREATED": "Modulo creato con successo!", + "MODULE_UPDATED": "Modulo aggiornato con successo!", + "MODULE_SAVE_ERROR": "Salvataggio del modulo non riuscito. Riprova." } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/i18n/assets/i18n/nl.json b/packages/ui-core/i18n/assets/i18n/nl.json index d45933eb4bb..5446cbf880e 100644 --- a/packages/ui-core/i18n/assets/i18n/nl.json +++ b/packages/ui-core/i18n/assets/i18n/nl.json @@ -3607,7 +3607,10 @@ "AUTHORIZED_TO_WORK": "{{ name }} is gemachtigd om te werken", "EMAIL_VERIFICATION_NOT_VALID": "Sorry, deze verificatielink is niet geldig.", "EMAIL_VERIFICATION_VALID": "Gefeliciteerd! Uw e-mail is nu geverifieerd.", - "SCREEN_CAPTURE_CHANGED": "Schermopnamestatus gewijzigd voor {{ name }}" + "SCREEN_CAPTURE_CHANGED": "Schermopnamestatus gewijzigd voor {{ name }}", + "MODULE_CREATED": "Module succesvol aangemaakt!", + "MODULE_UPDATED": "Module succesvol bijgewerkt!", + "MODULE_SAVE_ERROR": "Het opslaan van de module is mislukt. Probeer het opnieuw." } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/i18n/assets/i18n/pl.json b/packages/ui-core/i18n/assets/i18n/pl.json index 482d6bacde0..2966d02adb6 100644 --- a/packages/ui-core/i18n/assets/i18n/pl.json +++ b/packages/ui-core/i18n/assets/i18n/pl.json @@ -3607,7 +3607,10 @@ "AUTHORIZED_TO_WORK": "{{ name }} jest uprawniony do pracy", "EMAIL_VERIFICATION_NOT_VALID": "Przepraszam, ten link weryfikacyjny jest nieważny", "EMAIL_VERIFICATION_VALID": "Gratulacje! Twój email został teraz zweryfikowany", - "SCREEN_CAPTURE_CHANGED": "Zmieniono stan zrzutu ekranu dla {{ name }}" + "SCREEN_CAPTURE_CHANGED": "Zmieniono stan zrzutu ekranu dla {{ name }}", + "MODULE_CREATED": "Moduł został pomyślnie utworzony!", + "MODULE_UPDATED": "Moduł został pomyślnie zaktualizowany!", + "MODULE_SAVE_ERROR": "Nie udało się zapisać modułu. Spróbuj ponownie." } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/i18n/assets/i18n/pt.json b/packages/ui-core/i18n/assets/i18n/pt.json index 82a01577f4a..a0e306c8f0c 100644 --- a/packages/ui-core/i18n/assets/i18n/pt.json +++ b/packages/ui-core/i18n/assets/i18n/pt.json @@ -3607,7 +3607,10 @@ "AUTHORIZED_TO_WORK": "{{ name }} está autorizado a trabalhar", "EMAIL_VERIFICATION_NOT_VALID": "Desculpe, esse link de verificação não é válido.", "EMAIL_VERIFICATION_VALID": "Parabéns! Seu email foi verificado com sucesso.", - "SCREEN_CAPTURE_CHANGED": "Status de captura de tela alterado para {{ name }}" + "SCREEN_CAPTURE_CHANGED": "Status de captura de tela alterado para {{ name }}", + "MODULE_CREATED": "Módulo criado com sucesso!", + "MODULE_UPDATED": "Módulo atualizado com sucesso!", + "MODULE_SAVE_ERROR": "Falha ao salvar o módulo. Por favor, tente novamente." } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/i18n/assets/i18n/ru.json b/packages/ui-core/i18n/assets/i18n/ru.json index 779ac860c78..91d08762ef3 100644 --- a/packages/ui-core/i18n/assets/i18n/ru.json +++ b/packages/ui-core/i18n/assets/i18n/ru.json @@ -3626,7 +3626,10 @@ "TIME_LOG_DELETED": "Журнал времени для '{{ name }}' ' удален из '{{ organization }}'", "TIME_LOGS_DELETED": "Журналы времени удалены из '{{ organization }}'", "BUCKET_CREATED": "'{{ bucket }}' для '{{ region }}' был успешно создан", - "AUTHORIZED_TO_WORK": "{{ name }} авторизован для работы" + "AUTHORIZED_TO_WORK": "{{ name }} авторизован для работы", + "MODULE_CREATED": "Модуль успешно создан!", + "MODULE_UPDATED": "Модуль успешно обновлен!", + "MODULE_SAVE_ERROR": "Не удалось сохранить модуль. Попробуйте еще раз." } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/i18n/assets/i18n/zh.json b/packages/ui-core/i18n/assets/i18n/zh.json index f758db31e50..6bae61c17d6 100644 --- a/packages/ui-core/i18n/assets/i18n/zh.json +++ b/packages/ui-core/i18n/assets/i18n/zh.json @@ -3607,7 +3607,10 @@ "AUTHORIZED_TO_WORK": "{{ name }} 被授权工作。", "EMAIL_VERIFICATION_NOT_VALID": "对不起,该验证链接无效。", "EMAIL_VERIFICATION_VALID": "恭喜!您的电子邮件已经验证成功。", - "SCREEN_CAPTURE_CHANGED": "屏幕截图状态已更改为{{ name }}。" + "SCREEN_CAPTURE_CHANGED": "屏幕截图状态已更改为{{ name }}。", + "MODULE_CREATED": "模块创建成功!", + "MODULE_UPDATED": "模块更新成功!", + "MODULE_SAVE_ERROR": "模块保存失败。请再试一次。" } }, "ACCEPT_INVITE": { diff --git a/packages/ui-core/shared/src/lib/project/project-module/add-project-module-dialog/add-project-module-dialog.component.ts b/packages/ui-core/shared/src/lib/project/project-module/add-project-module-dialog/add-project-module-dialog.component.ts index 5660831c864..b7cf2dae26d 100644 --- a/packages/ui-core/shared/src/lib/project/project-module/add-project-module-dialog/add-project-module-dialog.component.ts +++ b/packages/ui-core/shared/src/lib/project/project-module/add-project-module-dialog/add-project-module-dialog.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnInit } from '@angular/core'; +import { Component,Input, OnInit} from '@angular/core'; import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; import { NbDialogRef } from '@nebular/theme'; import { TranslateService } from '@ngx-translate/core'; @@ -27,7 +27,8 @@ import { Store, OrganizationProjectModuleService, SprintService, - TasksService + TasksService, + ToastrService } from '@gauzy/ui-core/core'; import { richTextCKEditorConfig } from '../../../ckeditor.config'; @@ -96,7 +97,8 @@ export class AddProjectModuleDialogComponent extends TranslationBaseComponent im private organizationTeamsService: OrganizationTeamsService, private organizationProjectModuleService: OrganizationProjectModuleService, private organizationSprintService: SprintService, - private readonly tasksService: TasksService + private readonly tasksService: TasksService, + private readonly toastrService: ToastrService ) { super(translateService); } @@ -116,27 +118,46 @@ export class AddProjectModuleDialogComponent extends TranslationBaseComponent im * Populates form fields with data from an existing project module. * @param module - The selected project module data. */ - private populateForm(module: IOrganizationProjectModule) { + private populateForm(module: IOrganizationProjectModule): void { if (!module) return; + + const { + name, + description, + status, + startDate, + endDate, + isFavorite, + projectId, + parentId, + managerId, + members = [], + organizationSprints, + teams = [], + tasks = [] + } = module; + this.form.patchValue({ - name: module.name, - description: module.description, - status: module.status, - startDate: module.startDate, - endDate: module.endDate, - isFavorite: module.isFavorite, - projectId: module.projectId, - parentId: module.parentId, - managerId: module.managerId, - members: (module.members || [])?.map((m) => m.id), - organizationSprints: module.organizationSprints, - teams: (module.teams || [])?.map((t) => t.id), - tasks: (module.tasks || [])?.map((task) => task.id) + name, + description, + status, + startDate, + endDate, + isFavorite, + projectId, + parentId, + managerId, + members: members.map((m) => m.id), + organizationSprints, + teams: teams.map((t) => t.id), + tasks: tasks.map((task) => task.id), }); - this.selectedMembers = module.members?.map((m) => m.id); - this.selectedTeams = module.teams?.map((t) => t.id); + + this.selectedMembers = members.map((m) => m.id); + this.selectedTeams = teams.map((t) => t.id); } + /** * Validates and saves the form data to create or update the project module. */ @@ -149,39 +170,69 @@ export class AddProjectModuleDialogComponent extends TranslationBaseComponent im * Creates a new project module or updates the existing module based on form data. */ private async createOrUpdateModule() { - const organizationId = this.organization.id; - - this.form.get('members').setValue( - (this.selectedMembers || []).map((id) => this.employees.find((e) => e.id === id)).filter((e) => !!e) // Only valid employees - ); + try { + // Update form fields with valid members, teams, and tasks + this.updateFormFields(); + + // Prepare form values + const formValue = { + ...this.form.value, + organizationId: this.organization.id, + organization: this.organization + }; + + let module: IOrganizationProjectModule; + + // Determine if we are creating or updating a module + if (this.createModule) { + module = await firstValueFrom(this.organizationProjectModuleService.create(formValue)); + this.toastrService.success( + this.translateService.instant('TOASTR.MESSAGE.MODULE_CREATED'), + this.translateService.instant('TOASTR.TITLE.SUCCESS') + ); + } else { + module = await firstValueFrom( + this.organizationProjectModuleService.update(this.projectModule.id, formValue) + ); + this.toastrService.success( + this.translateService.instant('TOASTR.MESSAGE.MODULE_UPDATED'), + this.translateService.instant('TOASTR.TITLE.SUCCESS') + ); + } - this.form.get('teams').setValue( - (this.selectedTeams || []).map((id) => this.teams.find((e) => e.id === id)).filter((e) => !!e) // Only valid teams - ); + // Close the dialog and return the created/updated module + this.dialogRef.close(module); + } catch (error) { + // Display an error toast + this.toastrService.danger( + this.translateService.instant('TOASTR.MESSAGE.MODULE_SAVE_ERROR'), + this.translateService.instant('TOASTR.TITLE.ERROR') + ); + console.error('Failed to save module:', error); + } + } - this.form.get('tasks').setValue( - (this.form.get('tasks').value || []).map((id) => this.tasks.find((e) => e.id === id)).filter((e) => !!e) // Only valid teams - ); + /** + * Updates form fields with valid members, teams, and tasks. + */ + private updateFormFields() { + this.form + .get('members') + .setValue( + (this.selectedMembers || []).map((id: ID) => this.employees.find((e) => e.id === id)).filter(Boolean) + ); - const formValue = { ...this.form.value, organizationId, organization: this.organization }; + this.form + .get('teams') + .setValue((this.selectedTeams || []).map((id: ID) => this.teams.find((t) => t.id === id)).filter(Boolean)); - if (this.createModule) { - try { - const module = await firstValueFrom(this.organizationProjectModuleService.create(formValue)); - this.dialogRef.close(module); - } catch (error) { - console.error('Failed to create module:', error); - } - } else { - try { - const module = await firstValueFrom( - this.organizationProjectModuleService.update(this.projectModule.id, { ...formValue }) - ); - this.dialogRef.close(module); - } catch (error) { - console.error('Failed to update module:', error); - } - } + this.form + .get('tasks') + .setValue( + (this.form.get('tasks').value || []) + .map((id: ID) => this.tasks.find((t) => t.id === id)) + .filter(Boolean) + ); } /**