Browse Source

Extend alert dialog with copy-to-clipboard functionality

pull/7258/head
Thomas Kaul 1 week ago
parent
commit
6e1a08d91a
  1. 7
      apps/client/src/app/components/user-account-membership/user-account-membership.component.ts
  2. 13
      libs/ui/src/lib/notifications/alert-dialog/alert-dialog.component.ts
  3. 1
      libs/ui/src/lib/notifications/interfaces/interfaces.ts
  4. 6
      libs/ui/src/lib/notifications/notification.service.ts

7
apps/client/src/app/components/user-account-membership/user-account-membership.component.ts

@ -146,13 +146,6 @@ export class GfUserAccountMembershipComponent {
) )
.subscribe(({ apiKey }) => { .subscribe(({ apiKey }) => {
this.notificationService.alert({ this.notificationService.alert({
copyFn: () => {
this.snackBar.open(
'✅ ' + $localize`${apiKey} has been copied to the clipboard`,
undefined,
{ duration: ms('3 seconds') }
);
},
copyValue: apiKey, copyValue: apiKey,
discardLabel: $localize`Okay`, discardLabel: $localize`Okay`,
message: $localize`Set this API key in your self-hosted environment:`, message: $localize`Set this API key in your self-hosted environment:`,

13
libs/ui/src/lib/notifications/alert-dialog/alert-dialog.component.ts

@ -2,6 +2,8 @@ import { Clipboard } from '@angular/cdk/clipboard';
import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { MatButtonModule } from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule, MatDialogRef } from '@angular/material/dialog'; import { MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import ms from 'ms';
import { AlertDialogParams } from './interfaces/interfaces'; import { AlertDialogParams } from './interfaces/interfaces';
@ -22,6 +24,7 @@ export class GfAlertDialogComponent {
inject<MatDialogRef<GfAlertDialogComponent>>(MatDialogRef); inject<MatDialogRef<GfAlertDialogComponent>>(MatDialogRef);
private readonly clipboard = inject(Clipboard); private readonly clipboard = inject(Clipboard);
private readonly snackBar = inject(MatSnackBar);
public initialize({ public initialize({
copyValue, copyValue,
@ -38,8 +41,14 @@ export class GfAlertDialogComponent {
public onCopyToClipboard() { public onCopyToClipboard() {
if (this.copyValue) { if (this.copyValue) {
this.clipboard.copy(this.copyValue); this.clipboard.copy(this.copyValue);
}
this.dialogRef.close('copy'); this.snackBar.open(
'✅ ' + $localize`The value has been copied to the clipboard`,
undefined,
{
duration: ms('3 seconds')
}
);
}
} }
} }

1
libs/ui/src/lib/notifications/interfaces/interfaces.ts

@ -1,7 +1,6 @@
import { ConfirmationDialogType } from '@ghostfolio/common/enums'; import { ConfirmationDialogType } from '@ghostfolio/common/enums';
export interface AlertParams { export interface AlertParams {
copyFn?: () => void;
copyValue?: string; copyValue?: string;
discardFn?: () => void; discardFn?: () => void;
discardLabel?: string; discardLabel?: string;

6
libs/ui/src/lib/notifications/notification.service.ts

@ -37,10 +37,8 @@ export class NotificationService {
title: aParams.title title: aParams.title
}); });
return dialog.afterClosed().subscribe((result) => { return dialog.afterClosed().subscribe(() => {
if (result === 'copy' && isFunction(aParams.copyFn)) { if (isFunction(aParams.discardFn)) {
aParams.copyFn();
} else if (isFunction(aParams.discardFn)) {
aParams.discardFn(); aParams.discardFn();
} }
}); });

Loading…
Cancel
Save