|
|
|
@ -1,5 +1,6 @@ |
|
|
|
import { getSum } from '@ghostfolio/common/helper'; |
|
|
|
import { AdminUserResponse } from '@ghostfolio/common/interfaces'; |
|
|
|
import { AdminService } from '@ghostfolio/ui/services'; |
|
|
|
import { AdminService, DataService } from '@ghostfolio/ui/services'; |
|
|
|
import { GfValueComponent } from '@ghostfolio/ui/value'; |
|
|
|
|
|
|
|
import { |
|
|
|
@ -16,7 +17,11 @@ import { MatButtonModule } from '@angular/material/button'; |
|
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
|
|
import { MatDialogModule } from '@angular/material/dialog'; |
|
|
|
import { MatMenuModule } from '@angular/material/menu'; |
|
|
|
import { MatTableDataSource, MatTableModule } from '@angular/material/table'; |
|
|
|
import { IonIcon } from '@ionic/angular/standalone'; |
|
|
|
import { Subscription } from '@prisma/client'; |
|
|
|
import { Big } from 'big.js'; |
|
|
|
import { differenceInDays } from 'date-fns'; |
|
|
|
import { addIcons } from 'ionicons'; |
|
|
|
import { ellipsisVertical } from 'ionicons/icons'; |
|
|
|
import { EMPTY } from 'rxjs'; |
|
|
|
@ -35,7 +40,8 @@ import { |
|
|
|
IonIcon, |
|
|
|
MatButtonModule, |
|
|
|
MatDialogModule, |
|
|
|
MatMenuModule |
|
|
|
MatMenuModule, |
|
|
|
MatTableModule |
|
|
|
], |
|
|
|
schemas: [CUSTOM_ELEMENTS_SCHEMA], |
|
|
|
selector: 'gf-user-detail-dialog', |
|
|
|
@ -43,18 +49,29 @@ import { |
|
|
|
templateUrl: './user-detail-dialog.html' |
|
|
|
}) |
|
|
|
export class GfUserDetailDialogComponent implements OnInit { |
|
|
|
public baseCurrency: string; |
|
|
|
public subscriptionsDataSource = new MatTableDataSource<Subscription>(); |
|
|
|
public subscriptionsDisplayedColumns = [ |
|
|
|
'createdAt', |
|
|
|
'type', |
|
|
|
'price', |
|
|
|
'expiresAt' |
|
|
|
]; |
|
|
|
public user: AdminUserResponse; |
|
|
|
|
|
|
|
public constructor( |
|
|
|
private adminService: AdminService, |
|
|
|
private changeDetectorRef: ChangeDetectorRef, |
|
|
|
@Inject(MAT_DIALOG_DATA) public data: UserDetailDialogParams, |
|
|
|
private dataService: DataService, |
|
|
|
private destroyRef: DestroyRef, |
|
|
|
public dialogRef: MatDialogRef< |
|
|
|
GfUserDetailDialogComponent, |
|
|
|
UserDetailDialogResult |
|
|
|
> |
|
|
|
) { |
|
|
|
this.baseCurrency = this.dataService.fetchInfo().baseCurrency; |
|
|
|
|
|
|
|
addIcons({ |
|
|
|
ellipsisVertical |
|
|
|
}); |
|
|
|
@ -74,6 +91,8 @@ export class GfUserDetailDialogComponent implements OnInit { |
|
|
|
.subscribe((user) => { |
|
|
|
this.user = user; |
|
|
|
|
|
|
|
this.subscriptionsDataSource.data = this.user.subscriptions ?? []; |
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
}); |
|
|
|
} |
|
|
|
@ -85,6 +104,24 @@ export class GfUserDetailDialogComponent implements OnInit { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public getSum() { |
|
|
|
return getSum( |
|
|
|
this.subscriptionsDataSource.data.map(({ price }) => { |
|
|
|
return new Big(price); |
|
|
|
}) |
|
|
|
).toNumber(); |
|
|
|
} |
|
|
|
|
|
|
|
public getType({ createdAt, expiresAt, price }: Subscription) { |
|
|
|
if (price) { |
|
|
|
return $localize`Paid`; |
|
|
|
} |
|
|
|
|
|
|
|
return differenceInDays(expiresAt, createdAt) <= 90 |
|
|
|
? $localize`Trial` |
|
|
|
: $localize`Coupon`; |
|
|
|
} |
|
|
|
|
|
|
|
public onClose() { |
|
|
|
this.dialogRef.close(); |
|
|
|
} |
|
|
|
|