diff --git a/src/app/shared/services/excel-export.service.ts b/src/app/shared/services/excel-export.service.ts index d0b0c7d..a5ee3bd 100644 --- a/src/app/shared/services/excel-export.service.ts +++ b/src/app/shared/services/excel-export.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@angular/core'; import { saveAs } from 'file-saver'; import * as XLSX from 'xlsx'; +import { TranslateService } from '@ngx-translate/core'; import { EXCEL_FILE_EXTENSION, EXCEL_FILE_TYPE } from '../../utils/app.constants'; @Injectable({ @@ -8,21 +9,39 @@ import { EXCEL_FILE_EXTENSION, EXCEL_FILE_TYPE } from '../../utils/app.constants }) export class ExcelExportService { - constructor() { } - private fileType = EXCEL_FILE_TYPE; - private fileExtension = EXCEL_FILE_EXTENSION; + private fileExtension = EXCEL_FILE_EXTENSION; + + constructor(private translate: TranslateService) {} public exportExcel(jsonData: any[], fileName: string): void { - const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(jsonData); - const wb: XLSX.WorkBook = { Sheets: { 'data': ws }, SheetNames: ['data'] }; + // 🔑 Translate headers here (single place) + const translatedData = this.translateHeaders(jsonData); + + const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(translatedData); + const wb: XLSX.WorkBook = { Sheets: { data: ws }, SheetNames: ['data'] }; const excelBuffer: any = XLSX.write(wb, { bookType: 'xlsx', type: 'array' }); + this.saveExcelFile(excelBuffer, fileName); } + private translateHeaders(data: any[]): any[] { + if (!data || !data.length) return data; + + return data.map(row => { + const newRow: any = {}; + Object.keys(row).forEach(key => { + // Convention: translation keys == property names + const translatedKey = this.translate.instant(key); + newRow[translatedKey] = row[key]; + }); + return newRow; + }); + } + private saveExcelFile(buffer: any, fileName: string): void { - const data: Blob = new Blob([buffer], {type: this.fileType}); - saveAs.saveAs(data, fileName + this.fileExtension); + const data: Blob = new Blob([buffer], { type: this.fileType }); + saveAs(data, fileName + this.fileExtension); } } diff --git a/src/app/user-management/reset-password/reset-password.component.ts b/src/app/user-management/reset-password/reset-password.component.ts index 6e09527..3f1fcef 100644 --- a/src/app/user-management/reset-password/reset-password.component.ts +++ b/src/app/user-management/reset-password/reset-password.component.ts @@ -46,7 +46,7 @@ export class ResetPasswordComponent implements OnInit{ initializeForm(): void { this.resetPasswordForm = this.fb.group({ - userId: ['', Validators.required], // Changed to empty string and required + userId: [null, Validators.required], // Changed to empty string and required newPassword: ['', [ Validators.required, Validators.minLength(8), @@ -105,7 +105,6 @@ export class ResetPasswordComponent implements OnInit{ this.isSubmitting = true; const selectedId = this.resetPasswordForm.get('userId')?.value; - console.log("userid.....", selectedId); const payload = { userId: selectedId, @@ -119,10 +118,6 @@ export class ResetPasswordComponent implements OnInit{ this.i18nService.success(SuccessMessages.RESET_PASSWORD_SUCCESS, []); this.resetForm(); // Reset form after successful submission - // Optional: Navigate to dashboard or stay on page - setTimeout(() => { - this.router.navigate(['/dashboard']); - }, 1500); } this.isSubmitting = false; }, @@ -160,7 +155,7 @@ export class ResetPasswordComponent implements OnInit{ // Reset ng-select by clearing the value setTimeout(() => { this.resetPasswordForm.patchValue({ - userId: '', + userId: null, newPassword: '', confirmPassword: '' });