Skip to content

Commit af2650e

Browse files
committed
fix(move-file-dialog): fixed toasts
1 parent 2f2a3d6 commit af2650e

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/app/features/files/components/confirm-move-file-dialog/confirm-move-file-dialog.component.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { TranslatePipe, TranslateService } from '@ngx-translate/core';
44

55
import { Button } from 'primeng/button';
66
import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';
7-
import { ScrollerModule } from 'primeng/scroller';
87

98
import { finalize, forkJoin, of } from 'rxjs';
109
import { catchError } from 'rxjs/operators';
@@ -21,7 +20,7 @@ import { FileModel } from '@shared/models/files/file.model';
2120

2221
@Component({
2322
selector: 'osf-move-file-dialog',
24-
imports: [Button, TranslatePipe, ScrollerModule],
23+
imports: [Button, TranslatePipe],
2524
templateUrl: './confirm-move-file-dialog.component.html',
2625
styleUrl: './confirm-move-file-dialog.component.scss',
2726
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -82,7 +81,7 @@ export class ConfirmMoveFileDialogComponent {
8281
if (error.status === 409) {
8382
conflictFiles.push({ file, link });
8483
} else {
85-
this.toastService.showError(error.error?.message ?? 'Error');
84+
this.showErrorToast(action, error.error?.message);
8685
}
8786
return of(null);
8887
}),
@@ -92,7 +91,7 @@ export class ConfirmMoveFileDialogComponent {
9291
if (conflictFiles.length > 0) {
9392
this.openReplaceMoveDialog(conflictFiles, path, action);
9493
} else {
95-
this.showToast(action);
94+
this.showSuccessToast(action);
9695
this.config.header = this.translateService.instant('files.dialogs.moveFile.title');
9796
this.completeMove();
9897
}
@@ -124,26 +123,31 @@ export class ConfirmMoveFileDialogComponent {
124123
);
125124
forkJoin(replaceRequests$).subscribe({
126125
next: () => {
127-
this.showToast(action);
126+
this.showSuccessToast(action);
128127
this.completeMove();
129128
},
130129
});
131130
},
132131
onReject: () => {
133132
const totalFiles = this.config.data.files.length;
134133
if (totalFiles > conflictFiles.length) {
135-
this.showToast(action);
134+
this.showErrorToast(action);
136135
}
137136
this.completeMove();
138137
},
139138
});
140139
}
141140

142-
private showToast(action: string): void {
141+
private showSuccessToast(action: string) {
143142
const messageType = action === 'move' ? 'moveFile' : 'copyFile';
144143
this.toastService.showSuccess(`files.dialogs.${messageType}.success`);
145144
}
146145

146+
private showErrorToast(action: string, errorMessage?: string) {
147+
const messageType = action === 'move' ? 'moveFile' : 'copyFile';
148+
this.toastService.showError(errorMessage ?? `files.dialogs.${messageType}.error`);
149+
}
150+
147151
private completeMove(): void {
148152
this.dialogRef.close(true);
149153
}

src/app/features/files/components/move-file-dialog/move-file-dialog.component.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class MoveFileDialogComponent {
211211
if (error.status === 409) {
212212
conflictFiles.push({ file, link });
213213
} else {
214-
this.toastService.showError(error.error?.message ?? 'Error');
214+
this.showErrorToast(action, error.error?.message ?? 'Error');
215215
}
216216
return of(null);
217217
}),
@@ -221,7 +221,7 @@ export class MoveFileDialogComponent {
221221
if (conflictFiles.length > 0) {
222222
this.openReplaceMoveDialog(conflictFiles, path, action);
223223
} else {
224-
this.showToast(action);
224+
this.showSuccessToast(action);
225225
this.config.header = this.translateService.instant('files.dialogs.moveFile.title');
226226
this.completeMove();
227227
}
@@ -254,26 +254,31 @@ export class MoveFileDialogComponent {
254254

255255
forkJoin(replaceRequests$).subscribe({
256256
next: () => {
257-
this.showToast(action);
257+
this.showSuccessToast(action);
258258
this.completeMove();
259259
},
260260
});
261261
},
262262
onReject: () => {
263263
const totalFiles = this.config.data.files.length;
264264
if (totalFiles > conflictFiles.length) {
265-
this.showToast(action);
265+
this.showErrorToast(action);
266266
}
267267
this.completeMove();
268268
},
269269
});
270270
}
271271

272-
private showToast(action: string): void {
272+
private showSuccessToast(action: string) {
273273
const messageType = action === 'move' ? 'moveFile' : 'copyFile';
274274
this.toastService.showSuccess(`files.dialogs.${messageType}.success`);
275275
}
276276

277+
private showErrorToast(action: string, errorMessage?: string) {
278+
const messageType = action === 'move' ? 'moveFile' : 'copyFile';
279+
this.toastService.showError(errorMessage ?? `files.dialogs.${messageType}.error`);
280+
}
281+
277282
private completeMove(): void {
278283
this.isFilesUpdating.set(false);
279284
this.actions.setCurrentFolder(this.initialFolder);

src/assets/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@
11631163
"pathError": "Path is not specified!",
11641164
"success": "Successfully moved.",
11651165
"noMovePermission": "Cannot move or copy to this file provider",
1166+
"error": "Failed to move or copy files, please try again later",
11661167
"movingHeader": "Moving...",
11671168
"copingHeader": "Copying..."
11681169
},

0 commit comments

Comments
 (0)