@@ -11,7 +11,7 @@ import {
1111import { CommonModule } from "@angular/common" ;
1212import { FormsModule } from "@angular/forms" ;
1313import { Router , NavigationEnd } from "@angular/router" ;
14- import { filter } from "rxjs" ;
14+ import { filter , Observable , Subscription } from "rxjs" ;
1515import { SaleService } from "../../services/sale.service" ;
1616import { CartService } from "../../services/cart.service" ;
1717import { AuthService } from "../../services/auth.service" ;
@@ -117,8 +117,18 @@ export class CashierComponent implements OnInit, AfterViewInit {
117117
118118 onRegisterOpened ( ) : void {
119119 this . closeRegisterModal ( ) ;
120- // Focus calculator after register is opened
121- setTimeout ( ( ) => this . calculator ?. focusCalculator ( ) , 300 ) ;
120+ // Reload the active register to update the state
121+ this . registerService . getActiveRegister ( ) . subscribe ( {
122+ next : ( ) => {
123+ // Focus calculator after register is opened
124+ setTimeout ( ( ) => this . calculator ?. focusCalculator ( ) , 300 ) ;
125+ } ,
126+ error : ( err ) => {
127+ console . error ( "Error reloading register:" , err ) ;
128+ // Still focus calculator even if there's an error
129+ setTimeout ( ( ) => this . calculator ?. focusCalculator ( ) , 300 ) ;
130+ } ,
131+ } ) ;
122132 }
123133
124134 constructor (
@@ -146,18 +156,18 @@ export class CashierComponent implements OnInit, AfterViewInit {
146156 this . scaleConnected . set ( this . scaleService . isConnected ( ) ) ;
147157
148158 // Load active cart from database
149- this . loadActiveCart ( ) ;
150159
151160 // Handle session cleanup when user leaves or closes window
152161 this . setupSessionCleanup ( ) ;
153162 }
154163
155164 ngOnInit ( ) : void {
156165 // Subscribe to register state
157- this . registerService . currentRegister$ . subscribe ( ( register ) => {
158- this . currentRegister . set ( register ) ;
166+ this . loadActiveCart ( ) ?. add ( ( ) => {
167+ this . registerService . currentRegister$ . subscribe ( ( register ) => {
168+ this . currentRegister . set ( register ) ;
169+ } ) ;
159170 } ) ;
160-
161171 // Load active register
162172 this . registerService . getActiveRegister ( ) . subscribe ( ) ;
163173
@@ -214,11 +224,11 @@ export class CashierComponent implements OnInit, AfterViewInit {
214224 navigator . sendBeacon ( apiUrl , formData ) ;
215225 }
216226
217- loadActiveCart ( ) : void {
227+ loadActiveCart ( ) : Subscription | null {
218228 const currentUser = this . authService . getCurrentUser ( ) ;
219- if ( ! currentUser || ! currentUser . id ) return ;
229+ if ( ! currentUser || ! currentUser . id ) return null ;
220230
221- this . cartService . getActiveCart ( currentUser . id ) . subscribe ( {
231+ return this . cartService . getActiveCart ( currentUser . id ) . subscribe ( {
222232 next : ( cart ) => {
223233 if ( cart && cart . items ) {
224234 // Convert cart items to cashier items format
0 commit comments