Browse Source

Feature/duration extension in coupon system (#8493)

* Extend coupon system by duration extension of current subscription offer

* Update changelog
pull/8453/head^2
Thomas Kaul 5 hours ago
committed by GitHub
parent
commit
11e4b006f9
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      CHANGELOG.md
  2. 35
      apps/client/src/app/components/admin-overview/admin-overview.component.ts
  3. 25
      apps/client/src/app/components/admin-overview/admin-overview.html

6
CHANGELOG.md

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Changed
- Extended the coupon system to support the duration extension of the current subscription offer
## 3.101.0 - 2026-11-28
### Changed

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

@ -49,7 +49,11 @@ import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
import { RouterModule } from '@angular/router';
import { IonIcon } from '@ionic/angular/standalone';
import { addMilliseconds, formatDistanceToNowStrict } from 'date-fns';
import {
addMilliseconds,
FormatDistanceStrictUnit,
formatDistanceToNowStrict
} from 'date-fns';
import { addIcons } from 'ionicons';
import {
closeCircleOutline,
@ -88,6 +92,7 @@ import { catchError, finalize, of, switchMap } from 'rxjs';
export class GfAdminOverviewComponent implements OnInit {
protected activitiesCount: number;
protected couponDuration: StringValue = '14 days';
protected readonly couponDurationWithExtension: StringValue | undefined;
protected readonly couponsDataSource = new MatTableDataSource<Coupon>();
protected readonly couponsDisplayedColumns = [
'code',
@ -95,6 +100,7 @@ export class GfAdminOverviewComponent implements OnInit {
'createdAt',
'actions'
];
protected readonly durationExtension: StringValue | undefined;
protected hasPermissionForSubscription: boolean;
protected hasPermissionForSystemMessage: boolean;
protected hasPermissionToSyncDemoUserAccount: boolean;
@ -124,6 +130,15 @@ export class GfAdminOverviewComponent implements OnInit {
public constructor() {
this.info = this.dataService.fetchInfo();
this.durationExtension = this.info.subscriptionOffer?.durationExtension;
if (this.durationExtension) {
this.couponDurationWithExtension = ms(
ms('1 year') + ms(this.durationExtension),
{ long: true }
) as StringValue;
}
this.userService.stateChanged
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((state) => {
@ -185,13 +200,17 @@ export class GfAdminOverviewComponent implements OnInit {
this.fetchAdminData();
}
protected formatStringValue(aStringValue: StringValue) {
return formatDistanceToNowStrict(
addMilliseconds(new Date(), ms(aStringValue)),
{
locale: getDateFnsLocale(this.user?.settings?.language)
}
);
protected formatStringValue({
unit,
value
}: {
unit?: FormatDistanceStrictUnit;
value: StringValue;
}) {
return formatDistanceToNowStrict(addMilliseconds(new Date(), ms(value)), {
unit,
locale: getDateFnsLocale(this.user?.settings?.language)
});
}
protected onAddCoupon() {

25
apps/client/src/app/components/admin-overview/admin-overview.html

@ -178,7 +178,7 @@
<ng-container i18n>Duration</ng-container>
</th>
<td *matCellDef="let element" class="px-1 text-end" mat-cell>
{{ formatStringValue(element.duration) }}
{{ formatStringValue({ value: element.duration }) }}
</td>
</ng-container>
@ -263,23 +263,34 @@
(selectionChange)="onChangeCouponDuration($event.value)"
>
<mat-option value="7 days">{{
formatStringValue('7 days')
formatStringValue({ value: '7 days' })
}}</mat-option>
<mat-option value="14 days">{{
formatStringValue('14 days')
formatStringValue({ value: '14 days' })
}}</mat-option>
<mat-option value="30 days">{{
formatStringValue('30 days')
formatStringValue({ value: '30 days' })
}}</mat-option>
<mat-option value="90 days">{{
formatStringValue('90 days')
formatStringValue({ value: '90 days' })
}}</mat-option>
<mat-option value="180 days">{{
formatStringValue('180 days')
formatStringValue({ value: '180 days' })
}}</mat-option>
<mat-option value="1 year">{{
formatStringValue('1 year')
formatStringValue({ value: '1 year' })
}}</mat-option>
@if (durationExtension) {
<mat-option [value]="couponDurationWithExtension"
>{{ formatStringValue({ value: '1 year' }) }} +
{{
formatStringValue({
unit: 'day',
value: durationExtension
})
}}</mat-option
>
}
</mat-select>
</mat-form-field>
<button

Loading…
Cancel
Save