diff --git a/package-lock.json b/package-lock.json index 9cec0b2..6a96e4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,7 @@ "crypto-js": "3.3.0", "dayjs": "^1.10.7", "highlight.js": "11.2.0", + "jwt-decode": "^3.1.2", "libphonenumber-js": "^1.9.49", "lodash-es": "4.17.21", "moment": "2.29.1", @@ -9627,6 +9628,11 @@ "node >= 0.2.0" ] }, + "node_modules/jwt-decode": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-3.1.2.tgz", + "integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==" + }, "node_modules/karma": { "version": "6.3.16", "resolved": "https://registry.npmjs.org/karma/-/karma-6.3.16.tgz", @@ -22416,6 +22422,11 @@ "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=", "dev": true }, + "jwt-decode": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-3.1.2.tgz", + "integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==" + }, "karma": { "version": "6.3.16", "resolved": "https://registry.npmjs.org/karma/-/karma-6.3.16.tgz", diff --git a/package.json b/package.json index 79ddb6f..b639833 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "crypto-js": "3.3.0", "dayjs": "^1.10.7", "highlight.js": "11.2.0", + "jwt-decode": "^3.1.2", "libphonenumber-js": "^1.9.49", "lodash-es": "4.17.21", "moment": "2.29.1", diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 0103342..510aec1 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -13,4 +13,5 @@ export class AppComponent constructor() { } + } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 0d632c5..ec66f1e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -12,9 +12,10 @@ import { LayoutModule } from 'app/layout/layout.module'; import { AppComponent } from 'app/app.component'; import { appRoutes } from 'app/app.routing'; import { LocationStrategy, PathLocationStrategy } from '@angular/common'; -import { SettingsComponent } from './pages/admin/Settings/settings.component'; import { tesoModule } from '@teso/teso.module'; import { NgxAwesomePopupModule,ConfirmBoxConfigModule} from '@costlydeveloper/ngx-awesome-popup'; +import { ProductDescriptionShort } from './pipes/productDescriptionShort.pipe'; +import { CouponWorthPipe } from './pipes/coupon-worth.pipe'; const routerConfig: ExtraOptions = { preloadingStrategy : PreloadAllModules, @@ -24,7 +25,7 @@ const routerConfig: ExtraOptions = { @NgModule({ declarations: [ AppComponent, - SettingsComponent + ], imports : [ BrowserModule, diff --git a/src/app/app.resolvers.ts b/src/app/app.resolvers.ts index d67ce79..a4693ce 100644 --- a/src/app/app.resolvers.ts +++ b/src/app/app.resolvers.ts @@ -6,6 +6,11 @@ import { NavigationService } from 'app/core/navigation/navigation.service'; import { NotificationsService } from 'app/layout/common/notifications/notifications.service'; import { QuickChatService } from 'app/layout/common/quick-chat/quick-chat.service'; import { UserService } from 'app/core/user/user.service'; +import { GoldCoinService } from './layout/common/goldcoin/goldcoin.service'; +import { CouponsService } from './pages/admin/Coupons/coupons.service'; +import { ProductsService } from './pages/admin/Products/products.service'; +import { FollowersService } from './pages/admin/Followers/followers.service'; +import { ProfileService } from './pages/admin/Profile/profile.service'; @Injectable({ providedIn: 'root' @@ -20,9 +25,13 @@ export class InitialDataResolver implements Resolve private _navigationService: NavigationService, private _notificationsService: NotificationsService, private _quickChatService: QuickChatService, - private _userService: UserService - ) - { + private _userService: UserService, + private _couponService: CouponsService, + private _productService: ProductsService, + private _goldCoinService: GoldCoinService, + private _subscriberService:FollowersService, + private _profileService:ProfileService, + ) { } // ----------------------------------------------------------------------------------------------------- @@ -35,15 +44,20 @@ export class InitialDataResolver implements Resolve * @param route * @param state */ - resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable - { + resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { // Fork join multiple API endpoint calls to wait all of them to finish return forkJoin([ this._navigationService.get(), this._messagesService.getAll(), this._notificationsService.getAll(), this._quickChatService.getChats(), - this._userService.get() + this._userService.get(), + this._goldCoinService.getAll(), + this._couponService.getCategory(), + this._productService.getCategories(), + this._productService.getData(), + this._subscriberService.getData(), + this._profileService.getCategories() ]); } } diff --git a/src/app/app.routing.ts b/src/app/app.routing.ts index 6b5a770..431450a 100644 --- a/src/app/app.routing.ts +++ b/src/app/app.routing.ts @@ -48,7 +48,7 @@ export const appRoutes: Route[] = [ }, children: [ {path: 'sign-out', loadChildren: () => import('app/pages/auth/sign-out/sign-out.module').then(m => m.AuthSignOutModule)}, - {path: 'unlock-session', loadChildren: () => import('app/pages/auth/unlock-session/unlock-session.module').then(m => m.AuthUnlockSessionModule)} + ] }, @@ -67,6 +67,7 @@ export const appRoutes: Route[] = [ {path: 'products', loadChildren: () => import('app/pages/admin/Products/products.module').then(m => m.ProductsModule)}, {path: 'followers', loadChildren: () => import('app/pages/admin/Followers/followers.module').then(m => m.FollowersModule)}, {path: 'desires', loadChildren: () => import('app/pages/admin/Monthly_Desires/desires.module').then(m => m.DesiresModule)}, + {path: 'profile', loadChildren: () => import('app/pages/admin/Profile/profile.module').then(m => m.ProfileModule)}, ] } ]; diff --git a/src/app/core/auth/auth.interceptor.ts b/src/app/core/auth/auth.interceptor.ts index 3fb50b2..8c07b1e 100644 --- a/src/app/core/auth/auth.interceptor.ts +++ b/src/app/core/auth/auth.interceptor.ts @@ -6,13 +6,11 @@ import { AuthService } from 'app/core/auth/auth.service'; import { AuthUtils } from 'app/core/auth/auth.utils'; @Injectable() -export class AuthInterceptor implements HttpInterceptor -{ +export class AuthInterceptor implements HttpInterceptor { /** * Constructor */ - constructor(private _authService: AuthService) - { + constructor(private _authService: AuthService) { } /** @@ -21,8 +19,7 @@ export class AuthInterceptor implements HttpInterceptor * @param req * @param next */ - intercept(req: HttpRequest, next: HttpHandler): Observable> - { + intercept(req: HttpRequest, next: HttpHandler): Observable> { // Clone the request object let newReq = req.clone(); @@ -34,10 +31,15 @@ export class AuthInterceptor implements HttpInterceptor // for the protected API routes which our response interceptor will // catch and delete the access token from the local storage while logging // the user out from the app. - if ( this._authService.accessToken && !AuthUtils.isTokenExpired(this._authService.accessToken) ) + if (this._authService.relevantToken)//&& !AuthUtils.isTokenExpired() ) { newReq = req.clone({ - headers: req.headers.set('Authorization', 'Bearer ' + this._authService.accessToken) + headers: req.headers.set('Authorization', 'Bearer ' + this._authService.relevantToken) + .append('Accept', '*/*') + .append('Content-Type', 'application/json; charset=utf-8;') + .append("Access-Control-Allow-Origin", "*") + .append("Access-Control-Allow-Methods", "DELETE, POST, GET, OPTIONS") + .append("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With") }); } @@ -46,8 +48,7 @@ export class AuthInterceptor implements HttpInterceptor catchError((error) => { // Catch "401 Unauthorized" responses - if ( error instanceof HttpErrorResponse && error.status === 401 ) - { + if (error instanceof HttpErrorResponse && error.status === 401) { // Sign out this._authService.signOut(); diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index b720a0c..627463e 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -37,6 +37,16 @@ export class AuthService return localStorage.getItem('accessToken') ?? ''; } + set relevantToken(token: string) + { + localStorage.setItem('relevantToken', token); + } + + get relevantToken(): string + { + return localStorage.getItem('relevantToken') ?? ''; + } + // ----------------------------------------------------------------------------------------------------- // @ Public methods // ----------------------------------------------------------------------------------------------------- @@ -79,7 +89,7 @@ export class AuthService // Store the access token in the local storage this.accessToken = response.accessToken; - +this.relevantToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOiIyMjY0ODQyNzciLCJqdGkiOiI2ZWJiYzhlZC1hNTFkLTRjNTMtODBkOC05YWU2OTYyMzU4M2YiLCJpc3MiOiJURVNPIEFVVEggU0VSVkVSIiwiZXhwIjoxNjQ2NDA4NTU4LCJuYmYiOiIyMjY1NDQyNzciLCJzdWIiOiIxVEVTQlUwMDAwMDAwMCIsImJ1c2luZXNzSUQiOiIxVEVTQlUwMDAwMDAwMCIsInN1YnNjcmlwdGlvblBsYW4iOiJUVFMwMDEiLCJidXNpbmVzc05hbWUiOiJUZXNvIEdoYW5hIiwiYXVkIjoiVEVTTyJ9.HPgBtbrw8yFzzCUwMx7_3QbfX7LloANFZ-HFzLglDio"; // Set the authenticated flag to true this._authenticated = true; @@ -161,25 +171,23 @@ export class AuthService /** * Check the authentication status */ - check(): Observable - { + check(): Observable { // Check if the user is logged in - if ( this._authenticated ) - { + if (this._authenticated) { return of(true); } // Check the access token availability - if ( !this.accessToken ) - { + if (!this.accessToken) { + this.signOut(); return of(false); } - // Check the access token expire date - if ( AuthUtils.isTokenExpired(this.accessToken) ) - { - return of(false); - } + + // // Check the access token expire date + // if (AuthUtils.isTokenExpired(this.accessToken)) { + // return of(false); + // } // If the access token exists and it didn't expire, sign in using it return this.signInUsingToken(); diff --git a/src/app/core/user/user.service.ts b/src/app/core/user/user.service.ts index 11aab27..69da8bb 100644 --- a/src/app/core/user/user.service.ts +++ b/src/app/core/user/user.service.ts @@ -3,13 +3,15 @@ import { HttpClient } from '@angular/common/http'; import { Observable, ReplaySubject } from 'rxjs'; import { map, tap } from 'rxjs/operators'; import { User } from 'app/core/user/user.types'; +import { TesoBusinessDetail } from 'app/models/businessModel'; +import { environment } from 'environments/environment'; @Injectable({ providedIn: 'root' }) export class UserService { - private _user: ReplaySubject = new ReplaySubject(1); + private _user: ReplaySubject = new ReplaySubject(1); /** * Constructor @@ -27,13 +29,13 @@ export class UserService * * @param value */ - set user(value: User) + set user(value: TesoBusinessDetail) { // Store the value this._user.next(value); } - get user$(): Observable + get user$(): Observable { return this._user.asObservable(); } @@ -45,9 +47,9 @@ export class UserService /** * Get the current logged in user data */ - get(): Observable + get(): Observable { - return this._httpClient.get('api/common/user').pipe( + return this._httpClient.get(environment.apiURL +'business/getProfile').pipe( tap((user) => { this._user.next(user); }) @@ -59,11 +61,11 @@ export class UserService * * @param user */ - update(user: User): Observable + update(user: TesoBusinessDetail): Observable { - return this._httpClient.patch('api/common/user', {user}).pipe( + this._user.next(user); + return this._httpClient.patch('api/common/user', {user}).pipe( map((response) => { - this._user.next(response); }) ); } diff --git a/src/app/layout/common/goldcoin/goldcoin.component.html b/src/app/layout/common/goldcoin/goldcoin.component.html index b5d8682..0f5bde7 100644 --- a/src/app/layout/common/goldcoin/goldcoin.component.html +++ b/src/app/layout/common/goldcoin/goldcoin.component.html @@ -1,6 +1,6 @@
Logo image - +{{gold}} + {{gold}}
\ No newline at end of file diff --git a/src/app/layout/common/goldcoin/goldcoin.component.ts b/src/app/layout/common/goldcoin/goldcoin.component.ts index 15ca550..9d5386b 100644 --- a/src/app/layout/common/goldcoin/goldcoin.component.ts +++ b/src/app/layout/common/goldcoin/goldcoin.component.ts @@ -1,25 +1,26 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit, TemplateRef, ViewChild, ViewContainerRef, ViewEncapsulation } from '@angular/core'; +import { AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit, TemplateRef, ViewChild, ViewContainerRef, ViewEncapsulation } from '@angular/core'; import { Overlay, OverlayRef } from '@angular/cdk/overlay'; import { TemplatePortal } from '@angular/cdk/portal'; import { MatButton } from '@angular/material/button'; -import { Subject } from 'rxjs'; -import { takeUntil } from 'rxjs/operators'; +import { takeUntil, takeWhile, tap } from 'rxjs/operators'; import { GoldCoinService } from './goldcoin.service'; +import { Finance } from 'app/models/businessModel'; +import { interval, Subject, Subscription } from 'rxjs'; @Component({ - selector : 'goldcoins', - templateUrl : './goldcoin.component.html', - encapsulation : ViewEncapsulation.Emulated, - styleUrls :["./goldcoin.component.scss"], + selector: 'goldcoins', + templateUrl: './goldcoin.component.html', + encapsulation: ViewEncapsulation.Emulated, + styleUrls: ["./goldcoin.component.scss"], changeDetection: ChangeDetectionStrategy.OnPush, - exportAs : 'goldcoins' + exportAs: 'goldcoins' }) -export class GoldCoinComponent implements OnInit, OnDestroy -{ - - gold: number = 50; +export class GoldCoinComponent implements OnInit, OnDestroy, AfterViewInit { + + gold: number = 0; private _overlayRef: OverlayRef; private _unsubscribeAll: Subject = new Subject(); + sub: Subscription /** * Constructor @@ -27,8 +28,15 @@ export class GoldCoinComponent implements OnInit, OnDestroy constructor( private _changeDetectorRef: ChangeDetectorRef, private _goldcoinsService: GoldCoinService, - ) - { + ) { + + } + ngAfterViewInit(): void { + interval(1000) + // .pipe(takeWhile(() => !stop)) + .subscribe(() => { + this._goldcoinsService.getAll(); + }); } // ----------------------------------------------------------------------------------------------------- @@ -38,36 +46,36 @@ export class GoldCoinComponent implements OnInit, OnDestroy /** * On init */ - ngOnInit(): void - { - // Subscribe to notification changes - // this._notificationsService.notifications$ - // .pipe(takeUntil(this._unsubscribeAll)) - // .subscribe((notifications: Notification[]) => { - - // // Load the notifications - // this.notifications = notifications; - - // // Calculate the unread count - // this._calculateUnreadCount(); - - // // Mark for check - // this._changeDetectorRef.markForCheck(); - // }); + ngOnInit(): void { + this._goldcoinsService.notifications$ + .pipe(takeUntil(this._unsubscribeAll)) + .subscribe((gold: Finance) => { + + // Load the notifications + this.gold = gold.gold; + + + // Mark for check + this._changeDetectorRef.markForCheck(); + }); + this.sub = interval(100000) + .subscribe((val) => { + + this._goldcoinsService.getUpdate(); + this._changeDetectorRef.markForCheck(); + }); } /** * On destroy */ - ngOnDestroy(): void - { + ngOnDestroy(): void { // Unsubscribe from all subscriptions this._unsubscribeAll.next(); this._unsubscribeAll.complete(); - + this.sub.unsubscribe(); // Dispose the overlay - if ( this._overlayRef ) - { + if (this._overlayRef) { this._overlayRef.dispose(); } } @@ -82,15 +90,14 @@ export class GoldCoinComponent implements OnInit, OnDestroy /** * Mark all notifications as read */ - + /** * Track by function for ngFor loops * * @param index * @param item */ - trackByFn(index: number, item: any): any - { + trackByFn(index: number, item: any): any { return item.id || index; } @@ -108,5 +115,5 @@ export class GoldCoinComponent implements OnInit, OnDestroy * * @private */ - + } diff --git a/src/app/layout/common/goldcoin/goldcoin.service.ts b/src/app/layout/common/goldcoin/goldcoin.service.ts index 1833296..43f1dc0 100644 --- a/src/app/layout/common/goldcoin/goldcoin.service.ts +++ b/src/app/layout/common/goldcoin/goldcoin.service.ts @@ -1,21 +1,21 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; -import { Observable, ReplaySubject } from 'rxjs'; +import { interval, Observable, ReplaySubject } from 'rxjs'; import { Notification } from 'app/layout/common/notifications/notifications.types'; -import { map, switchMap, take, tap } from 'rxjs/operators'; +import { map, switchMap, take, takeWhile, tap } from 'rxjs/operators'; +import { Finance } from 'app/models/businessModel'; +import { environment } from 'environments/environment'; @Injectable({ providedIn: 'root' }) -export class GoldCoinService -{ - private _notifications: ReplaySubject = new ReplaySubject(1); +export class GoldCoinService { + private _notifications: ReplaySubject = new ReplaySubject(1); /** * Constructor */ - constructor(private _httpClient: HttpClient) - { + constructor(private _httpClient: HttpClient) { } // ----------------------------------------------------------------------------------------------------- @@ -25,8 +25,7 @@ export class GoldCoinService /** * Getter for notifications */ - get notifications$(): Observable - { + get notifications$(): Observable { return this._notifications.asObservable(); } @@ -37,119 +36,34 @@ export class GoldCoinService /** * Get all notifications */ - getAll(): Observable - { - return this._httpClient.get('api/common/notifications').pipe( + getAll(): Observable { + return this._httpClient.get(environment.apiURL + 'api/business-finance').pipe( tap((notifications) => { + if (notifications == null) { + notifications = { + businessID: "", + gold: 0, + } + } this._notifications.next(notifications); }) ); } - - /** - * Create a notification - * - * @param notification - */ - create(notification: Notification): Observable - { - return this.notifications$.pipe( - take(1), - switchMap(notifications => this._httpClient.post('api/common/notifications', {notification}).pipe( - map((newNotification) => { - - // Update the notifications with the new notification - this._notifications.next([...notifications, newNotification]); - - // Return the new notification from observable - return newNotification; - }) - )) - ); + getUpdate(): void { + this._httpClient.get(environment.apiURL + 'api/business-finance').subscribe((notifications) => { + if (notifications == null) { + notifications = { + businessID: "", + gold: 0, + } + } + this._notifications.next(notifications); + }) } - /** - * Update the notification + * Create a notification * - * @param id * @param notification */ - update(id: string, notification: Notification): Observable - { - return this.notifications$.pipe( - take(1), - switchMap(notifications => this._httpClient.patch('api/common/notifications', { - id, - notification - }).pipe( - map((updatedNotification: Notification) => { - - // Find the index of the updated notification - const index = notifications.findIndex(item => item.id === id); - - // Update the notification - notifications[index] = updatedNotification; - - // Update the notifications - this._notifications.next(notifications); - - // Return the updated notification - return updatedNotification; - }) - )) - ); - } - - /** - * Delete the notification - * - * @param id - */ - delete(id: string): Observable - { - return this.notifications$.pipe( - take(1), - switchMap(notifications => this._httpClient.delete('api/common/notifications', {params: {id}}).pipe( - map((isDeleted: boolean) => { - - // Find the index of the deleted notification - const index = notifications.findIndex(item => item.id === id); - // Delete the notification - notifications.splice(index, 1); - - // Update the notifications - this._notifications.next(notifications); - - // Return the deleted status - return isDeleted; - }) - )) - ); - } - - /** - * Mark all notifications as read - */ - markAllAsRead(): Observable - { - return this.notifications$.pipe( - take(1), - switchMap(notifications => this._httpClient.get('api/common/notifications/mark-all-as-read').pipe( - map((isUpdated: boolean) => { - - // Go through all notifications and set them as read - notifications.forEach((notification, index) => { - notifications[index].read = true; - }); - - // Update the notifications - this._notifications.next(notifications); - - // Return the updated status - return isUpdated; - }) - )) - ); - } } diff --git a/src/app/layout/common/user/user.component.html b/src/app/layout/common/user/user.component.html index 9640de7..5f1622f 100644 --- a/src/app/layout/common/user/user.component.html +++ b/src/app/layout/common/user/user.component.html @@ -4,20 +4,13 @@ [matMenuTriggerFor]="userActions"> + class="w-10 h-10 rounded-full" + *ngIf="showAvatar && user.businessLogo" + [src]="imageLoader(user.businessLogo)"> - + @@ -27,19 +20,17 @@ - - - + + + + diff --git a/src/app/pages/admin/Coupons/AdminNewCoupons/admin-new-coupons.component.html b/src/app/pages/admin/Coupons/AdminNewCoupons/admin-new-coupons.component.html index a962e77..e3e997a 100644 --- a/src/app/pages/admin/Coupons/AdminNewCoupons/admin-new-coupons.component.html +++ b/src/app/pages/admin/Coupons/AdminNewCoupons/admin-new-coupons.component.html @@ -1,6 +1,6 @@
-

New Coupons

+

New Coupons

@@ -15,26 +15,27 @@
- Target Name + {{businessTargetted.businessName}} - +
-
+
- Target Name + Product Name
- - Product 1 - Product 2 - Product 3 - Product 4 + + + {{product.productName}} + +
@@ -46,7 +47,7 @@
- GH¢200 + {{selectedProduct.unitPrice | currency:"GHS "}}
@@ -58,12 +59,12 @@
- - Freebie - Discount - Proximity Freebie - Proximity Discount + + + {{type.typeName}} + +
@@ -91,7 +92,7 @@ -
+
Percentage Off @@ -106,15 +107,34 @@ %  
+
+ + Percentage Off + +
+ + From   + + %   + +
+
+ + To   + + %   + +
+
Coupon Worth - From GH¢200 To GH¢800 + From {{selectedProduct.unitPrice | couponWorth:fromWorth}} To {{selectedProduct.unitPrice | couponWorth:toWorth}}
-
+
Date Of Expiration @@ -123,9 +143,25 @@ Time   - +
+
+
+ + + Date Of Expiration + + + +
+
+ + Time   + + +
+
diff --git a/src/app/pages/admin/Coupons/AdminNewCoupons/admin-new-coupons.component.ts b/src/app/pages/admin/Coupons/AdminNewCoupons/admin-new-coupons.component.ts index b74c02d..eb3b99d 100644 --- a/src/app/pages/admin/Coupons/AdminNewCoupons/admin-new-coupons.component.ts +++ b/src/app/pages/admin/Coupons/AdminNewCoupons/admin-new-coupons.component.ts @@ -1,22 +1,63 @@ -import { Component, Inject, OnInit } from '@angular/core'; +import { Component, Inject, OnDestroy, OnInit } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialog } from '@angular/material/dialog'; +import { tesoMediaWatcherService } from '@teso/services/media-watcher'; +import { TesoBusinessDetail } from 'app/models/businessModel'; +import { CouponsType } from 'app/models/couponsModel'; +import { ProductsModel } from 'app/models/productsModel'; +import { Subject } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; import { BusinessLookUpComponent } from '../../Products/BusinessLookUp/business-look-up.component'; +import { ProductsService } from '../../Products/products.service'; +import { CouponsService } from '../coupons.service'; @Component({ selector: 'app-admin-new-coupons', templateUrl: './admin-new-coupons.component.html', styleUrls: ['./admin-new-coupons.component.scss'] }) -export class AdminNewCouponsComponent implements OnInit { - constructor(@Inject(MAT_DIALOG_DATA) public data: { product: any }, public dialog: MatDialog,) { } +export class AdminNewCouponsComponent implements OnInit, OnDestroy { + businessTargetted: TesoBusinessDetail = {}; + products: ProductsModel[] = []; + fromWorth:number; + toWorth:number; + selectedProduct: any = {}; + selectedType: any = {}; + isLoading: boolean = false; + isScreenSmall: boolean; + couponTypes: CouponsType[] = []; + private _unsubscribeAll: Subject = new Subject(); + constructor(@Inject(MAT_DIALOG_DATA) public data: { product: any }, + public dialog: MatDialog, private _productService: ProductsService, + private _couponService: CouponsService, private _tesoMediaWatcherService: tesoMediaWatcherService,) { } ngOnInit(): void { + this._couponService.categories$.pipe(takeUntil(this._unsubscribeAll)).subscribe((d) => { + this.couponTypes = d; + }); + this._productService.data$.pipe(takeUntil(this._unsubscribeAll)).subscribe((d) => { + this.products = d; + }); + this._tesoMediaWatcherService.onMediaChange$ + .pipe(takeUntil(this._unsubscribeAll)) + .subscribe(({ matchingAliases }) => { + + // Check if the screen is small + this.isScreenSmall = !matchingAliases.includes('md'); + }); } lookupBusiness() { const dialogRef = this.dialog.open(BusinessLookUpComponent, { disableClose: true, hasBackdrop: true, + }); + dialogRef.afterClosed().subscribe((result) => { + this.businessTargetted = result; }); } + ngOnDestroy(): void { + // Unsubscribe from all subscriptions + this._unsubscribeAll.next(); + this._unsubscribeAll.complete(); + } } diff --git a/src/app/pages/admin/Coupons/Inactive/inactive-coupons.component.html b/src/app/pages/admin/Coupons/Inactive/inactive-coupons.component.html index e8d367d..4dd2758 100644 --- a/src/app/pages/admin/Coupons/Inactive/inactive-coupons.component.html +++ b/src/app/pages/admin/Coupons/Inactive/inactive-coupons.component.html @@ -9,7 +9,7 @@ - {{transaction.name}} + {{transaction.targetProduct}} @@ -51,8 +51,11 @@ Range - - {{transaction.range}} + + {{transaction.lower}} - {{transaction.upper}} + + + 100% OFF @@ -62,7 +65,7 @@ - {{transaction.claimed}} + {{transaction.numberClaimed}} diff --git a/src/app/pages/admin/Coupons/NewCoupons/new-coupons.component.html b/src/app/pages/admin/Coupons/NewCoupons/new-coupons.component.html index df6135d..a9aa5b6 100644 --- a/src/app/pages/admin/Coupons/NewCoupons/new-coupons.component.html +++ b/src/app/pages/admin/Coupons/NewCoupons/new-coupons.component.html @@ -1,6 +1,6 @@
-

New Coupons

+

New Coupons

@@ -10,17 +10,17 @@
- Target Product + Product Name
- - Product 1 - Product 2 - Product 3 - Product 4 + + + {{product.productName}} + +
@@ -32,7 +32,7 @@
- GH¢200 + {{selectedProduct.unitPrice | currency:"GHS "}}
@@ -44,12 +44,12 @@
- - Freebie - Discount - Proximity Freebie - Proximity Discount + + + {{type.typeName}} + +
@@ -77,7 +77,7 @@ -
+
Percentage Off @@ -92,29 +92,66 @@ %  
+
+ + Percentage Off + +
+ + From   + + %   + +
+
+ + To   + + %   + +
+
Coupon Worth - From GH¢200 To GH¢800 + From {{selectedProduct.unitPrice | couponWorth:fromWorth}} To {{selectedProduct.unitPrice | + couponWorth:toWorth}}
-
- +
+ Date Of Expiration - + Time   - +
+
+
+ + + Date Of Expiration + + + +
+
+ + Time   + + +
+
+ \ No newline at end of file diff --git a/src/app/pages/admin/Coupons/NewCoupons/new-coupons.component.ts b/src/app/pages/admin/Coupons/NewCoupons/new-coupons.component.ts index a42c37f..46bba6a 100644 --- a/src/app/pages/admin/Coupons/NewCoupons/new-coupons.component.ts +++ b/src/app/pages/admin/Coupons/NewCoupons/new-coupons.component.ts @@ -1,15 +1,50 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, Inject, OnDestroy, OnInit } from '@angular/core'; +import { MAT_DIALOG_DATA, MatDialog } from '@angular/material/dialog'; +import { tesoMediaWatcherService } from '@teso/services/media-watcher'; +import { CouponsType } from 'app/models/couponsModel'; +import { ProductsModel } from 'app/models/productsModel'; +import { Subject } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; +import { ProductsService } from '../../Products/products.service'; +import { CouponsService } from '../coupons.service'; @Component({ selector: 'app-new-coupons', templateUrl: './new-coupons.component.html', styleUrls: ['./new-coupons.component.scss'] }) -export class NewCouponsComponent implements OnInit { - - constructor() { } +export class NewCouponsComponent implements OnInit,OnDestroy { + products: ProductsModel[] = []; + selectedProduct:any={}; + selectedType:any={}; + isLoading: boolean = false; + couponTypes:CouponsType[]=[]; + fromWorth:number; + toWorth:number; + isScreenSmall:boolean; + private _unsubscribeAll: Subject = new Subject(); + constructor(@Inject(MAT_DIALOG_DATA) public data: { product: any }, + public dialog: MatDialog, private _productService: ProductsService, + private _couponService: CouponsService, private _tesoMediaWatcherService: tesoMediaWatcherService,) { } ngOnInit(): void { - } + this._couponService.categories$.pipe(takeUntil(this._unsubscribeAll)).subscribe((d) => { + this.couponTypes = d; + }); + this._productService.data$.pipe(takeUntil(this._unsubscribeAll)).subscribe((d) => { + this.products = d; + }); + this._tesoMediaWatcherService.onMediaChange$ + .pipe(takeUntil(this._unsubscribeAll)) + .subscribe(({ matchingAliases }) => { + // Check if the screen is small + this.isScreenSmall = !matchingAliases.includes('md'); + }); + } + ngOnDestroy(): void { + // Unsubscribe from all subscriptions + this._unsubscribeAll.next(); + this._unsubscribeAll.complete(); + } } diff --git a/src/app/pages/admin/Coupons/coupons.component.html b/src/app/pages/admin/Coupons/coupons.component.html index 2652dcc..a08b8b6 100644 --- a/src/app/pages/admin/Coupons/coupons.component.html +++ b/src/app/pages/admin/Coupons/coupons.component.html @@ -6,7 +6,7 @@
Coupons
-
Here is a list of all your coupons on Teso (850) +
Here is a list of all your coupons on Teso ({{allcoupons.length}})
diff --git a/src/app/pages/admin/Coupons/coupons.component.ts b/src/app/pages/admin/Coupons/coupons.component.ts index 6a51105..a24f3c5 100644 --- a/src/app/pages/admin/Coupons/coupons.component.ts +++ b/src/app/pages/admin/Coupons/coupons.component.ts @@ -4,8 +4,13 @@ import { MatTableDataSource } from '@angular/material/table'; import { Router } from '@angular/router'; import { ConfirmBoxEvokeService } from '@costlydeveloper/ngx-awesome-popup'; import { tesoMediaWatcherService } from '@teso/services/media-watcher'; +import { CouponsModel } from 'app/models/couponsModel'; +import { throwIfEmpty } from 'rxjs/operators'; import { AdminNewCouponsComponent } from './AdminNewCoupons/admin-new-coupons.component'; +import { CouponsService } from './coupons.service'; import { NewCouponsComponent } from './NewCoupons/new-coupons.component'; +import jwt_decode from 'jwt-decode'; +import { AuthService } from 'app/core/auth/auth.service'; @Component({ selector: 'app-coupons', @@ -15,210 +20,48 @@ import { NewCouponsComponent } from './NewCoupons/new-coupons.component'; export class CouponsComponent implements OnInit { activecouponsData: MatTableDataSource = new MatTableDataSource(); inactivecouponsData: MatTableDataSource = new MatTableDataSource(); + allcoupons: CouponsModel[] = []; constructor(private router: Router, private _tesoMediaWatcherService: tesoMediaWatcherService, - public dialog: MatDialog, private confirmBoxEvokeService: ConfirmBoxEvokeService) { } + public dialog: MatDialog, private confirmBoxEvokeService: ConfirmBoxEvokeService, + private _couponsService: CouponsService, private _authService: AuthService) { + + } ngOnInit(): void { - this.activecouponsData.data = [ - { - id: '2bfa2be5-7688-48d5-b5ac-dc0d9ac97f14', - expiration:"2022-03-15", - name: 'Nadia Mcknight', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: '77a4383b-b5a5-4943-bc46-04c3431d1566', - expiration:"2022-03-15", - name: 'Best Blackburn', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: '8bb0f597-673a-47ca-8c77-2f83219cb9af', - expiration:"2022-03-15", - name: 'Duncan Carver', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: 'c318e31f-1d74-49c5-8dae-2bc5805e2fdb', - expiration:"2022-03-15", - name: 'Martin Richards', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: '0a8bc517-631a-4a93-aacc-000fa2e8294c', - expiration:"2022-03-15", - name: 'Candice Munoz', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: 'a4c9945a-757b-40b0-8942-d20e0543cabd', - expiration:"2022-03-15", - name: 'Vickie Mosley', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: 'b8258ccf-48b5-46a2-9c95-e0bd7580c645', - expiration:"2022-03-15", - name: 'Tina Harris', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: 'f004ea79-98fc-436c-9ba5-6cfe32fe583d', - expiration:"2022-03-15", - name: 'Holt Manning', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: '8b69fe2d-d7cc-4a3d-983d-559173e37d37', - expiration:"2022-03-15", - name: 'Misty Ramsey', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - } - ]; - this.inactivecouponsData.data = [ - { - id: '2bfa2be5-7688-48d5-b5ac-dc0d9ac97f14', - expiration:"2022-03-15", - name: 'Nadia Mcknight', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: '77a4383b-b5a5-4943-bc46-04c3431d1566', - expiration:"2022-03-15", - name: 'Best Blackburn', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: '8bb0f597-673a-47ca-8c77-2f83219cb9af', - expiration:"2022-03-15", - name: 'Duncan Carver', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: 'c318e31f-1d74-49c5-8dae-2bc5805e2fdb', - expiration:"2022-03-15", - name: 'Martin Richards', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: '0a8bc517-631a-4a93-aacc-000fa2e8294c', - expiration:"2022-03-15", - name: 'Candice Munoz', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: 'a4c9945a-757b-40b0-8942-d20e0543cabd', - expiration:"2022-03-15", - name: 'Vickie Mosley', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: 'b8258ccf-48b5-46a2-9c95-e0bd7580c645', - expiration:"2022-03-15", - name: 'Tina Harris', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: 'f004ea79-98fc-436c-9ba5-6cfe32fe583d', - expiration:"2022-03-15", - name: 'Holt Manning', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - }, - { - id: '8b69fe2d-d7cc-4a3d-983d-559173e37d37', - expiration:"2022-03-15", - name: 'Misty Ramsey', - range: '60% - 95%', - condition: 'By one get one free', - quantity:17, - type: "Freebie", - claimed: 50, - } - ] + this._couponsService.getData().subscribe((response) => { + this.allcoupons = response; + this.activecouponsData.data = this.allcoupons.filter(t => t.status.toLowerCase() == "active"); + this.inactivecouponsData.data = this.allcoupons.filter(t => t.status.toLowerCase() != "active"); + }); + } - generateCoupons(){ - if (!true) { - const dialogRef = this.dialog.open(NewCouponsComponent, { + generateCoupons() { + const tokenInfo = this.getDecodedAccessToken(this._authService.relevantToken); + + + if (tokenInfo.businessID != "1TESBU00000000") { + const dialogRef = this.dialog.open(AdminNewCouponsComponent, { disableClose: true, hasBackdrop: true, }); } else { - const dialogRef = this.dialog.open(AdminNewCouponsComponent, { + const dialogRef = this.dialog.open(NewCouponsComponent, { disableClose: true, hasBackdrop: true, }); + + } + } + + getDecodedAccessToken(token: string): any { + try { + return jwt_decode(token); + } catch (Error) { + return null; } } } diff --git a/src/app/pages/admin/Coupons/coupons.module.ts b/src/app/pages/admin/Coupons/coupons.module.ts index e83da52..57a8796 100644 --- a/src/app/pages/admin/Coupons/coupons.module.ts +++ b/src/app/pages/admin/Coupons/coupons.module.ts @@ -26,6 +26,7 @@ import { ActiveCouponsComponent } from './Active/active-coupons.component'; import { InactiveCouponsComponent } from './Inactive/inactive-coupons.component'; import { NewCouponsComponent } from './NewCoupons/new-coupons.component'; import { AdminNewCouponsComponent } from './AdminNewCoupons/admin-new-coupons.component'; +import { CouponWorthPipe } from 'app/pipes/coupon-worth.pipe'; @NgModule({ @@ -34,7 +35,8 @@ import { AdminNewCouponsComponent } from './AdminNewCoupons/admin-new-coupons.co ActiveCouponsComponent, InactiveCouponsComponent, NewCouponsComponent, - AdminNewCouponsComponent + AdminNewCouponsComponent, + CouponWorthPipe ], imports: [ RouterModule.forChild(couponsRoutes), diff --git a/src/app/pages/admin/Coupons/coupons.service.ts b/src/app/pages/admin/Coupons/coupons.service.ts new file mode 100644 index 0000000..1cbc770 --- /dev/null +++ b/src/app/pages/admin/Coupons/coupons.service.ts @@ -0,0 +1,59 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { BehaviorSubject, Observable } from 'rxjs'; +import { tap } from 'rxjs/operators'; +import { analytics as analyticsData } from 'app/mock-api/dashboards/analytics/data'; +import { environment } from 'environments/environment'; +import { CouponsModel, CouponsType } from 'app/models/couponsModel'; + +@Injectable({ + providedIn: 'root' +}) +export class CouponsService { + private _data: BehaviorSubject = new BehaviorSubject(null); + private _couponCategory: BehaviorSubject = new BehaviorSubject(null); + + /** + * Constructor + */ + constructor(private _httpClient: HttpClient) { + } + + // ----------------------------------------------------------------------------------------------------- + // @ Accessors + // ----------------------------------------------------------------------------------------------------- + + /** + * Getter for data + */ + get data$(): Observable { + return this._data.asObservable(); + } + + get categories$(): Observable { + return this._couponCategory.asObservable(); + } + + // ----------------------------------------------------------------------------------------------------- + // @ Public methods + // ----------------------------------------------------------------------------------------------------- + + /** + * Get data + */ + getData(): Observable { + return this._httpClient.get(environment.apiURL + `allcoupons`).pipe( + tap((response: any) => { + this._data.next(response); + }) + ); + } + + getCategory(): Observable { + return this._httpClient.get(environment.apiURL + `api/CouponTypes`).pipe( + tap((response: CouponsType[]) => { + this._couponCategory.next(response); + }) + ); + } +} diff --git a/src/app/pages/admin/Followers/PersonalizedCoupons/personalized-coupons.component.html b/src/app/pages/admin/Followers/PersonalizedCoupons/personalized-coupons.component.html new file mode 100644 index 0000000..9eb1593 --- /dev/null +++ b/src/app/pages/admin/Followers/PersonalizedCoupons/personalized-coupons.component.html @@ -0,0 +1,139 @@ +
+
+

Send a coupon to {{data.subscriber.firstname}} + {{data.subscriber.surname}}

+
+ + +
+ +
+ +
+
+ + Target Business + +
+
+ + {{businessTargetted.businessName}} + + +
+
+
+
+
+ + Product Name + +
+
+ + + + {{product.productName}} + + + + +
+
+
+
+ + Original Price + +
+
+ + {{selectedProduct.unitPrice | currency:"GHS "}} + +
+
+
+
+ + Coupon Type + +
+
+ + + DISCOUNT + FREEBIE + + +
+
+ +
+
+ + Coupon Condition + +
+
+ +
+
+
+
+ + Number Of Coupons + +
+
+ + + +
+ +
+
+ + Percentage Off + + + From   + + %   + + + To   + + %   + +
+
+ + Coupon Worth + + + From GH¢200 To GH¢800 + +
+
+ + Date Of Expiration + + + + + + Time   + + +
+
+ + +
+
+
\ No newline at end of file diff --git a/src/app/pages/admin/Followers/PersonalizedCoupons/personalized-coupons.component.scss b/src/app/pages/admin/Followers/PersonalizedCoupons/personalized-coupons.component.scss new file mode 100644 index 0000000..4ec9e31 --- /dev/null +++ b/src/app/pages/admin/Followers/PersonalizedCoupons/personalized-coupons.component.scss @@ -0,0 +1,11 @@ +.columns { + display: flex; + flex-direction: row; + flex-wrap: wrap; + width: 100%; +} + +.column { + flex: 50%; + font-size: medium; +} \ No newline at end of file diff --git a/src/app/pages/admin/Followers/PersonalizedCoupons/personalized-coupons.component.spec.ts b/src/app/pages/admin/Followers/PersonalizedCoupons/personalized-coupons.component.spec.ts new file mode 100644 index 0000000..c17c6da --- /dev/null +++ b/src/app/pages/admin/Followers/PersonalizedCoupons/personalized-coupons.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PersonalizedCouponsComponent } from './personalized-coupons.component'; + +describe('PersonalizedCouponsComponent', () => { + let component: PersonalizedCouponsComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ PersonalizedCouponsComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(PersonalizedCouponsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/admin/Followers/PersonalizedCoupons/personalized-coupons.component.ts b/src/app/pages/admin/Followers/PersonalizedCoupons/personalized-coupons.component.ts new file mode 100644 index 0000000..0bf9e58 --- /dev/null +++ b/src/app/pages/admin/Followers/PersonalizedCoupons/personalized-coupons.component.ts @@ -0,0 +1,50 @@ +import { Component, Inject, OnInit } from '@angular/core'; +import { MatDialog, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { TesoBusinessDetail } from 'app/models/businessModel'; +import { CouponsType } from 'app/models/couponsModel'; +import { ProductsModel } from 'app/models/productsModel'; +import { TesoUserDetails } from 'app/models/userModel'; +import { environment } from 'environments/environment'; +import { Subject } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; +import { CouponsService } from '../../Coupons/coupons.service'; +import { BusinessLookUpComponent } from '../../Products/BusinessLookUp/business-look-up.component'; +import { ProductsService } from '../../Products/products.service'; + +@Component({ + selector: 'app-personalized-coupons', + templateUrl: './personalized-coupons.component.html', + styleUrls: ['./personalized-coupons.component.scss'] +}) +export class PersonalizedCouponsComponent implements OnInit { + tesoGhana:boolean = false; + businessTargetted: TesoBusinessDetail = {}; + private _unsubscribeAll: Subject = new Subject(); + isLoading: boolean = false; + products: ProductsModel[] = []; + selectedProduct: any = {}; + selectedType: string; + couponTypes: CouponsType[] = []; + constructor(private _productService: ProductsService, + @Inject(MAT_DIALOG_DATA) public data: { subscriber: TesoUserDetails }, + public dialog: MatDialog,) { } + + ngOnInit(): void { + this._productService.data$.pipe(takeUntil(this._unsubscribeAll)).subscribe((d) => { + this.products = d; + }); + } + imageLoader(path: string): string { + return environment.apiURL + `followeruserdp/${path}`; + } + lookupBusiness() { + const dialogRef = this.dialog.open(BusinessLookUpComponent, { + disableClose: true, + hasBackdrop: true, + }); + + dialogRef.afterClosed().subscribe((result) => { + this.businessTargetted = result; + }); + } +} diff --git a/src/app/pages/admin/Followers/followers.component.html b/src/app/pages/admin/Followers/followers.component.html index 8b852df..24f6f57 100644 --- a/src/app/pages/admin/Followers/followers.component.html +++ b/src/app/pages/admin/Followers/followers.component.html @@ -13,26 +13,26 @@ - +
- +
- +
-
{{member.name}}
-
{{member.title}}
+
{{member.firstname}} {{member.surname}}
+
{{member.username}}
diff --git a/src/app/pages/admin/Followers/followers.component.ts b/src/app/pages/admin/Followers/followers.component.ts index e9408cc..d4e95d9 100644 --- a/src/app/pages/admin/Followers/followers.component.ts +++ b/src/app/pages/admin/Followers/followers.component.ts @@ -1,8 +1,14 @@ import { Component, OnInit } from '@angular/core'; +import { FormControl } from '@angular/forms'; +import { MatDialog } from '@angular/material/dialog'; import { Router } from '@angular/router'; +import { ConfirmBoxEvokeService } from '@costlydeveloper/ngx-awesome-popup'; +import { TesoUserDetails } from 'app/models/userModel'; +import { environment } from 'environments/environment'; import { Subject } from 'rxjs'; -import { takeUntil } from 'rxjs/operators'; +import { debounceTime, map, switchMap, takeUntil } from 'rxjs/operators'; import { FollowersService } from './followers.service'; +import { PersonalizedCouponsComponent } from './PersonalizedCoupons/personalized-coupons.component'; @Component({ selector: 'app-followers', @@ -11,100 +17,34 @@ import { FollowersService } from './followers.service'; }) export class FollowersComponent implements OnInit { - data: any; + data: TesoUserDetails[] = []; private _unsubscribeAll: Subject = new Subject(); - + searchInputControl: FormControl = new FormControl(); constructor( private _followersService: FollowersService, - private _router: Router + private _router: Router, + public dialog: MatDialog, private confirmBoxEvokeService: ConfirmBoxEvokeService, ) { } ngOnInit(): void { - this.data = { - teamMembers : [ - { - id : '2bfa2be5-7688-48d5-b5ac-dc0d9ac97f14', - avatar: 'assets/images/avatars/female-10.jpg', - name : 'Nadia Mcknight', - email : 'nadiamcknight@mail.com', - phone : '+1-943-511-2203', - title : 'Project Director' - }, - { - id : '77a4383b-b5a5-4943-bc46-04c3431d1566', - avatar: 'assets/images/avatars/male-19.jpg', - name : 'Best Blackburn', - email : 'blackburn.best@beadzza.me', - phone : '+1-814-498-3701', - title : 'Senior Developer' - }, - { - id : '8bb0f597-673a-47ca-8c77-2f83219cb9af', - avatar: 'assets/images/avatars/male-14.jpg', - name : 'Duncan Carver', - email : 'duncancarver@mail.info', - phone : '+1-968-547-2111', - title : 'Senior Developer' - }, - { - id : 'c318e31f-1d74-49c5-8dae-2bc5805e2fdb', - avatar: 'assets/images/avatars/male-01.jpg', - name : 'Martin Richards', - email : 'martinrichards@mail.biz', - phone : '+1-902-500-2668', - title : 'Junior Developer' - }, - { - id : '0a8bc517-631a-4a93-aacc-000fa2e8294c', - avatar: 'assets/images/avatars/female-20.jpg', - name : 'Candice Munoz', - email : 'candicemunoz@mail.co.uk', - phone : '+1-838-562-2769', - title : 'Lead Designer' - }, - { - id : 'a4c9945a-757b-40b0-8942-d20e0543cabd', - avatar: 'assets/images/avatars/female-01.jpg', - name : 'Vickie Mosley', - email : 'vickiemosley@mail.net', - phone : '+1-939-555-3054', - title : 'Designer' - }, - { - id : 'b8258ccf-48b5-46a2-9c95-e0bd7580c645', - avatar: 'assets/images/avatars/female-02.jpg', - name : 'Tina Harris', - email : 'tinaharris@mail.ca', - phone : '+1-933-464-2431', - title : 'Designer' - }, - { - id : 'f004ea79-98fc-436c-9ba5-6cfe32fe583d', - avatar: 'assets/images/avatars/male-02.jpg', - name : 'Holt Manning', - email : 'holtmanning@mail.org', - phone : '+1-822-531-2600', - title : 'Marketing Manager' - }, - { - id : '8b69fe2d-d7cc-4a3d-983d-559173e37d37', - avatar: 'assets/images/avatars/female-03.jpg', - name : 'Misty Ramsey', - email : 'mistyramsey@mail.us', - phone : '+1-990-457-2106', - title : 'Consultant' - } - ] - } - // this._followersService.data$ - // .pipe(takeUntil(this._unsubscribeAll)) - // .subscribe((data) => { - - // // Store the data - // this.data = data; - // console.log(this.data) - // // Prepare the chart data - // }); + this._followersService.data$ + .pipe(takeUntil(this._unsubscribeAll)) + .subscribe((data: TesoUserDetails[]) => { + this.data = data; + }); + this.searchInputControl.valueChanges + .pipe( + takeUntil(this._unsubscribeAll), + debounceTime(300), + switchMap((query) => { + // this.isLoading = true; + return this.data = this._followersService.filterFollowers(query); + }), + map(() => { + // this.isLoading = false; + }) + ) + .subscribe(); } ngOnDestroy(): void { // Unsubscribe from all subscriptions @@ -125,4 +65,15 @@ export class FollowersComponent implements OnInit { trackByFn(index: number, item: any): any { return item.id || index; } + imageLoader(path: string): string { + return environment.apiURL + `followeruserdp/${path}`; + } + + personalizedCoupon(user: TesoUserDetails) { + const dialogRef = this.dialog.open(PersonalizedCouponsComponent, { + disableClose: true, + hasBackdrop: true, + data: { subscriber: user }, + }); + } } diff --git a/src/app/pages/admin/Followers/followers.module.ts b/src/app/pages/admin/Followers/followers.module.ts index b1d6bbe..b3b3faf 100644 --- a/src/app/pages/admin/Followers/followers.module.ts +++ b/src/app/pages/admin/Followers/followers.module.ts @@ -16,12 +16,16 @@ import { TranslocoModule } from '@ngneat/transloco'; import { followersRoutes } from './followers.routing'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatInputModule } from '@angular/material/input'; +import { PersonalizedCouponsComponent } from './PersonalizedCoupons/personalized-coupons.component'; +import { MatDialogModule } from '@angular/material/dialog'; +import { MatSelectModule } from '@angular/material/select'; @NgModule({ declarations: [ - FollowersComponent + FollowersComponent, + PersonalizedCouponsComponent ], imports: [ RouterModule.forChild(followersRoutes), @@ -32,12 +36,12 @@ import { MatInputModule } from '@angular/material/input'; MatFormFieldModule, MatInputModule, MatMenuModule, + MatDialogModule, MatProgressBarModule, MatRippleModule, - // MatSidenavModule, MatSortModule, MatTableModule, - // MatTabsModule, + MatSelectModule, TranslocoModule, SharedModule ] diff --git a/src/app/pages/admin/Followers/followers.resolvers.ts b/src/app/pages/admin/Followers/followers.resolvers.ts index a5bc86d..10ce8b1 100644 --- a/src/app/pages/admin/Followers/followers.resolvers.ts +++ b/src/app/pages/admin/Followers/followers.resolvers.ts @@ -11,7 +11,7 @@ export class FollowersResolver implements Resolve /** * Constructor */ - constructor(private _projectService: FollowersService) + constructor(private _subscriberService: FollowersService) { } @@ -27,6 +27,6 @@ export class FollowersResolver implements Resolve */ resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { - return ;//this._projectService.getData(); + return this._subscriberService.getData(); } } diff --git a/src/app/pages/admin/Followers/followers.service.ts b/src/app/pages/admin/Followers/followers.service.ts index 0847825..842f089 100644 --- a/src/app/pages/admin/Followers/followers.service.ts +++ b/src/app/pages/admin/Followers/followers.service.ts @@ -2,13 +2,15 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { BehaviorSubject, Observable } from 'rxjs'; import { tap } from 'rxjs/operators'; +import { TesoUserDetails } from 'app/models/userModel'; +import { environment } from 'environments/environment'; @Injectable({ providedIn: 'root' }) export class FollowersService { - private _data: BehaviorSubject = new BehaviorSubject(null); + private _data: BehaviorSubject = new BehaviorSubject(null); /** * Constructor @@ -24,7 +26,7 @@ export class FollowersService /** * Getter for data */ - get data$(): Observable + get data$(): Observable { return this._data.asObservable(); } @@ -36,89 +38,15 @@ export class FollowersService /** * Get data */ - getData() + getData():Observable { - var project = { - teamMembers : [ - { - id : '2bfa2be5-7688-48d5-b5ac-dc0d9ac97f14', - avatar: 'assets/images/avatars/female-10.jpg', - name : 'Nadia Mcknight', - email : 'nadiamcknight@mail.com', - phone : '+1-943-511-2203', - title : 'Project Director' - }, - { - id : '77a4383b-b5a5-4943-bc46-04c3431d1566', - avatar: 'assets/images/avatars/male-19.jpg', - name : 'Best Blackburn', - email : 'blackburn.best@beadzza.me', - phone : '+1-814-498-3701', - title : 'Senior Developer' - }, - { - id : '8bb0f597-673a-47ca-8c77-2f83219cb9af', - avatar: 'assets/images/avatars/male-14.jpg', - name : 'Duncan Carver', - email : 'duncancarver@mail.info', - phone : '+1-968-547-2111', - title : 'Senior Developer' - }, - { - id : 'c318e31f-1d74-49c5-8dae-2bc5805e2fdb', - avatar: 'assets/images/avatars/male-01.jpg', - name : 'Martin Richards', - email : 'martinrichards@mail.biz', - phone : '+1-902-500-2668', - title : 'Junior Developer' - }, - { - id : '0a8bc517-631a-4a93-aacc-000fa2e8294c', - avatar: 'assets/images/avatars/female-20.jpg', - name : 'Candice Munoz', - email : 'candicemunoz@mail.co.uk', - phone : '+1-838-562-2769', - title : 'Lead Designer' - }, - { - id : 'a4c9945a-757b-40b0-8942-d20e0543cabd', - avatar: 'assets/images/avatars/female-01.jpg', - name : 'Vickie Mosley', - email : 'vickiemosley@mail.net', - phone : '+1-939-555-3054', - title : 'Designer' - }, - { - id : 'b8258ccf-48b5-46a2-9c95-e0bd7580c645', - avatar: 'assets/images/avatars/female-02.jpg', - name : 'Tina Harris', - email : 'tinaharris@mail.ca', - phone : '+1-933-464-2431', - title : 'Designer' - }, - { - id : 'f004ea79-98fc-436c-9ba5-6cfe32fe583d', - avatar: 'assets/images/avatars/male-02.jpg', - name : 'Holt Manning', - email : 'holtmanning@mail.org', - phone : '+1-822-531-2600', - title : 'Marketing Manager' - }, - { - id : '8b69fe2d-d7cc-4a3d-983d-559173e37d37', - avatar: 'assets/images/avatars/female-03.jpg', - name : 'Misty Ramsey', - email : 'mistyramsey@mail.us', - phone : '+1-990-457-2106', - title : 'Consultant' - } - ] - } - // return this._httpClient.get('api/dashboards/project').pipe( - // tap((response: any) => { - // this._data.next(response); - // }) - // ); - return project + return this._httpClient.get(environment.apiURL + 'business/getsubscribers').pipe( + tap((response: any) => { + this._data.next(response); + }) + ); + } + filterFollowers(name: string): TesoUserDetails[] { + return this._data.getValue().filter(p => p.firstname.toLowerCase().includes(name) || p.surname.toLowerCase().includes(name) ||p.username.toLowerCase().includes(name)); } } diff --git a/src/app/pages/admin/Monthly_Desires/ListDesires/list-desires.component.html b/src/app/pages/admin/Monthly_Desires/ListDesires/list-desires.component.html index 1df4eb9..50a29d7 100644 --- a/src/app/pages/admin/Monthly_Desires/ListDesires/list-desires.component.html +++ b/src/app/pages/admin/Monthly_Desires/ListDesires/list-desires.component.html @@ -5,7 +5,7 @@
-
Products
+
Monthly Desires
Here is a list of all products in your Teso (850)
@@ -21,7 +21,7 @@
-
Products
+
Monthly Desires
(850) products
@@ -41,18 +41,18 @@
- - +
diff --git a/src/app/pages/admin/Monthly_Desires/ListDesires/list-desires.component.scss b/src/app/pages/admin/Monthly_Desires/ListDesires/list-desires.component.scss index c1616f3..32de181 100644 --- a/src/app/pages/admin/Monthly_Desires/ListDesires/list-desires.component.scss +++ b/src/app/pages/admin/Monthly_Desires/ListDesires/list-desires.component.scss @@ -257,8 +257,7 @@ img { } .product-price:first-of-type { - text-decoration: line-through; - color: #40c9a2; + color: #003445; } .product-img img { diff --git a/src/app/pages/admin/Monthly_Desires/ListDesires/list-desires.component.ts b/src/app/pages/admin/Monthly_Desires/ListDesires/list-desires.component.ts index 23fe0a8..d1c5da6 100644 --- a/src/app/pages/admin/Monthly_Desires/ListDesires/list-desires.component.ts +++ b/src/app/pages/admin/Monthly_Desires/ListDesires/list-desires.component.ts @@ -5,10 +5,14 @@ import { MatSort } from '@angular/material/sort'; import { Router } from '@angular/router'; import { ConfirmBoxEvokeService } from '@costlydeveloper/ngx-awesome-popup'; import { tesoMediaWatcherService } from '@teso/services/media-watcher'; +import { DesiredList, DesiredProduct } from 'app/models/productsModel'; +import { environment } from 'environments/environment'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { AdminCouponDialogComponent } from '../../Products/AdminCouponDialog/admin-coupon-dialog.component'; import { CouponDialogComponent } from '../../Products/CouponDialog/coupon-dialog.component'; +import { ProductsService } from '../../Products/products.service'; +import { DesiresService } from '../desires.service'; @Component({ selector: 'app-list-desires', @@ -17,13 +21,15 @@ import { CouponDialogComponent } from '../../Products/CouponDialog/coupon-dialog }) export class ListDesiresComponent implements OnInit { - data: { teamproducts: { id: string; image: string; name: string; email: string; phone: string; title: string; }[]; }; + data: DesiredList; @ViewChild(MatPaginator) private _paginator: MatPaginator; @ViewChild(MatSort) private _sort: MatSort; isScreenSmall: boolean; + availableP:any[]=[]; private _unsubscribeAll: Subject = new Subject(); constructor(private router: Router, private _tesoMediaWatcherService: tesoMediaWatcherService, - public dialog: MatDialog, private confirmBoxEvokeService: ConfirmBoxEvokeService) { } + public dialog: MatDialog, private confirmBoxEvokeService: ConfirmBoxEvokeService, + private _desireService: DesiresService,private _productService: ProductsService) { } ngOnDestroy(): void { // Unsubscribe from all subscriptions @@ -40,115 +46,37 @@ export class ListDesiresComponent implements OnInit { // Check if the screen is small this.isScreenSmall = !matchingAliases.includes('md'); }); - this.data = { - teamproducts: [ - { - id: '2bfa2be5-7688-48d5-b5ac-dc0d9ac97f14', - image: 'assets/images/brands/bagset.png', - name: 'Nadia Mcknight', - email: 'nadiamcknight@mail.com', - phone: '+1-943-511-2203', - title: 'Project Director' - }, - { - id: '77a4383b-b5a5-4943-bc46-04c3431d1566', - image: 'assets/images/brands/bagset.png', - name: 'Best Blackburn', - email: 'blackburn.best@beadzza.me', - phone: '+1-814-498-3701', - title: 'Senior Developer' - }, - { - id: '8bb0f597-673a-47ca-8c77-2f83219cb9af', - image: 'assets/images/brands/bagset.png', - name: 'Duncan Carver', - email: 'duncancarver@mail.info', - phone: '+1-968-547-2111', - title: 'Senior Developer' - }, - { - id: 'c318e31f-1d74-49c5-8dae-2bc5805e2fdb', - image: 'assets/images/brands/bagset.png', - name: 'Martin Richards', - email: 'martinrichards@mail.biz', - phone: '+1-902-500-2668', - title: 'Junior Developer' - }, - { - id: '0a8bc517-631a-4a93-aacc-000fa2e8294c', - image: 'assets/images/brands/bagset.png', - name: 'Candice Munoz', - email: 'candicemunoz@mail.co.uk', - phone: '+1-838-562-2769', - title: 'Lead Designer' - }, - { - id: 'a4c9945a-757b-40b0-8942-d20e0543cabd', - image: 'assets/images/brands/bagset.png', - name: 'Vickie Mosley', - email: 'vickiemosley@mail.net', - phone: '+1-939-555-3054', - title: 'Designer' - }, - { - id: 'b8258ccf-48b5-46a2-9c95-e0bd7580c645', - image: 'assets/images/brands/bagset.png', - name: 'Tina Harris', - email: 'tinaharris@mail.ca', - phone: '+1-933-464-2431', - title: 'Designer' - }, - { - id: 'f004ea79-98fc-436c-9ba5-6cfe32fe583d', - image: 'assets/images/brands/bagset.png', - name: 'Holt Manning', - email: 'holtmanning@mail.org', - phone: '+1-822-531-2600', - title: 'Marketing Manager' - }, - { - id: '8b69fe2d-d7cc-4a3d-983d-559173e37d37', - image: 'assets/images/brands/bagset.png', - name: 'Misty Ramsey', - email: 'mistyramsey@mail.us', - phone: '+1-990-457-2106', - title: 'Consultant' - } - ] - } + + this._desireService.data$.pipe(takeUntil(this._unsubscribeAll)).subscribe((data: DesiredList) => { + this.data = data; + this.availableP = data.availableProducts.map(p => p.productID); + }); + } createProduct() { this.router.navigate(['products/create-product']); } - editProduct(productID: any) { - this.router.navigate(['products/' + productID]); - } + generateCoupon(product: any) { + + const selectedproduct = this._productService.getProduct(product); if (!true) { const dialogRef = this.dialog.open(CouponDialogComponent, { disableClose: true, hasBackdrop: true, - data: { product: product }, + data: { product: selectedproduct }, }); } else { const dialogRef = this.dialog.open(AdminCouponDialogComponent, { disableClose: true, hasBackdrop: true, - data: { product: product }, + data: { product: selectedproduct }, }); } } - deleteProduct(product: any) { - this.confirmBoxEvokeService.danger("Delete Product", - "Are you sure you would like to delete this product from your inventory ?", - "Yes", "No") - .subscribe((response: any) => { - console.log(response) - if (response.clickedButtonID === "yes") { - this.data.teamproducts = this.data.teamproducts.filter((e) => e == product); - } - }); + imageLoader(path: string): string { + return environment.apiURL + `imagingproducts/${path}`; } } diff --git a/src/app/pages/admin/Monthly_Desires/desires.resolvers.ts b/src/app/pages/admin/Monthly_Desires/desires.resolvers.ts new file mode 100644 index 0000000..e97889c --- /dev/null +++ b/src/app/pages/admin/Monthly_Desires/desires.resolvers.ts @@ -0,0 +1,32 @@ +import { Injectable } from '@angular/core'; +import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router'; +import { Observable } from 'rxjs'; +import { DesiresService } from './desires.service'; + +@Injectable({ + providedIn: 'root' +}) +export class DesiresResolver implements Resolve +{ + /** + * Constructor + */ + constructor(private _desiresService: DesiresService) + { + } + + // ----------------------------------------------------------------------------------------------------- + // @ Public methods + // ----------------------------------------------------------------------------------------------------- + + /** + * Resolver + * + * @param route + * @param state + */ + resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable + { + return this._desiresService.getData(); + } +} diff --git a/src/app/pages/admin/Monthly_Desires/desires.routing.ts b/src/app/pages/admin/Monthly_Desires/desires.routing.ts index 0fd1ea2..b88e08f 100644 --- a/src/app/pages/admin/Monthly_Desires/desires.routing.ts +++ b/src/app/pages/admin/Monthly_Desires/desires.routing.ts @@ -2,15 +2,16 @@ import { Route } from '@angular/router'; import { EditProductComponent } from '../Products/EditProduct/edit-product.component'; import { NewProductComponent } from '../Products/NewProduct/new-product.component'; import { DesiresComponent } from './desires.component'; +import { DesiresResolver } from './desires.resolvers'; import { ListDesiresComponent } from './ListDesires/list-desires.component'; export const desiresRoutes: Route[] = [ { path : '', component: DesiresComponent, - // resolve : { - // data: FollowersResolver - // } + resolve : { + data: DesiresResolver + }, children : [ { path : '', diff --git a/src/app/pages/admin/Monthly_Desires/desires.service.ts b/src/app/pages/admin/Monthly_Desires/desires.service.ts new file mode 100644 index 0000000..3133d69 --- /dev/null +++ b/src/app/pages/admin/Monthly_Desires/desires.service.ts @@ -0,0 +1,49 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { BehaviorSubject, Observable } from 'rxjs'; +import { tap } from 'rxjs/operators'; +import { analytics as analyticsData } from 'app/mock-api/dashboards/analytics/data'; +import { environment } from 'environments/environment'; +import { DesiredList, DesiredProduct, ProductCategory, ProductsModel } from 'app/models/productsModel'; + +@Injectable({ + providedIn: 'root' +}) +export class DesiresService { + private _data: BehaviorSubject = new BehaviorSubject(null); + + + /** + * Constructor + */ + constructor(private _httpClient: HttpClient) { + } + + // ----------------------------------------------------------------------------------------------------- + // @ Accessors + // ----------------------------------------------------------------------------------------------------- + + /** + * Getter for data + */ + get data$(): Observable { + return this._data.asObservable(); + } + + + // ----------------------------------------------------------------------------------------------------- + // @ Public methods + // ----------------------------------------------------------------------------------------------------- + + /** + * Get data + */ + getData(): Observable { + return this._httpClient.get(environment.apiURL + `desires/pull-monthly`).pipe( + tap((response: DesiredList) => { + this._data.next(response); + + }) + ); + } +} diff --git a/src/app/pages/admin/Products/AdminCouponDialog/admin-coupon-dialog.component.html b/src/app/pages/admin/Products/AdminCouponDialog/admin-coupon-dialog.component.html index 17f738a..6ec0998 100644 --- a/src/app/pages/admin/Products/AdminCouponDialog/admin-coupon-dialog.component.html +++ b/src/app/pages/admin/Products/AdminCouponDialog/admin-coupon-dialog.component.html @@ -1,12 +1,12 @@
-

Coupons for {{data.product.name}}

+

Coupons for {{data.product.productName}}

-
+
@@ -15,7 +15,7 @@
- Target Name + {{businessTargetted.businessName}}
@@ -24,12 +24,12 @@
- Target Name + Product Name
- Target Name + {{data.product.productName}}
@@ -41,7 +41,7 @@
- GH¢200 + {{data.product.unitPrice | currency:"GHS "}}
@@ -53,12 +53,12 @@
- - Freebie - Discount - Proximity Freebie - Proximity Discount + + + {{type.typeName}} + +
@@ -126,4 +126,126 @@
+
+
+
+ + Target Business + +
+
+ + {{businessTargetted.businessName}} + + +
+
+
+
+
+ + Product Name + +
+
+ + {{data.product.productName}} + +
+
+
+
+ + Original Price + +
+
+ + {{data.product.unitPrice | currency:"GHS "}} + +
+
+
+ +
+ + + Coupon Type + + + + {{type.typeName}} + + + + +
+
+ +
+
+ + Coupon Condition + +
+
+ +
+
+
+ +
+ + + Number Of Coupons + + + +
+ +
+ + Percentage Off + +
+ + From   + + %   + +
+
+ + To   + + %   + +
+
+ + Coupon Worth + + + From GH¢200 To GH¢800 + +
+
+ + + Date Of Expiration + + + +
+
+ + Time   + + +
+
+ + +
+
\ No newline at end of file diff --git a/src/app/pages/admin/Products/AdminCouponDialog/admin-coupon-dialog.component.ts b/src/app/pages/admin/Products/AdminCouponDialog/admin-coupon-dialog.component.ts index 8a5c9e5..026cd88 100644 --- a/src/app/pages/admin/Products/AdminCouponDialog/admin-coupon-dialog.component.ts +++ b/src/app/pages/admin/Products/AdminCouponDialog/admin-coupon-dialog.component.ts @@ -1,17 +1,45 @@ -import { Component, Inject, OnInit } from '@angular/core'; +import { Component, Inject, OnDestroy, OnInit } from '@angular/core'; import { MatDialog, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { ConfirmBoxEvokeService } from '@costlydeveloper/ngx-awesome-popup'; +import { tesoMediaWatcherService } from '@teso/services/media-watcher'; +import { TesoBusinessDetail } from 'app/models/businessModel'; +import { CouponsType } from 'app/models/couponsModel'; +import { ProductsModel } from 'app/models/productsModel'; +import { Subject } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; +import { CouponsService } from '../../Coupons/coupons.service'; import { BusinessLookUpComponent } from '../BusinessLookUp/business-look-up.component'; +import { ProductsService } from '../products.service'; @Component({ selector: 'admin-coupon-dialog', templateUrl: './admin-coupon-dialog.component.html', styleUrls: ['./admin-coupon-dialog.component.scss'] }) -export class AdminCouponDialogComponent implements OnInit { - - constructor(@Inject(MAT_DIALOG_DATA) public data: { product: any }, public dialog: MatDialog,) { } +export class AdminCouponDialogComponent implements OnInit,OnDestroy { + businessTargetted:TesoBusinessDetail={}; + private _unsubscribeAll: Subject = new Subject(); + isLoading:boolean=false; + selectedProduct:any={}; + selectedType:any={}; + couponTypes:CouponsType[]=[]; + isScreenSmall: boolean; + constructor( + private _couponService: CouponsService,@Inject(MAT_DIALOG_DATA) public data: { product: ProductsModel }, + public dialog: MatDialog,private _tesoMediaWatcherService: tesoMediaWatcherService, + private confirmBoxEvokeService: ConfirmBoxEvokeService,) { } ngOnInit(): void { + this._couponService.categories$.pipe(takeUntil(this._unsubscribeAll)).subscribe((d) => { + this.couponTypes = d; + }); + this._tesoMediaWatcherService.onMediaChange$ + .pipe(takeUntil(this._unsubscribeAll)) + .subscribe(({ matchingAliases }) => { + + // Check if the screen is small + this.isScreenSmall = !matchingAliases.includes('md'); + }); } lookupBusiness() { const dialogRef = this.dialog.open(BusinessLookUpComponent, { @@ -19,5 +47,13 @@ export class AdminCouponDialogComponent implements OnInit { hasBackdrop: true, }); + dialogRef.afterClosed().subscribe((result) => { + this.businessTargetted = result; + }); + } + ngOnDestroy(): void { + // Unsubscribe from all subscriptions + this._unsubscribeAll.next(); + this._unsubscribeAll.complete(); } } diff --git a/src/app/pages/admin/Products/BusinessLookUp/business-look-up.component.html b/src/app/pages/admin/Products/BusinessLookUp/business-look-up.component.html index d61d73b..d783e01 100644 --- a/src/app/pages/admin/Products/BusinessLookUp/business-look-up.component.html +++ b/src/app/pages/admin/Products/BusinessLookUp/business-look-up.component.html @@ -6,7 +6,7 @@ - +