@@ -475,8 +475,20 @@ document.addEventListener('DOMContentLoaded', function () {
475475 projectNameInput . addEventListener ( 'input' , function ( ) {
476476 chrome . storage . local . set ( { projectName : projectNameInput . value } ) ;
477477 } ) ;
478- orgInput . addEventListener ( 'input' , function ( ) {
479- chrome . storage . local . set ( { orgName : orgInput . value . trim ( ) . toLowerCase ( ) } ) ;
478+
479+ // Save to storage and validate ONLY when user clicks out (blur event)
480+ orgInput . addEventListener ( 'blur' , function ( ) {
481+ const org = orgInput . value . trim ( ) . toLowerCase ( ) ;
482+ chrome . storage . local . set ( { orgName : org } ) ;
483+
484+ // Only validate if org name is not empty
485+ if ( org ) {
486+ validateOrgOnBlur ( org ) ;
487+ } else {
488+ // Clear any existing toast if org is empty
489+ const oldToast = document . getElementById ( 'invalid-org-toast' ) ;
490+ if ( oldToast ) oldToast . parentNode . removeChild ( oldToast ) ;
491+ }
480492 } ) ;
481493 userReasonInput . addEventListener ( 'input' , function ( ) {
482494 chrome . storage . local . set ( { userReason : userReasonInput . value } ) ;
@@ -1527,17 +1539,9 @@ async function triggerRepoFetchIfEnabled() {
15271539 }
15281540}
15291541
1530- const handleOrgInput = debounce ( function ( ) {
1531- let org = orgInput . value . trim ( ) . toLowerCase ( ) ;
1532- if ( ! org ) {
1533- chrome . storage . local . set ( { orgName : '' } , ( ) => {
1534- console . log ( `Org cleared, triggering repo fetch for all git` ) ;
1535- chrome . storage . local . remove ( [ 'githubCache' , 'repoCache' ] ) ;
1536- triggerRepoFetchIfEnabled ( ) ;
1537- } )
1538- return ;
1539- }
1540- console . log ( '[Org Check] Checking organization:' , org ) ;
1542+ // Validate organization only when user is done typing (on blur)
1543+ function validateOrgOnBlur ( org ) {
1544+ console . log ( '[Org Check] Checking organization on blur:' , org ) ;
15411545 fetch ( `https://api.github.com/orgs/${ org } ` )
15421546 . then ( res => {
15431547 console . log ( '[Org Check] Response status for' , org , ':' , res . status ) ;
@@ -1568,10 +1572,8 @@ const handleOrgInput = debounce(function () {
15681572 const oldToast = document . getElementById ( 'invalid-org-toast' ) ;
15691573 if ( oldToast ) oldToast . parentNode . removeChild ( oldToast ) ;
15701574 console . log ( '[Org Check] Organisation exists on GitHub:' , org ) ;
1571- chrome . storage . local . set ( { orgName : org } , function ( ) {
1572- // if (window.generateScrumReport) window.generateScrumReport();
1573- triggerRepoFetchIfEnabled ( ) ;
1574- } ) ;
1575+ chrome . storage . local . remove ( [ 'githubCache' , 'repoCache' ] ) ;
1576+ triggerRepoFetchIfEnabled ( ) ;
15751577 } )
15761578 . catch ( ( err ) => {
15771579 console . log ( '[Org Check] Error validating organisation:' , org , err ) ;
@@ -1596,6 +1598,4 @@ const handleOrgInput = debounce(function () {
15961598 if ( toastDiv . parentNode ) toastDiv . parentNode . removeChild ( toastDiv ) ;
15971599 } , 3000 ) ;
15981600 } ) ;
1599- } , 500 ) ;
1600-
1601- orgInput . addEventListener ( 'input' , handleOrgInput ) ;
1601+ }
0 commit comments