Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🀍

Bugfix/copy coupon code to clipboard (#7386)

Thomas Kaul759588aef1cd
diff --git a/apps/client/src/app/components/admin-overview/admin-overview.component.ts b/apps/client/src/app/components/admin-overview/admin-overview.component.ts
index 62bc78df16..0bed8111fb 100644
--- a/apps/client/src/app/components/admin-overview/admin-overview.component.ts
+++ b/apps/client/src/app/components/admin-overview/admin-overview.component.ts
@@ -213,9 +213,16 @@ export class GfAdminOverviewComponent implements OnInit {
duration: this.couponDuration
};
+ const hasCopiedCouponCode = this.clipboard.copy(newCoupon.code);
+
const coupons = [...this.couponsDataSource.data, newCoupon];
- this.saveCoupons({ coupons, codeToCopy: newCoupon.code });
+ this.saveCoupons({
+ coupons,
+ snackBarMessage: hasCopiedCouponCode
+ ? 'βœ… ' + $localize`${newCoupon.code} has been copied to the clipboard`
+ : 'βœ… ' + $localize`Coupon ${newCoupon.code} has been created`
+ });
}
protected onChangeCouponDuration(aCouponDuration: StringValue) {
@@ -374,11 +381,11 @@ export class GfAdminOverviewComponent implements OnInit {
}
private saveCoupons({
- codeToCopy,
- coupons
+ coupons,
+ snackBarMessage
}: {
- codeToCopy?: string;
coupons: Coupon[];
+ snackBarMessage?: string;
}) {
this.dataService
.putAdminSetting(PROPERTY_COUPONS, {
@@ -388,14 +395,10 @@ export class GfAdminOverviewComponent implements OnInit {
.subscribe(() => {
this.couponsDataSource.data = coupons;
- if (codeToCopy) {
- this.clipboard.copy(codeToCopy);
-
- this.snackBar.open(
- 'βœ… ' + $localize`${codeToCopy} has been copied to the clipboard`,
- undefined,
- { duration: ms('3 seconds') }
- );
+ if (snackBarMessage) {
+ this.snackBar.open(snackBarMessage, undefined, {
+ duration: ms('3 seconds')
+ });
}
this.changeDetectorRef.markForCheck();