-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7076 from ever-co/develop
Release
- Loading branch information
Showing
13 changed files
with
436 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
<nb-layout> | ||
<nb-layout-column class="wrapper"> | ||
<nb-card class="card"> | ||
<nb-card-header class="header" [ngClass]="{register: isRegister}"> | ||
<nav class="navigation"> | ||
<a href="#" (click)="back()" class="link back-link" aria-label="Back"> | ||
<nb-icon icon="arrow-back"></nb-icon> | ||
</a> | ||
</nav> | ||
<gauzy-switch-theme class="theme-switch" [hasText]="false"></gauzy-switch-theme> | ||
</nb-card-header> | ||
<nb-card-body class="body" [ngClass]="{register: isRegister}"> | ||
<nb-auth-block class="auth-block"> | ||
<router-outlet></router-outlet> | ||
</nb-auth-block> | ||
<!-- <div class="message-us-wrapper">--> | ||
<!-- <nb-icon icon="message-square-outline"></nb-icon>--> | ||
<!-- </div>--> | ||
</nb-card-body> | ||
</nb-card> | ||
</nb-layout-column> | ||
<nb-layout-column class="wrapper"> | ||
<nb-card class="card"> | ||
<nb-card-header class="header" [ngClass]="{register: isRegister }"> | ||
<nav [ngClass]="{ 'hide-go-back' : !(queryParams$ | async)?.returnUrl }" class="navigation"> | ||
<a (click)="goBack()" class="link back-link" aria-label="Back"> | ||
<nb-icon icon="arrow-back"></nb-icon> | ||
</a> | ||
</nav> | ||
<gauzy-switch-theme class="theme-switch" [hasText]="false"></gauzy-switch-theme> | ||
</nb-card-header> | ||
<nb-card-body class="body" [ngClass]="{ register: isRegister }"> | ||
<nb-auth-block class="auth-block"> | ||
<router-outlet></router-outlet> | ||
</nb-auth-block> | ||
<!-- <div class="message-us-wrapper"> | ||
<nb-icon icon="message-square-outline"></nb-icon> | ||
</div> --> | ||
</nb-card-body> | ||
</nb-card> | ||
</nb-layout-column> | ||
</nb-layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,82 @@ | ||
import { NbAuthComponent, NbAuthService } from "@nebular/auth"; | ||
import { Component, OnInit } from "@angular/core"; | ||
import { Location } from '@angular/common'; | ||
import { NavigationStart, Router } from "@angular/router"; | ||
import { ActivatedRoute, NavigationStart, Params, Router } from "@angular/router"; | ||
import { filter } from "rxjs/operators"; | ||
import { map } from "rxjs"; | ||
|
||
import { Observable, map, tap } from "rxjs"; | ||
import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy"; | ||
|
||
@UntilDestroy({ checkProperties: true }) | ||
@Component({ | ||
selector: 'ngx-auth', | ||
templateUrl: './auth.component.html', | ||
styleUrls: ['./auth.component.scss'], | ||
selector: 'ngx-auth', | ||
templateUrl: './auth.component.html', | ||
styleUrls: ['./auth.component.scss'], | ||
}) | ||
export class NgxAuthComponent extends NbAuthComponent implements OnInit { | ||
isRegister: boolean = false; | ||
|
||
constructor ( | ||
protected auth: NbAuthService, | ||
protected location: Location, | ||
private router: Router, | ||
) { | ||
super(auth, location); | ||
} | ||
|
||
updateRegisterClas (url: string) { | ||
this.isRegister = url === '/auth/register'; | ||
} | ||
|
||
ngOnInit () { | ||
this.updateRegisterClas(this.router.url); | ||
|
||
this.router.events.pipe( | ||
filter(e => e instanceof NavigationStart), | ||
map(e => e as NavigationStart), | ||
) | ||
.subscribe(e => { | ||
this.updateRegisterClas(e.url); | ||
}); | ||
} | ||
isRegister: boolean = false; | ||
public queryParams$: Observable<Params>; // Observable for the query params | ||
|
||
constructor( | ||
protected readonly auth: NbAuthService, | ||
protected readonly location: Location, | ||
private readonly _router: Router, | ||
private readonly _route: ActivatedRoute | ||
) { | ||
super(auth, location); | ||
} | ||
|
||
updateRegisterClass(url: string) { | ||
this.isRegister = url === '/auth/register'; | ||
} | ||
|
||
ngOnInit() { | ||
this.updateRegisterClass(this._router.url); | ||
|
||
// Create an observable to listen to query parameter changes in the current route. | ||
this.queryParams$ = this._route.queryParams.pipe( | ||
// Filter and ensure that query parameters are present. | ||
filter((params: Params) => !!params), | ||
|
||
// Use 'untilDestroyed' to handle component lifecycle and avoid memory leaks. | ||
untilDestroyed(this) | ||
); | ||
|
||
this._router.events.pipe( | ||
filter((event) => event instanceof NavigationStart), | ||
map((event) => event as NavigationStart), | ||
).subscribe((event) => { | ||
this.updateRegisterClass(event.url); | ||
}); | ||
} | ||
|
||
/** | ||
* Go back to the return URL. | ||
*/ | ||
goBack() { | ||
// Access query parameters from the snapshot. | ||
const returnUrl = this._route.snapshot.queryParamMap.get('returnUrl'); | ||
|
||
if (returnUrl) { | ||
if (this.isExternalUrl(returnUrl)) { | ||
// If it's an external URL, navigate to it using window.location.href. | ||
window.location.href = returnUrl; | ||
} else { | ||
// If it's an Angular app URL, navigate within the Angular application. | ||
this._router.navigate([returnUrl], { replaceUrl: true }); | ||
} | ||
} else { | ||
// Handle the case when returnUrl is not provided. | ||
// You can navigate to a default route or display an error message. | ||
console.error('No return URL provided.'); | ||
} | ||
} | ||
|
||
/** | ||
* Check if a URL is external (not part of the Angular app). | ||
*/ | ||
isExternalUrl(url: string): boolean { | ||
const location = window.location; | ||
const currentOrigin = location.origin; | ||
return !url.startsWith(currentOrigin); | ||
} | ||
} |
Oops, something went wrong.