Browse Source

Bugfix/copy coupon code to clipboard (#7386)

Improve copy coupon code to clipboard
pull/7371/head^2
Thomas Kaul 2 days ago
committed by GitHub
parent
commit
759588aef1
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 27
      apps/client/src/app/components/admin-overview/admin-overview.component.ts

27
apps/client/src/app/components/admin-overview/admin-overview.component.ts

@ -213,9 +213,16 @@ export class GfAdminOverviewComponent implements OnInit {
duration: this.couponDuration duration: this.couponDuration
}; };
const hasCopiedCouponCode = this.clipboard.copy(newCoupon.code);
const coupons = [...this.couponsDataSource.data, newCoupon]; 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) { protected onChangeCouponDuration(aCouponDuration: StringValue) {
@ -374,11 +381,11 @@ export class GfAdminOverviewComponent implements OnInit {
} }
private saveCoupons({ private saveCoupons({
codeToCopy, coupons,
coupons snackBarMessage
}: { }: {
codeToCopy?: string;
coupons: Coupon[]; coupons: Coupon[];
snackBarMessage?: string;
}) { }) {
this.dataService this.dataService
.putAdminSetting(PROPERTY_COUPONS, { .putAdminSetting(PROPERTY_COUPONS, {
@ -388,14 +395,10 @@ export class GfAdminOverviewComponent implements OnInit {
.subscribe(() => { .subscribe(() => {
this.couponsDataSource.data = coupons; this.couponsDataSource.data = coupons;
if (codeToCopy) { if (snackBarMessage) {
this.clipboard.copy(codeToCopy); this.snackBar.open(snackBarMessage, undefined, {
duration: ms('3 seconds')
this.snackBar.open( });
'✅ ' + $localize`${codeToCopy} has been copied to the clipboard`,
undefined,
{ duration: ms('3 seconds') }
);
} }
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();

Loading…
Cancel
Save