import { Maybe } from '@/core'; import { Component, EventEmitter, Input, Output } from '@angular/core'; import { FileSelectEvent, FileUpload } from 'primeng/fileupload'; import { onSelectArgs } from './model'; @Component({ selector: 'app-shared-upload-file', templateUrl: './upload-file.component.html', imports: [FileUpload], }) export class SharedUploadFileComponent { @Input() currentImage: Maybe = null; @Input() loading: boolean = false; @Input() name: string = 'file'; @Input() accept: string = 'image/*'; @Input() maxSize: Maybe = 5 * 1024; @Input() error: Maybe = null; @Input() hint: Maybe = null; @Output() onSelect = new EventEmitter(); onSelectedFile($event: FileSelectEvent) { const file = $event.files?.[0]; if (!file) { return; } const payload = new FormData(); payload.append(this.name, file, file.name); this.onSelect.emit({ data: payload, file }); } }