{ "version": 3, "sources": ["apps/partner-center-client/src/app/assigned-salesperson/assigned-salesperson.service.ts"], "sourcesContent": ["import { Inject, Injectable } from '@angular/core';\nimport { MatDialogConfig } from '@angular/material/dialog';\nimport { Salesperson, SalespersonService } from '@vendasta/sales';\nimport { combineLatest, Observable, of } from 'rxjs';\nimport { catchError, delay, map, mergeMap, publishReplay, refCount, retryWhen, switchMap } from 'rxjs/operators';\nimport { AppConfigService } from '../app-config.service';\n\nconst DEFAULT_IMAGE_URL =\n 'https://lh3.googleusercontent.com/70DGcv8fyAzy1n_cWh8GyVbsCIWzPGZMdBFiwJa8Ot-Ss5Rf_oZY8hKOG2wAttY4_iuU5TlO9NLlDrBGuEJBj6DHwRnGd2CJ32J2Im3c1g';\n\n@Injectable()\nexport class AssignedSalespersonService {\n salesperson$: Observable;\n dialogConfig$: Observable;\n bookMeetingUrl$: Observable;\n\n defaultImageUrl = DEFAULT_IMAGE_URL;\n delayTimes = [5, 5, 10, 10, 30, 30, 30, 60, 60, 60, 80];\n\n constructor(\n private readonly salespersonService: SalespersonService,\n private readonly configService: AppConfigService,\n @Inject('PARTNER_ID') private readonly partnerId$: Observable,\n @Inject('MARKET_ID') private readonly marketId$: Observable,\n ) {\n let newPartner = false;\n const assignedSalesPerson$: Observable<{ accountGroupId: string; salesperson: Salesperson }> = combineLatest([\n this.partnerId$,\n this.marketId$,\n this.configService.config$,\n ]).pipe(\n switchMap(([partnerId, marketId, partnerConfig]) => {\n if (partnerConfig.partnerCreated) {\n // check if partner was created within 1 day.\n const today = new Date();\n if (today.setDate(today.getDate() - 1) < partnerConfig.partnerCreated * 1000) {\n newPartner = true;\n }\n }\n return this.salespersonService.getAssignedSalespersonForPartner(partnerId, marketId || null);\n }),\n retryWhen((attempts) => {\n return attempts.pipe(\n mergeMap((error, i) => {\n if (!newPartner || i >= this.delayTimes.length || error.status >= 500) {\n throw new Error('Could not retrieve salesperson.');\n } else {\n return of(error).pipe(delay(this.delayTimes[i] * 1000));\n }\n }),\n );\n }),\n publishReplay(1),\n refCount(),\n );\n\n this.salesperson$ = assignedSalesPerson$.pipe(\n map((a) => a?.salesperson),\n catchError(() => of(null)),\n publishReplay(1),\n refCount(),\n );\n\n const businessId$ = assignedSalesPerson$.pipe(\n map((as) => as.accountGroupId),\n catchError(() => of(null)),\n publishReplay(1),\n refCount(),\n );\n\n this.dialogConfig$ = combineLatest([businessId$, this.salesperson$]).pipe(\n map(([businessId, salesperson]) => {\n if (salesperson) {\n const dialogConfig = new MatDialogConfig();\n dialogConfig.disableClose = false;\n dialogConfig.autoFocus = true;\n dialogConfig.width = '550px';\n dialogConfig.maxHeight = '400px';\n dialogConfig.data = {\n imgUrl: salesperson?.photoUrlHttps,\n name: `${salesperson?.firstName || ''} ${salesperson?.lastName || ''}`.trim(),\n title: salesperson?.jobTitle,\n telephone: salesperson?.phoneNumber?.length > 0 ? salesperson.phoneNumber[0] : '',\n country: salesperson?.countryCode,\n salespersonId: salesperson?.salespersonId,\n businessId: businessId,\n };\n return dialogConfig;\n }\n }),\n publishReplay(1),\n refCount(),\n );\n\n this.bookMeetingUrl$ = this.salesperson$.pipe(map((sp) => sp?.meetingBookingUrl || ''));\n }\n}\n"], "mappings": "mPAOA,IAAMA,EACJ,+IAGWC,GAA0B,IAAA,CAAjC,IAAOA,EAAP,MAAOA,CAA0B,CAQrCC,YACmBC,EACAC,EACsBC,EACDC,EAA6B,CAHlD,KAAAH,mBAAAA,EACA,KAAAC,cAAAA,EACsB,KAAAC,WAAAA,EACD,KAAAC,UAAAA,EAPxC,KAAAC,gBAAkBP,EAClB,KAAAQ,WAAa,CAAC,EAAG,EAAG,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,EAAE,EAQpD,IAAIC,EAAa,GACXC,EAAyFC,EAAc,CAC3G,KAAKN,WACL,KAAKC,UACL,KAAKF,cAAcQ,OAAO,CAC3B,EAAEC,KACDC,EAAU,CAAC,CAACC,EAAWC,EAAUC,CAAa,IAAK,CACjD,GAAI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auB,aAAajC,OAAS,EAAIU,EAAYuB,YAAY,CAAC,EAAI,GAC/EC,QAASxB,GAAayB,YACtBC,cAAe1B,GAAa0B,cAC5BpB,WAAYA,GAEPC,CACT,CACF,CAAC,EACDZ,EAAc,CAAC,EACfC,EAAQ,CAAE,EAGZ,KAAK+B,gBAAkB,KAAK9B,aAAavB,KAAKwB,EAAK8B,GAAOA,GAAIC,mBAAqB,EAAE,CAAC,CACxF,yCApFWnE,GAA0BoE,EAAAC,CAAA,EAAAD,EAAAE,CAAA,EAAAF,EAW3B,YAAY,EAAAA,EACZ,WAAW,CAAA,CAAA,wBAZVpE,EAA0BuE,QAA1BvE,EAA0BwE,SAAA,CAAA,EAAjC,IAAOxE,EAAPyE,SAAOzE,CAA0B,GAAA", "names": ["DEFAULT_IMAGE_URL", "AssignedSalespersonService", "constructor", "salespersonService", "configService", "partnerId$", "marketId$", "defaultImageUrl", "delayTimes", "newPartner", "assignedSalesPerson$", "combineLatest", "config$", "pipe", "switchMap", "partnerId", "marketId", "partnerConfig", "partnerCreated", "today", "Date", "setDate", "getDate", "getAssignedSalespersonForPartner", "retryWhen", "attempts", "mergeMap", "error", "i", "length", "status", "Error", "of", "delay", "publishReplay", "refCount", "salesperson$", "map", "a", "salesperson", "catchError", "businessId$", "as", "accountGroupId", "dialogConfig$", "businessId", "dialogConfig", "MatDialogConfig", "disableClose", "autoFocus", "width", "maxHeight", "data", "imgUrl", "photoUrlHttps", "name", "firstName", "lastName", "trim", "title", "jobTitle", "telephone", "phoneNumber", "country", "countryCode", "salespersonId", "bookMeetingUrl$", "sp", "meetingBookingUrl", "\u0275\u0275inject", "SalespersonService", "AppConfigService", "factory", "\u0275fac", "_AssignedSalespersonService"] }