From c319a96fb3df7b346c5f94391f3733ed77ae48c0 Mon Sep 17 00:00:00 2001 From: Sibin Sabu Date: Fri, 19 Sep 2025 14:36:54 +0530 Subject: [PATCH] fix : added print for login --- btc-UI/src/app/login/login.component.ts | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/btc-UI/src/app/login/login.component.ts b/btc-UI/src/app/login/login.component.ts index 8355fb8..cdbe822 100755 --- a/btc-UI/src/app/login/login.component.ts +++ b/btc-UI/src/app/login/login.component.ts @@ -240,6 +240,14 @@ async onSubmit(): Promise { const btid = this.btcService.btid; console.log("📦 BTID from file (via service):", btid); + + const printData = { + name: userName, + employeeId: employeeId, + action: 'login', + type: 'login' + }; + // ✅ Store in localStorage localStorage.setItem('userName', userName); localStorage.setItem('employeeId', employeeId); @@ -265,6 +273,26 @@ async onSubmit(): Promise { this.loginError = "Could not load race card."; } }); + // ✅ Print first — login only if printing succeeds + fetch('http://localhost:9100/print', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(printData), + }) + .then((res) => { + if (!res.ok) throw new Error('Print failed'); + console.log('🖨️ Print successful'); + + // ✅ Only here we allow login + (window as any).electronAPI?.openSecondScreen?.(); + this.router.navigate(['/home']); + }) + .catch((err) => { + console.error('‼️ Print failed', err); + this.loginError = 'Login failed: printing service unavailable.'; + this.passwordStatus = false; // reset status + }); + }, error: () => { this.loginError = 'Invalid login credentials';