diff --git a/src/app/core/models/qbd-direct/qbd-direct-configuration/qbd-direct-advanced-settings.model.ts b/src/app/core/models/qbd-direct/qbd-direct-configuration/qbd-direct-advanced-settings.model.ts index 18289da8a..86cc494ed 100644 --- a/src/app/core/models/qbd-direct/qbd-direct-configuration/qbd-direct-advanced-settings.model.ts +++ b/src/app/core/models/qbd-direct/qbd-direct-configuration/qbd-direct-advanced-settings.model.ts @@ -38,5 +38,21 @@ export class QbdDirectAdvancedSettingsModel extends AdvancedSettingsModel { searchOption: new FormControl('') }); } + + static constructPayload (advancedSettingForm: FormGroup): QbdDirectAdvancedSettingsPost { + + const topMemo: string[] = []; + topMemo.push(advancedSettingForm.value.topMemoStructure); + + const advancedSettingPayload: QbdDirectAdvancedSettingsPost = { + expense_memo_structure: advancedSettingForm.get('expenseMemoStructure')?.value ? advancedSettingForm.get('expenseMemoStructure')?.value : null, + top_memo_structure: advancedSettingForm.get('topMemoStructure')?.value ? topMemo : null, + schedule_is_enabled: advancedSettingForm.get('exportSchedule')?.value ? advancedSettingForm.get('exportSchedule')?.value : false, + emails_selected: advancedSettingForm.get('exportSchedule')?.value ? advancedSettingForm.get('email')?.value : null, + interval_hours: advancedSettingForm.get('exportSchedule')?.value ? advancedSettingForm.get('exportScheduleFrequency')?.value : null + }; + + return advancedSettingPayload; + } } diff --git a/src/app/integrations/qbd-direct/qbd-direct-shared/qbd-direct-advanced-settings/qbd-direct-advanced-settings.component.ts b/src/app/integrations/qbd-direct/qbd-direct-shared/qbd-direct-advanced-settings/qbd-direct-advanced-settings.component.ts index 98b7ab4cf..54e89af86 100644 --- a/src/app/integrations/qbd-direct/qbd-direct-shared/qbd-direct-advanced-settings/qbd-direct-advanced-settings.component.ts +++ b/src/app/integrations/qbd-direct/qbd-direct-shared/qbd-direct-advanced-settings/qbd-direct-advanced-settings.component.ts @@ -5,9 +5,11 @@ import { Router } from '@angular/router'; import { forkJoin } from 'rxjs'; import { brandingConfig, brandingContent, brandingFeatureConfig } from 'src/app/branding/branding-config'; import { EmailOption, SelectFormOption } from 'src/app/core/models/common/select-form-option.model'; -import { AppName, ConfigurationCta, QBDScheduleFrequency } from 'src/app/core/models/enum/enum.model'; +import { AppName, ConfigurationCta, QBDOnboardingState, QBDScheduleFrequency, ToastSeverity } from 'src/app/core/models/enum/enum.model'; import { QbdDirectAdvancedSettingsGet, QbdDirectAdvancedSettingsModel } from 'src/app/core/models/qbd-direct/qbd-direct-configuration/qbd-direct-advanced-settings.model'; import { HelperService } from 'src/app/core/services/common/helper.service'; +import { IntegrationsToastService } from 'src/app/core/services/common/integrations-toast.service'; +import { WorkspaceService } from 'src/app/core/services/common/workspace.service'; import { OrgService } from 'src/app/core/services/org/org.service'; import { QbdDirectAdvancedSettingsService } from 'src/app/core/services/qbd-direct/qbd-direct-configuration/qbd-direct-advanced-settings.service'; import { SharedModule } from 'src/app/shared/shared.module'; @@ -68,12 +70,27 @@ export class QbdDirectAdvancedSettingsComponent implements OnInit { private advancedSettingsService: QbdDirectAdvancedSettingsService, public helper: HelperService, private router: Router, - private orgService: OrgService - // Private toastService: IntegrationsToastService, - // Private workspaceService: WorkspaceService + private orgService: OrgService, + private toastService: IntegrationsToastService, + private workspaceService: WorkspaceService ) { } - save() {} + save() { + this.saveInProgress = true; + const advancedSettingPayload = QbdDirectAdvancedSettingsModel.constructPayload(this.advancedSettingsForm); + this.advancedSettingsService.postQbdAdvancedSettings(advancedSettingPayload).subscribe((response: QbdDirectAdvancedSettingsGet) => { + this.saveInProgress = false; + this.toastService.displayToastMessage(ToastSeverity.SUCCESS, 'Advanced settings saved successfully'); + + if (this.isOnboarding) { + this.workspaceService.setOnboardingState(QBDOnboardingState.COMPLETE); + this.router.navigate([`/integrations/qbd_direct/onboarding/done`]); + } + }, () => { + this.saveInProgress = false; + this.toastService.displayToastMessage(ToastSeverity.ERROR, 'Error saving advanced settings, please try again later'); + }); + } private createMemoStructureWatcher(): void { this.memoStructure = this.advancedSettingsForm.value.expenseMemoStructure;