Skip to content

Commit

Permalink
Merge branch 'features/NEW-REMOVE-FREE-PLAN-PROD'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicola Lanzilotto committed Jan 29, 2025
2 parents 5b47be3 + 07df355 commit 9b303b2
Show file tree
Hide file tree
Showing 41 changed files with 2,442 additions and 150 deletions.
141 changes: 116 additions & 25 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { BrandService } from './services/brand.service';
import { ScriptService } from './services/script/script.service';
import { LoggerService } from './services/logger/logger.service';
import { NotifyService } from './core/notify.service';
import { avatarPlaceholder, getColorBck } from './utils/util';
import { avatarPlaceholder, freePlanLimitDate, getColorBck } from './utils/util';
import { LocalDbService } from './services/users-local-db.service';
import { ProjectService } from './services/project.service';
import { HttpClient } from '@angular/common/http';
Expand Down Expand Up @@ -113,9 +113,16 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
) {
this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
// this.logger.log('NavigationEnd event ', event)
this.logger.log('[APP-COMPONENT] - NavigationEnd event ', event)
gtag('config', 'G-3DMYV3HG61', { 'page_path': event.urlAfterRedirects });

if (event.urlAfterRedirects !== '/projects' && event.urlAfterRedirects !== '/login' && event.urlAfterRedirects !== '/signup' && event.urlAfterRedirects !== '/create-new-project') {
this.logger.log('[APP-COMPONENT] ------> calling GET CURRENT PROJECT ')
this.getCurrentProject(event.urlAfterRedirects)
}



const grecaptchaBadgeEl = <HTMLElement>document.querySelector('.grecaptcha-badge');
if (event.url !== '/signup') {
// this.logger.log('[APP-COMPONENT] grecaptchaBadgeEl ', grecaptchaBadgeEl)
Expand Down Expand Up @@ -245,16 +252,15 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
this.subscription = router.events.subscribe((event) => {
if (event instanceof NavigationStart) {
browserRefresh = !router.navigated;
this.logger.log('APP-COMP browserRefresh ', browserRefresh)
this.logger.log('[APP-COMPONENT] browserRefresh ', browserRefresh)
this.logger.log('[APP-COMPONENT] browserRefresh ', event)
if (browserRefresh === true) {
window.addEventListener('load', () => {
this.logger.log('Page fully loaded');

// Check if there is the sleelplan chagenlog live announcemnt popup
this.checkSPPopupIframeWithRetries(5, 1000); // Retry 5 times with a 1-second delay
});


}
}
});
Expand All @@ -269,7 +275,7 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy {

const checkForIframe = () => {
attempts++;
this.logger.log(`Attempt ${attempts} to find the iframe...`);
this.logger.log(`Attempt ${attempts} to find the iframe...`);

const wrapper = document.getElementById('sleek-widget-wrap');
this.logger.log('wrapper 1', wrapper)
Expand Down Expand Up @@ -436,24 +442,109 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy {



// getCurrentProject() {
// this.auth.project_bs.subscribe((project) => {
// if (project) {
// this.logger.log('[APP-COMPONENT] project from $ubscription ', project)
// // this.current_selected_prjct = project
// this.projectService.getProjects().subscribe((projects: any) => {
// this.logger.log('[APP-COMPONENT] getProjects projects ', projects)
// if (projects) {
// this.current_selected_prjct_user = projects.find(prj => prj.id_project.id === project._id);
// this.logger.log('[APP-COMPONENT] current_selected_prjct_user ', this.current_selected_prjct_user)
getCurrentProject(url) {
// this.logger.log('[APP-COMPONENT] calling --- GET CURRENT PROJECT ---- - url 1', url)
this.logger.log('[APP-COMPONENT] calling --- GET CURRENT PROJECT ---- - this.auth.user_bs.value 1 ', this.auth.user_bs.value)
this.auth.project_bs.subscribe((project) => {
if (project) {
this.logger.log('[APP-COMPONENT] -->> project from $ubscription 1 ', project)
// this.current_selected_prjct = project
this.projectService.getProjects().subscribe((projects: any) => {
this.logger.log('[APP-COMPONENT] getProjects projects ', projects)
if (projects) {
this.current_selected_prjct_user = projects.find(prj => prj.id_project.id === project._id);
this.logger.log('[APP-COMPONENT] -->> current_selected_prjct_user 1', this.current_selected_prjct_user)
if (this.current_selected_prjct_user) {


this.redirectToPricing(this.current_selected_prjct_user)


}

}
})
} else {
this.logger.log('[APP-COMPONENT] calling --- GET CURRENT PROJECT ---- - url 2', url)
this.logger.log('[APP-COMPONENT] calling --- GET CURRENT PROJECT ---- - project 2 ', project)
this.logger.log('[APP-COMPONENT] calling --- GET CURRENT PROJECT ---- - this.auth.user_bs.value 2 ', this.auth.user_bs.value)
this.logger.log('[APP-COMPONENT] calling --- GET CURRENT PROJECT ---- - this.auth.hasChangedProject.value 2 ', this.auth.hasChangedProject.value)
if (!project && this.auth.user_bs.value && this.auth.hasChangedProject.value === false) {
const url_segments = url.split('/');
const nav_project_id = url_segments[2];
this.logger.log('[APP-COMPONENT] -->> project from $ubscription 2 nav_project_id', nav_project_id)

const navProjectIdContainsNumber = this.containsNumber(nav_project_id)
this.logger.log('[APP-COMPONENT] -->> project from $ubscription 2 projectIdIsNumber', navProjectIdContainsNumber)

if (navProjectIdContainsNumber === true) {
this.projectService.getProjects().subscribe((projects: any) => {
this.logger.log('[APP-COMPONENT] getProjects projects ', projects)
if (projects) {
this.current_selected_prjct_user = projects.find(prj => prj.id_project.id === nav_project_id);
this.logger.log('[APP-COMPONENT] current_selected_prjct_user 2', this.current_selected_prjct_user)
this.logger.log('[APP-COMPONENT] calling --- GET CURRENT PROJECT ---- - this.auth.user_bs.value 3 ', this.auth.user_bs.value)
if (this.current_selected_prjct_user) {
this.redirectToPricing(this.current_selected_prjct_user)
}
}
})
}
}
}
});
}

redirectToPricing(projectUser) {
this.logger.log('[APP-COMPONENT] REDIRECT TO PRICING - projectUser ', projectUser)

const role = projectUser.role;
const project = projectUser.id_project;
this.logger.log('[APP-COMPONENT] REDIRECT TO PRICING - project ', project)


// const dateLimit = new Date('2022-07-04T00:00:00') // for test purpose
// console.log('[APP-COMPONENT] REDIRECT TO PRICING - dateLimit ', dateLimit)
this.logger.log('[APP-COMPONENT] REDIRECT TO PRICING - freePlanLimitDate ', freePlanLimitDate)


if (project) {

const projectCreationDate = new Date(project.createdAt);
this.logger.log('[APP-COMPONENT] REDIRECT TO PRICING - projectCreationDate ', projectCreationDate)
this.logger.log('[APP-COMPONENT] REDIRECT TO PRICING - project.profile.type ', project.profile.type)
this.logger.log('[APP-COMPONENT] REDIRECT TO PRICING - project.trialExpired ', project.trialExpired)

if (projectCreationDate >= freePlanLimitDate) {
this.logger.log('[APP-COMPONENT] REDIRECT TO PRICING - projectCreationDate > dateLimit ')


if (project.profile.type === 'free' && project.trialExpired === true) {
if (role === 'owner') {

this.router.navigate(['project/' + project._id + '/pricing/te']);


} else {
this.router.navigate(['project/' + project._id + '/unauthorized-to-upgrade']);
}
}
} else {
this.logger.log('[APP-COMPONENT] REDIRECT TO PRICING - projectCreationDate < dateLimit ')
}
}
}

// this.USER_ROLE = this.current_selected_prjct_user.role
// this.logger.log('[APP-COMPONENT] USER_ROLE ', this.USER_ROLE)
// }
// })
// }
// });
// }

redirectToPricingFromChat(projectUser) {
const project = projectUser.id_project;
console.log('[APP-COMPONENT] redirectToPricingFromChat')
this.router.navigate(['project/' + project._id + '/unauthorized-to-upgrade']);
}

containsNumber(str: string): boolean {
return /\d/.test(str);
}

listenToSwPostMessage() {
this.logger.log('[APP-COMPONENT] listenToNotificationCLick - CALLED: ')
Expand Down Expand Up @@ -1144,8 +1235,8 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
(this.route.indexOf('/cds') !== -1) ||
(this.route.indexOf('/desktop-access') !== -1) ||
(this.route.indexOf('/desktop--access') !== -1) ||
(this.route.indexOf('/projects') !== -1)

(this.route.indexOf('/projects') !== -1) ||
(this.route.indexOf('/pricing') !== -1)
) {
elemFooter.setAttribute('style', 'display:none;');
// this.logger.log('DETECT LOGIN PAGE')
Expand Down
3 changes: 3 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ import { SleekplanSsoService } from './services/sleekplan-sso.service';
import { SleekplanService } from './services/sleekplan.service';
import { SleekplanApiService } from './services/sleekplan-api.service';
import { LogoutModalComponent } from './auth/logout-modal/logout-modal.component';
import { UnauthorizedToUpgradeComponent } from './auth/unauthorized-to-upgrade/unauthorized-to-upgrade.component';


// import { ModalAddContentComponent } from './modal-add-content/modal-add-content.component';
// import { PasswordStrengthModule } from './auth/signup/password-strength/password-strength.module';
Expand Down Expand Up @@ -723,6 +725,7 @@ const appInitializerFn = (appConfig: AppConfigService, brandService: BrandServic
KnowledgeBasesAlertComponent,
CnpSelectTemplatesOrKbComponent,
LogoutModalComponent,
UnauthorizedToUpgradeComponent,
// ModalAddContentComponent,
// ModalChatbotReassignmentComponent,
// ModalAddNamespaceComponent,
Expand Down
13 changes: 12 additions & 1 deletion src/app/app.routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ import { CnpIsMobileComponent } from './create-new-project/cnp-is-mobile/cnp-is-
import { CnpTemplatesComponent } from './create-new-project/cnp-templates/cnp-templates.component';
import { OnboardingWelcomeComponent } from './create-new-project/onboarding-welcome/onboarding-welcome.component';
import { RoleGuard } from './core/role.guard';
import { UnauthorizedToUpgradeComponent } from './auth/unauthorized-to-upgrade/unauthorized-to-upgrade.component';

// import { AutomationsComponent } from './automations/automations.component'; // now lazy

Expand Down Expand Up @@ -247,6 +248,15 @@ const routes: Routes = [
canActivate: [AuthGuard, RoleGuard],
data: [{ roles: ['owner'] }]
},

// Pricing trial expired
{
path: 'project/:projectid/pricing/te',
loadChildren: () => import('app/pricing/pricing.module').then(m => m.PricingModule),
canActivate: [AuthGuard, RoleGuard],
data: [{ roles: ['owner'] }]
},

// { path: 'project/:projectid/pricing', component: PricingComponent, canActivate: [AuthGuard] }, // now Lazy
{
path: 'project/:projectid/chat-pricing',
Expand Down Expand Up @@ -1167,7 +1177,8 @@ const routes: Routes = [
{ path: 'unauthorized', component: UnauthorizedComponent },
{ path: 'project/:projectid/unauthorized-access', component: UnauthorizedForPricingComponent },
{ path: 'project/:projectid/unauthorized_access', component: UnauthorizedForProjectComponent },

{ path: 'project/:projectid/unauthorized-to-upgrade', component: UnauthorizedToUpgradeComponent },




Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<div class="unauthorized-to-upgrade-container">
<div class="unauthorized-to-upgrade-main">
<div class="unauthorized-to-upgrade-spacing"></div>
<div class="unauthorized-to-upgrade-content-wpr">
<div class="unauthorized-to-upgrade-content">
<div class="unauthorized-to-upgrade-inner-content">

<div class="unauthorized-to-upgrade-logo-container">
<div class="unauthorized-to-upgrade-logo-svg-wpr">


<!-- <svg style="display: block;" xml:space="preserve" xmlns:xlink="http://www.w3.org/1999/xlink"
height="45px" viewBox="0 0 60 60" width="45px" x="0px"
xmlns="http://www.w3.org/2000/svg" y="0px" style="position: relative; left: -1px;">
<path _ngcontent-gda-c124=""
d="M51.8,28.2h-19c-1.7,0-3-1.3-3-3V6.4c0-1.7-1.3-3-3-3H8c-1.7,0-3,1.3-3,3v22v22c0,1.7,1.3,3,3,3H6.7h3.4 c0.8,0,1.3,0.2,1.9,0.8l2.3,2.3l2.1,2.1c0.8,0.8,1.7,0.8,2.4,0l2.1-2.1l2.3-2.3c0.6-0.6,1.1-0.8,1.9-0.8H52c1.7,0,3-1.3,3-3V31.2 C54.8,29.5,53.5,28.2,51.8,28.2"
fill="#F18876"></path>
<path _ngcontent-gda-c124=""
d="M52,24.2H36.8c-1.5,0-2.8-1.3-2.8-2.8V6.2c0-1.5,1.3-2.8,2.8-2.8H52c1.5,0,2.8,1.3,2.8,2.8v15.2 C54.8,22.9,53.5,24.2,52,24.2"
fill="#E5BBAD"></path>
</svg> -->

<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px"
fill="#b7394a">
<path
d="M480-280q17 0 28.5-11.5T520-320q0-17-11.5-28.5T480-360q-17 0-28.5 11.5T440-320q0 17 11.5 28.5T480-280Zm-40-160h80v-240h-80v240Zm40 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" />
</svg>
</div>
</div>

<div class="unauthorized-to-upgrade-title-wpr">
<div class="unauthorized-to-upgrade-title" [ngClass]="{'panel-mode': CHAT_MODE}">


{{'Pricing.YourTrialHasEnded' | translate}}
</div>
</div>
<div class="unauthorized-to-upgrade-subtitle-wpr">
<div class="unauthorized-to-upgrade-subtitle" [ngClass]="{'panel-mode': CHAT_MODE}">
<!-- {{'AutomateConversationsFromPrototyping' | translate }} -->
{{ 'TrialExpirationDate' | translate: {expiration_date: trialExpirationDate} }}.
<span *ngIf="userRole !== 'owner'">
{{'Pricing.ContactTheProjectOwner' | translate}}.
</span>
</div>
</div>
<div *ngIf="!CHAT_MODE" class="unauthorized-to-upgrade-btn-container">
<div class="unauthorized-to-upgrade-btn-wpr">

<div class="unauthorized-to-upgrade-go-to-project" (click)="goToYourProjects()">
{{'GoToYourProjects' | translate}}
</div>
</div>
</div>

<div *ngIf="CHAT_MODE && userRole === 'owner'" class="unauthorized-to-upgrade-btn-container">
<div class="unauthorized-to-upgrade-btn-wpr">

<div *ngIf="isVisiblePAY" class="unauthorized-to-upgrade-go-to-project" (click)="goToPricingFromChat()">
{{ 'Pricing.UpgradePlan' | translate }}
</div>
<div *ngIf="!isVisiblePAY" class="unauthorized-to-upgrade-go-to-project" (click)="contactUs()">
{{ 'ContactUs' | translate }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Loading

0 comments on commit 9b303b2

Please sign in to comment.