diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/document-info-dialog/document-info-dialog.component.ts b/apps/red-ui/src/app/modules/file-preview/dialogs/document-info-dialog/document-info-dialog.component.ts index 3846939ee..8974e1037 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/document-info-dialog/document-info-dialog.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/document-info-dialog/document-info-dialog.component.ts @@ -7,6 +7,7 @@ import { ActiveDossiersService } from '@services/dossiers/active-dossiers.servic import { FilesService } from '@services/files/files.service'; import { BaseDialogComponent } from '@iqser/common-ui'; import { firstValueFrom } from 'rxjs'; +import dayjs from 'dayjs'; @Component({ templateUrl: './document-info-dialog.component.html', @@ -39,7 +40,7 @@ export class DocumentInfoDialogComponent extends BaseDialogComponent implements async save() { const attributeIdToValue = { ...this.file.fileAttributes?.attributeIdToValue, - ...this.form.getRawValue(), + ...this._mapFormValues(this.form.getRawValue()), }; await firstValueFrom(this._fileAttributesService.setFileAttributes({ attributeIdToValue }, this.file.dossierId, this.file.fileId)); await firstValueFrom(this._filesService.reload(this.file.dossierId, this.file)); @@ -48,13 +49,27 @@ export class DocumentInfoDialogComponent extends BaseDialogComponent implements private _getForm(): UntypedFormGroup { return this._formBuilder.group( - this.attributes.reduce( - (acc, attr) => ({ + this.attributes.reduce((acc, attr) => { + const attrValue = this.file.fileAttributes?.attributeIdToValue[attr.id]; + return { ...acc, - [attr.id]: [this.file.fileAttributes?.attributeIdToValue[attr.id]], - }), - {}, - ), + [attr.id]: [this._isDate(attr.id) ? dayjs(attrValue).toDate() : attrValue], + }; + }, {}), ); } + + private _isDate(attrId: string) { + return this.attributes.find(a => a.id === attrId).type === 'DATE'; + } + + private _mapFormValues(formValue) { + return Object.keys(formValue).reduce((acc, key) => { + const crtValue = formValue[key]; + return { + ...acc, + [key]: this._isDate(key) ? dayjs(crtValue).format('YYYY-MM-DD') : crtValue, + }; + }, {}); + } }