-
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 #7072 from ever-co/develop
Release
- Loading branch information
Showing
68 changed files
with
5,314 additions
and
597 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
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
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
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
18 changes: 11 additions & 7 deletions
18
...thorize/gauzy-ai-authorize.component.html → ...uthorization/authorization.component.html
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
File renamed without changes.
24 changes: 24 additions & 0 deletions
24
.../app/pages/integrations/gauzy-ai/components/authorization/authorization.component.spec.ts
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { GauzyAIAuthorizationComponent } from './authorization.component'; | ||
|
||
describe('GauzyAIAuthorizationComponent', () => { | ||
let component: GauzyAIAuthorizationComponent; | ||
let fixture: ComponentFixture<GauzyAIAuthorizationComponent>; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [GauzyAIAuthorizationComponent], | ||
teardown: { destroyAfterEach: false } | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(GauzyAIAuthorizationComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
100 changes: 100 additions & 0 deletions
100
...y/src/app/pages/integrations/gauzy-ai/components/authorization/authorization.component.ts
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'; | ||
import { ActivatedRoute, Data, Router } from '@angular/router'; | ||
import { FormGroup, FormBuilder, Validators, FormGroupDirective } from '@angular/forms'; | ||
import { filter, tap } from 'rxjs/operators'; | ||
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; | ||
import { IIntegrationTenant, IOrganization } from '@gauzy/contracts'; | ||
import { GauzyAIService, Store } from './../../../../../@core/services'; | ||
|
||
@UntilDestroy({ checkProperties: true }) | ||
@Component({ | ||
selector: 'ngx-gauzy-ai-authorization', | ||
templateUrl: './authorization.component.html', | ||
styleUrls: ['./authorization.component.scss'], | ||
}) | ||
export class GauzyAIAuthorizationComponent implements OnInit, OnDestroy { | ||
|
||
public organization: IOrganization; | ||
|
||
readonly form: FormGroup = GauzyAIAuthorizationComponent.buildForm(this._formBuilder); | ||
static buildForm(fb: FormBuilder): FormGroup { | ||
return fb.group({ | ||
client_id: [null, Validators.required], | ||
client_secret: [null, Validators.required], | ||
}); | ||
} | ||
|
||
@ViewChild('formDirective') formDirective: FormGroupDirective; | ||
|
||
constructor( | ||
private readonly _formBuilder: FormBuilder, | ||
private readonly _router: Router, | ||
private readonly _activatedRoute: ActivatedRoute, | ||
private readonly _store: Store, | ||
private readonly _gauzyAIService: GauzyAIService | ||
) { } | ||
|
||
ngOnInit(): void { | ||
this._activatedRoute.data | ||
.pipe( | ||
tap(({ integration }: Data) => { | ||
if (integration) { | ||
this._redirectToGauzyAIIntegration(integration.id); | ||
} | ||
}), | ||
untilDestroyed(this) // Ensure that subscriptions are automatically unsubscribed on component destruction. | ||
) | ||
.subscribe(); | ||
this._store.selectedOrganization$ | ||
.pipe( | ||
filter((organization: IOrganization) => !!organization), | ||
tap((organization: IOrganization) => (this.organization = organization)), | ||
untilDestroyed(this) | ||
) | ||
.subscribe(); | ||
} | ||
|
||
ngOnDestroy(): void { } | ||
|
||
/** | ||
* Gauzy AI integration remember state API call | ||
*/ | ||
private _redirectToGauzyAIIntegration(integrationId: string) { | ||
this._router.navigate(['pages/integrations/gauzy-ai', integrationId]); | ||
} | ||
|
||
/** | ||
* | ||
* @returns | ||
*/ | ||
async onSubmit() { | ||
if (!this.organization || this.form.invalid) { | ||
return; | ||
} | ||
try { | ||
const { client_id, client_secret } = this.form.value; | ||
const { id: organizationId, tenantId } = this.organization; | ||
|
||
this._gauzyAIService.addIntegration({ | ||
client_id, | ||
client_secret, | ||
organizationId, | ||
tenantId | ||
}).pipe( | ||
tap((integration: IIntegrationTenant) => { | ||
this._redirectToGauzyAIIntegration(integration.id); | ||
}), | ||
untilDestroyed(this) | ||
).subscribe(); | ||
} catch (error) { | ||
console.log('Error while creating new integration for Gauzy AI', error); | ||
} | ||
} | ||
|
||
/** | ||
* Navigate to the "Integrations" page. | ||
*/ | ||
navigateToIntegrations(): void { | ||
this._router.navigate(['/pages/integrations']); | ||
} | ||
} |
Oops, something went wrong.