Skip to content

Commit

Permalink
Improves the method that display the runned out quotas banner
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicola Lanzilotto committed Nov 28, 2024
1 parent 1de6afc commit 357b3f7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/app/home/home.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3351,6 +3351,7 @@ img {
align-items: center;
justify-content: center;
gap: 6px;
padding-bottom: 18px;
}

.hqb-footer-link {
Expand Down
68 changes: 38 additions & 30 deletions src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class HomeComponent implements OnInit, OnDestroy, AfterViewInit {
tokens_limit = 0;

project_limits: any;

quotes: any;
conversationsRunnedOut: boolean = false;
emailsRunnedOut: boolean = false;
tokensRunnedOut: boolean = false;
Expand Down Expand Up @@ -471,6 +471,7 @@ export class HomeComponent implements OnInit, OnDestroy, AfterViewInit {
getQuotes() {
this.quotesService.getAllQuotes(this.projectId).subscribe((resp: any) => {
this.logger.log("[HOME] getAllQuotes response: ", resp)
this.quotes = resp

this.logger.log("[HOME] project_limits: ", this.project_limits)
this.logger.log("[HOME] resp.quotes: ", resp.quotes)
Expand Down Expand Up @@ -510,35 +511,7 @@ export class HomeComponent implements OnInit, OnDestroy, AfterViewInit {
this.logger.log('[HOME] used tokens', resp.quotes.tokens.quote)
this.logger.log('[HOME] tokens_limit', this.tokens_limit)

if (resp.quotes.requests.quote >= this.requests_limit) {
this.conversationsRunnedOut = true;
this.logger.log('[HOME] conversationsRunnedOut', this.conversationsRunnedOut)
// this.quotesService.hasReachedQuotasLimitInHome(true)
} else {
this.conversationsRunnedOut = false;
// this.quotesService.hasReachedQuotasLimitInHome(false)
this.logger.log('[HOME] conversationsRunnedOut', this.conversationsRunnedOut)
}

if (resp.quotes.email.quote >= this.email_limit) {
this.emailsRunnedOut = true;
this.logger.log('[HOME] emailsRunnedOut', this.emailsRunnedOut)
// this.quotesService.hasReachedQuotasLimitInHome(true)
} else {
this.emailsRunnedOut = false;
// this.quotesService.hasReachedQuotasLimitInHome(false)
this.logger.log('[HOME] emailsRunnedOut', this.emailsRunnedOut)
}

if (resp.quotes.tokens.quote >= this.tokens_limit) {
this.tokensRunnedOut = true;
this.logger.log('[HOME] tokensRunnedOut', this.tokensRunnedOut)
// this.quotesService.hasReachedQuotasLimitInHome(true)
} else {
this.tokensRunnedOut = false;
// this.quotesService.hasReachedQuotasLimitInHome(false)
this.logger.log('[HOME] tokensRunnedOut', this.tokensRunnedOut)
}


this.requests_perc = Math.min(100, Math.floor((resp.quotes.requests.quote / this.requests_limit) * 100));
this.messages_perc = Math.min(100, Math.floor((resp.quotes.messages.quote / this.messages_limit) * 100));
Expand All @@ -554,15 +527,50 @@ export class HomeComponent implements OnInit, OnDestroy, AfterViewInit {
}, (error) => {
this.logger.error("[HOME] get all quotes error: ", error)
this.displayQuotaSkeleton = false


}, () => {
this.logger.log("[HOME] get all quotes *COMPLETE*");
setTimeout(() => {
this.displayQuotaSkeleton = false
this.getRunnedOutQuotes( this.quotes)
}, 1000);

})
}

getRunnedOutQuotes(resp) {
if (resp.quotes.requests.quote >= this.requests_limit) {
this.conversationsRunnedOut = true;
this.logger.log('[HOME] conversationsRunnedOut', this.conversationsRunnedOut)
// this.quotesService.hasReachedQuotasLimitInHome(true)
} else {
this.conversationsRunnedOut = false;
// this.quotesService.hasReachedQuotasLimitInHome(false)
this.logger.log('[HOME] conversationsRunnedOut', this.conversationsRunnedOut)
}

if (resp.quotes.email.quote >= this.email_limit) {
this.emailsRunnedOut = true;
this.logger.log('[HOME] emailsRunnedOut', this.emailsRunnedOut)
// this.quotesService.hasReachedQuotasLimitInHome(true)
} else {
this.emailsRunnedOut = false;
// this.quotesService.hasReachedQuotasLimitInHome(false)
this.logger.log('[HOME] emailsRunnedOut', this.emailsRunnedOut)
}

if (resp.quotes.tokens.quote >= this.tokens_limit) {
this.tokensRunnedOut = true;
this.logger.log('[HOME] tokensRunnedOut', this.tokensRunnedOut)
// this.quotesService.hasReachedQuotasLimitInHome(true)
} else {
this.tokensRunnedOut = false;
// this.quotesService.hasReachedQuotasLimitInHome(false)
this.logger.log('[HOME] tokensRunnedOut', this.tokensRunnedOut)
}
}

contacUsViaEmail() {
window.open(`mailto:${this.salesEmail}?subject=Resource increase request for project ${this.projectName} (${this.projectId}) &body=Dear Sales team, some of my monthly resource quota reached his limit for this month, I need some help!`);
}
Expand Down

0 comments on commit 357b3f7

Please sign in to comment.