-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: QBD direct main connection page business logic
- Loading branch information
1 parent
20665aa
commit c2ecefc
Showing
14 changed files
with
284 additions
and
70 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
3 changes: 1 addition & 2 deletions
3
...core/qbd-direct-connector.service.spec.ts → ...tion/qbd-direct-connector.service.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
24 changes: 24 additions & 0 deletions
24
src/app/core/services/qbd-direct/qbd-direct-configuration/qbd-direct-connector.service.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 { Injectable } from '@angular/core'; | ||
import { ApiService } from '../../common/api.service'; | ||
import { WorkspaceService } from '../../common/workspace.service'; | ||
import { Observable } from 'rxjs'; | ||
import { QbdConnectorPost, QbdConnectorGet, SyncDataType } from 'src/app/core/models/qbd-direct/qbd-direct-configuration/qbd-direct-connector.model'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class QbdDirectConnectorService { | ||
|
||
constructor( | ||
private apiService: ApiService, | ||
private workspaceService: WorkspaceService | ||
) { } | ||
|
||
postQbdDirectConntion(payload: QbdConnectorPost): Observable<QbdConnectorGet> { | ||
return this.apiService.post(`/workspaces/${this.workspaceService.getWorkspaceId()}/connector_settings/`, payload); | ||
} | ||
|
||
syncAttribuites(): Observable<SyncDataType[]> { | ||
return this.apiService.get(`/workspaces/${this.workspaceService.getWorkspaceId()}/qbd/attribute_stats/`, {}); | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
...vices/qbd-direct/qbd-direct-configuration/qbd-direct-connector.service.ts.service.spec.ts
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...e/services/qbd-direct/qbd-direct-configuration/qbd-direct-connector.service.ts.service.ts
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
src/app/core/services/qbd-direct/qbd-direct-core/qbd-direct-connector.service.ts
This file was deleted.
Oops, something went wrong.
51 changes: 48 additions & 3 deletions
51
...onboarding/qbd-direct-onboarding-connector/qbd-direct-onboarding-connector.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,48 @@ | ||
<!-- <app-qbd-direct-download-file></app-qbd-direct-download-file> --> | ||
<!-- <app-qbd-direct-setup-connection></app-qbd-direct-setup-connection> --> | ||
<!-- <app-qbd-direct-data-sync></app-qbd-direct-data-sync> --> | ||
<div class="tw-pb-48-px"> | ||
<app-onboarding-steppers [onboardingSteps]="onboardingSteps"></app-onboarding-steppers> | ||
<div> | ||
<div *ngIf="isLoading" class="tw-flex tw-justify-center tw-items-center tw-pt-80-px"> | ||
<app-loader></app-loader> | ||
</div> | ||
<div *ngIf="!isLoading" class="configuration--contents tw-border-border-tertiary tw-mt-24-px" [ngClass]="{'tw-mx-120-px tw-shadow-app-card': brandingConfig.brandId === 'fyle', 'tw-mx-60-px tw-shadow-shadow-level-1': brandingConfig.brandId === 'co'}"> | ||
<div> | ||
<app-configuration-step-header | ||
[headerText]="brandingContent.configurationHeaderText" | ||
[contentText]="brandingContent.configurationSubHeaderText" | ||
[redirectLink]="redirectLink"> | ||
</app-configuration-step-header> | ||
</div> | ||
<div class="tw-px-24-px"> | ||
<div class="tw-py-24-px"> | ||
<app-qbd-direct-download-file | ||
[isLoading]="isdownloadfileLoading" | ||
[showDownloadLink]="showDownloadLink" | ||
[isStepCompleted]="isDownloadStepCompleted" | ||
[isCompanyPathInvalid]="isCompanyPathInvalid" | ||
(nextStep)="proceedToConnection()" | ||
(downloadClick)="triggerDownload($event)" | ||
(retryClick)="retry()" | ||
(manualDownload)="triggerManualDownload()"></app-qbd-direct-download-file> | ||
</div> | ||
<div class="tw-py-24-px"> | ||
<app-qbd-direct-setup-connection | ||
[showSection]="isDownloadStepCompleted" | ||
[password]="password" | ||
[isLoading]="isconnectionLoading" | ||
[connectionStatus]="connectionStatus" | ||
[isStepCompleted]="isConnectionStepCompleted" | ||
[isCTAEnabled]="isConnectionCTAEnabled" | ||
(doneClick)="onConnectionDone($event)" | ||
(nextClick)="proceedToSyncData()"></app-qbd-direct-setup-connection> | ||
</div> | ||
<div class="tw-py-24-px"> | ||
<app-qbd-direct-data-sync | ||
[qbdFields]="qbdFields" | ||
[isCTAEnabled]="isDataSyncCTADisabled" | ||
[showSection]="isConnectionStepCompleted" | ||
(continueClick)="proceedToExportSetting()"></app-qbd-direct-data-sync> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
184 changes: 181 additions & 3 deletions
184
...t-onboarding/qbd-direct-onboarding-connector/qbd-direct-onboarding-connector.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 |
---|---|---|
@@ -1,14 +1,192 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { QbdDirectSharedModule } from '../../qbd-direct-shared/qbd-direct-shared.module'; | ||
import { SharedModule } from 'src/app/shared/shared.module'; | ||
import { brandingConfig, brandingContent, brandingKbArticles } from 'src/app/branding/branding-config'; | ||
import { BrandingConfiguration } from 'src/app/core/models/branding/branding-configuration.model'; | ||
import { AppName, ConfigurationCta, QBDConnectionStatus, QbdDirectOnboardingState, QBDOnboardingState } from 'src/app/core/models/enum/enum.model'; | ||
import { OnboardingStepper } from 'src/app/core/models/misc/onboarding-stepper.model'; | ||
import { QbdDirectOnboardingModel } from 'src/app/core/models/qbd-direct/qbd-direct-configuration/qbd-direct-onboarding.model'; | ||
import { Router } from '@angular/router'; | ||
import { WorkspaceService } from 'src/app/core/services/common/workspace.service'; | ||
import { CommonModule } from '@angular/common'; | ||
import { QbdConnectorGet, SyncDataType } from 'src/app/core/models/qbd-direct/qbd-direct-configuration/qbd-direct-connector.model'; | ||
import { StorageService } from 'src/app/core/services/common/storage.service'; | ||
import { MinimalUser } from 'src/app/core/models/db/user.model'; | ||
import { QbdDirectWorkspace } from 'src/app/core/models/qbd-direct/db/qbd-direct-workspaces.model'; | ||
import { QbdDirectConnectorService } from 'src/app/core/services/qbd-direct/qbd-direct-configuration/qbd-direct-connector.service'; | ||
import { checkBoxEmit } from 'src/app/core/models/common/helper.model'; | ||
import { interval, switchMap, from, takeWhile } from 'rxjs'; | ||
import { QbdDirectTaskResponse } from 'src/app/core/models/qbd-direct/db/qbd-direct-task-log.model'; | ||
|
||
@Component({ | ||
selector: 'app-qbd-direct-onboarding-connector', | ||
standalone: true, | ||
imports: [QbdDirectSharedModule, SharedModule], | ||
imports: [QbdDirectSharedModule, SharedModule, CommonModule], | ||
templateUrl: './qbd-direct-onboarding-connector.component.html', | ||
styleUrl: './qbd-direct-onboarding-connector.component.scss' | ||
}) | ||
export class QbdDirectOnboardingConnectorComponent { | ||
export class QbdDirectOnboardingConnectorComponent implements OnInit { | ||
|
||
brandingContent = brandingContent.qbd_direct.configuration.connector; | ||
|
||
onboardingSteps: OnboardingStepper[] = new QbdDirectOnboardingModel().getOnboardingSteps(this.brandingContent.stepName, this.workspaceService.getOnboardingState()); | ||
|
||
isLoading: boolean = true; | ||
|
||
redirectLink: string = brandingKbArticles.onboardingArticles.QBD_DIRECT.CONNECTOR; | ||
|
||
brandingConfig: BrandingConfiguration = brandingConfig; | ||
|
||
ConfigurationCtaText = ConfigurationCta; | ||
|
||
showDownloadLink: boolean; | ||
|
||
isdownloadfileLoading: boolean; | ||
|
||
isconnectionLoading: boolean; | ||
|
||
isDownloadStepCompleted: boolean; | ||
|
||
isConnectionStepCompleted: boolean; | ||
|
||
xmlFileContent: string; | ||
|
||
isCompanyPathInvalid: boolean = true; | ||
|
||
password: string; | ||
|
||
connectionStatus: QBDConnectionStatus; | ||
|
||
isConnectionCTAEnabled: boolean; | ||
|
||
isDialogVisible: boolean; | ||
|
||
qbdFields: SyncDataType[]; | ||
|
||
isDataSyncCTADisabled: boolean; | ||
|
||
user:MinimalUser = this.storageService.get('user'); | ||
|
||
constructor( | ||
private router: Router, | ||
private workspaceService: WorkspaceService, | ||
private storageService: StorageService, | ||
private qbdDirectConntorService: QbdDirectConnectorService | ||
) { } | ||
|
||
triggerDownload(filePath: string) { | ||
const normalizedPath = filePath.replace(/\\\\/g, "\\"); | ||
const filePathRegex = /^(\/?|\.?\/?|[a-zA-Z]:\\)([a-zA-Z0-9_-]+[\\/])*[a-zA-Z0-9 _-]+\.qbw$/; | ||
this.isCompanyPathInvalid = filePathRegex.test(normalizedPath); | ||
if (this.isCompanyPathInvalid) { | ||
this.isdownloadfileLoading = true; | ||
this.qbdDirectConntorService.postQbdDirectConntion({file_location: normalizedPath}).subscribe((connectionResponse: QbdConnectorGet) => { | ||
this.password = connectionResponse.password; | ||
this.xmlFileContent = connectionResponse.qwc; | ||
this.triggerManualDownload(); | ||
this.showDownloadLink = true; | ||
}); | ||
this.isdownloadfileLoading = false; | ||
} | ||
} | ||
|
||
triggerManualDownload() { | ||
const blob = new Blob([this.xmlFileContent], { type: 'text/xml' }); | ||
const url = window.URL.createObjectURL(blob); | ||
const a = document.createElement('a'); | ||
const objectUrl = URL.createObjectURL(blob); | ||
a.href = objectUrl; | ||
a.download = 'fyle_quickbooks.qwc'; | ||
a.click(); | ||
URL.revokeObjectURL(objectUrl); | ||
} | ||
|
||
proceedToConnection() { | ||
this.isdownloadfileLoading = true; | ||
this.workspaceService.updateWorkspaceOnboardingState({onboarding_state: QbdDirectOnboardingState.PENDING_QWC_UPLOAD}).subscribe((workspaceResponse: QbdDirectWorkspace) => { | ||
this.isDownloadStepCompleted = true; | ||
this.isdownloadfileLoading = false; | ||
}); | ||
} | ||
|
||
retry() { | ||
this.showDownloadLink = false; | ||
} | ||
|
||
onConnectionDone(event: checkBoxEmit) { | ||
if (event.value) { | ||
this.qbdDirectConntorService.syncAttribuites().subscribe((sd: SyncDataType[]) => { | ||
this.qbdFields = sd; | ||
this.isConnectionCTAEnabled = true; | ||
// Interval(3000).pipe( | ||
// SwitchMap(() => this.workspaceService.getWorkspace(this.user.org_id)), // Make HTTP request | ||
// TakeWhile((status: any) => !this.isTerminalStatus(status.onboarding_state as QbdDirectOnboardingState), true) // Stop if terminal status is reached | ||
// ) | ||
// .subscribe( | ||
// (status) => this.handleStatus(status), | ||
// (error) => console.error('Error polling workspace status:', error) | ||
// ); | ||
}); | ||
} | ||
} | ||
|
||
handleStatus(status: QbdDirectWorkspace): void { | ||
const onboardingState = status.onboarding_state; | ||
|
||
if (onboardingState === QbdDirectOnboardingState.INCORRECT_COMPANY_PATH) { | ||
// Set connection status, open dialog, and stop polling | ||
this.connectionStatus = QBDConnectionStatus.INCORRECT_COMPANY_PATH; | ||
this.isDialogVisible = true; | ||
} else if (onboardingState === QbdDirectOnboardingState.IN_CORRECT_PASSWORD) { | ||
// Set connection status, open dialog, and stop polling | ||
this.connectionStatus = QBDConnectionStatus.IN_CORRECT_PASSWORD; | ||
this.isDialogVisible = true; | ||
} else if (onboardingState === QbdDirectOnboardingState.DESTINATION_SYNC_IN_PROGRESS || onboardingState === QbdDirectOnboardingState.DESTINATION_SYNC_COMPLETE) { | ||
// Set success status, enable connection CTA, and stop polling | ||
this.connectionStatus = QBDConnectionStatus.SUCCESS; | ||
this.isConnectionCTAEnabled = true; | ||
} | ||
} | ||
|
||
isTerminalStatus(status: QbdDirectOnboardingState): boolean { | ||
return [QbdDirectOnboardingState.DESTINATION_SYNC_IN_PROGRESS, QbdDirectOnboardingState.IN_CORRECT_PASSWORD, QbdDirectOnboardingState.INCORRECT_COMPANY_PATH, QbdDirectOnboardingState.DESTINATION_SYNC_COMPLETE].includes(status); | ||
} | ||
|
||
proceedToSyncData() { | ||
this.isConnectionStepCompleted = true; | ||
this.isDataSyncCTADisabled= true; | ||
|
||
// If DESTINATION_SYNC_IN_PROGRESS -> start polling workspaces/ | ||
// Set value to qbdFields when getting API response | ||
// If DESTINATION_SYNC_COMPLETE => stop polling, set isDataSyncCTADisabled to false | ||
} | ||
|
||
|
||
proceedToExportSetting() { | ||
this.isLoading = true; | ||
this.workspaceService.updateWorkspaceOnboardingState({onboarding_state: QbdDirectOnboardingState.EXPORT_SETTINGS}).subscribe((workspaceResponse: QbdDirectWorkspace) => { | ||
this.router.navigate([`/integrations/qbd_direct/onboarding/export_settings`]); | ||
this.isLoading = false; | ||
}); | ||
} | ||
|
||
|
||
setupPage() { | ||
this.workspaceService.getWorkspace(this.user.org_id).subscribe((workspaceResponse: QbdDirectWorkspace) => { | ||
if (workspaceResponse.onboarding_state === QbdDirectOnboardingState.PENDING_QWC_UPLOAD) { | ||
this.isDownloadStepCompleted = true; | ||
this.isdownloadfileLoading = false; | ||
} else if (workspaceResponse.onboarding_state === QbdDirectOnboardingState.DESTINATION_SYNC_IN_PROGRESS) { | ||
this.isDownloadStepCompleted = true; | ||
this.isConnectionStepCompleted = true; | ||
this.isconnectionLoading = false; | ||
this.isdownloadfileLoading = false; | ||
} | ||
this.isLoading = false; | ||
}); | ||
} | ||
|
||
ngOnInit(): void { | ||
this.setupPage(); | ||
} | ||
} |
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
Oops, something went wrong.