@@ -11,8 +11,9 @@ import { LoginInfo } from 'src/app/models/interfaces';
1111import { initFlowbite } from 'flowbite' ;
1212import { EventMessageService } from "../../services/event-message.service" ;
1313import * as moment from 'moment' ;
14- import { Subject } from 'rxjs' ;
14+ import { firstValueFrom , Subject } from 'rxjs' ;
1515import { takeUntil } from 'rxjs/operators' ;
16+ import { QuoteService } from 'src/app/features/quotes/services/quote.service' ;
1617
1718@Component ( {
1819 selector : 'app-seller-offerings' ,
@@ -41,6 +42,7 @@ export class SellerOfferingsComponent implements OnInit, OnDestroy {
4142 serv_to_update :any ;
4243 res_to_update :any ;
4344 offer_to_update :any ;
45+ custom_offer_partyId :any = null ;
4446 catalog_to_update :any ;
4547 feedback :boolean = false ;
4648 userInfo :any ;
@@ -59,7 +61,10 @@ export class SellerOfferingsComponent implements OnInit, OnDestroy {
5961 constructor (
6062 private localStorage : LocalStorageService ,
6163 private cdr : ChangeDetectorRef ,
62- private eventMessage : EventMessageService
64+ private eventMessage : EventMessageService ,
65+ private router : Router ,
66+ private quoteService : QuoteService ,
67+ private api : ApiServiceService
6368 ) {
6469 this . eventMessage . messages$
6570 . pipe ( takeUntil ( this . destroy$ ) )
@@ -114,7 +119,9 @@ export class SellerOfferingsComponent implements OnInit, OnDestroy {
114119 this . goToUpdateOffer ( ) ;
115120 }
116121 if ( ev . type === 'SellerCreateCustomOffer' ) {
117- this . offer_to_update = ev . value ;
122+ const evValue = ev . value as { offer : any , partyId ?: string } ;
123+ this . offer_to_update = evValue . offer ;
124+ this . custom_offer_partyId = evValue . partyId || null ;
118125 this . goToCreateCustomOffer ( ) ;
119126 }
120127 if ( ev . type === 'SellerCatalogUpdate' ) {
@@ -127,14 +134,31 @@ export class SellerOfferingsComponent implements OnInit, OnDestroy {
127134 } )
128135 }
129136
130- ngOnInit ( ) {
137+ async ngOnInit ( ) {
131138 this . userInfo = this . localStorage . getObject ( 'login_items' ) as LoginInfo ;
132139 const saved = localStorage . getItem ( 'activeSection' ) ;
133140 console . log ( saved )
134141 if ( saved ) this . activeSection = saved ;
135142 if ( saved && this . sectionActions [ saved ] ) {
136143 this . sectionActions [ saved ] . call ( this ) ; // bind `this` context
137144 }
145+
146+ const state = history . state as { quoteId ?: string } ;
147+ console . log ( 'Checking state' )
148+ console . log ( state )
149+
150+ if ( state && state . quoteId ) {
151+ // If there's a quoteId in the state, open the offers section
152+ const quote = await firstValueFrom ( this . quoteService . getQuoteById ( state . quoteId ) ) ;
153+ const offerId = quote ?. quoteItem ?. [ 0 ] ?. productOffering ?. id ;
154+ let offer :any = null ;
155+ if ( offerId ) {
156+ offer = await this . api . getProductById ( offerId ) ;
157+ }
158+
159+ const quoteBuyer = quote ?. relatedParty ?. find ( ( party : any ) => party . role . toLowerCase ( ) === environment . BUYER_ROLE . toLowerCase ( ) ) ;
160+ this . eventMessage . emitSellerCreateCustomOffer ( offer , quoteBuyer ?. id ) ;
161+ }
138162 }
139163
140164 ngOnDestroy ( ) {
0 commit comments