Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
- import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
- import { MatDialog, MatDialogRef } from '@angular/material/dialog';
- import { MatStepper } from '@angular/material/stepper';
- import { PopupComponent } from '@shared/component/popup/popup.component';
- import { FooterService } from 'app/store-front/services/footer.service';
- import { StoreFrontService } from 'app/store-front/services/store-front.service';
- import { ValidationService } from 'app/validation.service';
- import { environment } from 'environments/environment';
- import { ApiService } from '../api.service';
- import { Location } from '@angular/common';
- import { Router } from '@angular/router';
- import { CanExit } from 'app/_guard/auth-guard.service';
- import { Observable } from 'rxjs';
- import { ConfirmNoclickComponent } from '@shared/component/confirm-noclick/confirm-noclick.component';
- import { DraftParam } from 'app/_core/domain/enda';
- import { Econtract } from 'app/_core/domain/econtract';
- import { ConfirmPrivyComponent } from '@shared/component/confirm-privy/confirm-privy.component';
- declare var grecaptcha: any;
- @Component({
- selector: 'app-nda',
- templateUrl: './nda.component.html',
- styleUrls: ['./nda.component.scss']
- })
- export class NDAComponent implements OnInit, CanExit, AfterViewInit, OnDestroy {
- @ViewChild('stepper') stepper: MatStepper;
- userEnterprise: boolean = false;
- errorMsg: string;
- errorMsgBool: boolean = false;
- result: boolean = true;
- public loading = false;
- openContent: boolean = false;
- openCompany: boolean = false;
- openProvince: boolean = false;
- openCity: boolean = false;
- openPostalCode: boolean = false;
- openNumber: boolean = false;
- openDuration: boolean = false;
- openScope: boolean = false;
- select: boolean = false;
- openOther: boolean = false;
- openOtherPosition: boolean = false;
- statusRecaptcha: boolean = environment.disableRecaptcha;
- // ndaForm: FormGroup;
- btnDisable: boolean = false;
- alredyResolve = false;
- selectBussiness = '';
- selectPosition = '';
- fieldTigalabel = '';
- accountInformation: any;
- allProvince: any;
- allCity: any;
- companyPlaceholder = 'Company Name';
- provincePlaceholder = '';
- cityPlaceholder = '';
- PostalCodePlaceholder = '';
- siteAddPlaceholder = 'Enter Your Site Address';
- legalPlaceholder = '';
- numberPlaceholder = '';
- durationPlaceholder = '';
- scopePlaceholder = '';
- provinceId: number;
- otherPlaceholder = 'Enter Your Other Bussiness Field';
- otherAttPlaceholder = 'Enter Your Position of Representative or Attorney';
- attorneyPlaceholder = 'Enter Your Name of Representative or Attorney';
- progress: number = 1;
- idProv: number;
- plandId: number;
- title: string;
- content: string;
- data: any;
- name: any;
- configFile;
- configDoc;
- count;
- fields;
- productName: string = ''
- categoryName: string = '';
- productImg: string = '';
- typePlan: string = '';
- targetFilename: any;
- business = [{
- id: 1,
- name: 'Banking service',
- checked: false
- }, {
- id: 2,
- name: 'Technology Finance',
- checked: false
- }, {
- id: 3,
- name: 'Other',
- checked: false
- }]
- position = [{
- id: 1,
- name: 'Director',
- checked: false
- }, {
- id: 2,
- name: 'President Director',
- checked: false
- }, {
- id: 3,
- name: 'Other',
- checked: false
- }]
- company = [{
- id: 1,
- name: 'PT Perseroan Terbatas'
- },
- {
- id: 2,
- name: 'Koperasi'
- },
- {
- id: 3,
- name: 'Instansi Pemerintah'
- },
- {
- id: 4,
- name: 'CV Persekutuan Komanditer'
- }]
- number = [{
- id: 1,
- name: 'Bipartit'
- },
- {
- id: 2,
- name: 'Tripartit'
- }]
- duration = [{
- id: 1,
- name: '1 Years'
- },
- {
- id: 2,
- name: '2 Years'
- }]
- scope = [{
- id: 1,
- name: 'Testing Mechanism'
- },
- {
- id: 2,
- name: 'Non-Testing Mechanism'
- }]
- messageRes = '';
- status: number;
- productId: number;
- ndaForm = new FormGroup({
- step0: this.formBuilder.group({
- companyName: ['', Validators.required],
- typeOfLegal: ['', Validators.required],
- businessField: ['', Validators.required],
- planId: ['', Validators.required],
- cityId: ['', Validators.required],
- postalCode: ['', [Validators.required, Validators.minLength(4), Validators.maxLength(5), ValidationService.onlyNumber]],
- companyAddress: ['', Validators.required],
- siteAddress: ['', [Validators.required, ValidationService.websiteValidator]]
- }),
- step1: this.formBuilder.group({
- name: ['', Validators.required],
- position: ['', Validators.required],
- email: ['', [Validators.required, ValidationService.emailValidator, Validators.minLength(4)]],
- phoneNumber: ['', [Validators.required, ValidationService.checkTselNumber, ValidationService.onlyNumber]],
- privyId: ['', Validators.required],
- privyEmail: ['', [Validators.required, ValidationService.emailValidator, Validators.minLength(4)]]
- }),
- step2: this.formBuilder.group({
- numberOfParties: ['', Validators.required],
- durationAgreement: ['', Validators.required],
- scope: ['', Validators.required]
- }),
- step3: this.formBuilder.group({
- documentDeed: ['', [Validators.required, ValidationService.fileValidator]],
- documentSiup: ['', [Validators.required, ValidationService.fileValidator]],
- documentNpwp: ['', [Validators.required, ValidationService.fileValidator]],
- documentCredential: ['', [Validators.required, ValidationService.fileValidator]],
- gResponseRecaptcha: ['', Validators.required]
- }),
- step4: this.formBuilder.group({
- accept: ['', Validators.required],
- })
- });
- planId: any;
- subscriptionData: any;
- openSummary: boolean = false;
- mobileView;
- econtract: boolean = false;
- typeNda;
- progressActive;
- subjects: any[] = [];
- activeButton: boolean = false;
- saveDraft: boolean = false;
- idOrder: number;
- typeId;
- dataType: string;
- ndaId: number;
- userId: number;
- historyData: Econtract;
- first = true;
- placeholderBussinesField = '';
- isDraft = false;
- autoFirst = false;
- autoSecond = false;
- autoThird = false;
- statusDraft = false;
- firstDraft = false;
- constructor(
- private formBuilder: FormBuilder,
- private storeFrontService: StoreFrontService,
- public dialog: MatDialog,
- private footerService: FooterService,
- private apiService: ApiService,
- private location: Location,
- private router: Router
- ) {
- this.typeNda = this.router.url.split('/').slice(-1)[0];
- this.userId = JSON.parse(sessionStorage.getItem('data'))?.id;
- this.statusDraft = Boolean(sessionStorage.getItem('statusDraft'));
- if (this.statusDraft) {
- this.idOrder = +this.router.url.split('/').slice(-2)[0];
- this.progress = 4;
- this.firstDraft = true;
- this.selectType();
- }
- this.ndaId = +JSON.parse(sessionStorage.getItem('dataDraftNda'))?.ndaId;
- if (this.ndaId) {
- this.isDraft = true;
- } else {
- this.getLatestDoc();
- this.isDraft = false;
- this.autoFirst = true;
- this.autoSecond = true;
- this.autoThird = true;
- this.productImg = localStorage.getItem('imgProduct');
- this.productName = sessionStorage.getItem('productName');
- this.categoryName = sessionStorage.getItem('productCat');
- }
- if (this.isDraft) {
- this.idOrder = +this.router.url.split('/').slice(-2)[0];
- this.getDataNda();
- this.autoFirst = true;
- this.autoSecond = true;
- this.autoThird = true;
- }
- this.typeId = history.state?.id
- }
- // @HostListener('window:beforeunload', ['$event'])
- // canExit($event) {
- // return $event.returnValue = 'Your Change';
- // }
- canDeactivate(): boolean | Observable<boolean> {
- const widthDialog = this.mobileView ? '322px' : '557px';
- if (!this.first) {
- if (this.progress === 4 && this.typeNda === 'enda') {
- const dialogRef = this.dialog.open(ConfirmNoclickComponent, {
- width: widthDialog,
- panelClass: 'container-candeactive',
- data: {
- header: 'Leave This Page?',
- content: 'Changes you made may not be saved. <br> Do you want to save your changes as draft?',
- btnTrue: 'Save as Draft',
- btnFalse: 'Leave',
- download: false,
- hiddenIcon: true,
- hiddenIconHeader: false,
- hiddenFooter: false,
- hiddenHeader: false,
- hiddenLink: true,
- disableList: true,
- hiddenBtnFalse: false,
- hiddenBtnClose: true,
- hiddenBtnTrue: false,
- hiddenChecked: true,
- hiddenBtnDownload: true
- }
- });
- dialogRef.afterClosed().subscribe((result) => {
- if (result === true) {
- dialogRef.close(true);
- this.dialog.closeAll();
- } else {
- dialogRef.close();
- this.dialog.closeAll();
- }
- })
- return dialogRef.afterClosed();
- } else {
- const dialogRef = this.dialog.open(ConfirmNoclickComponent, {
- width: widthDialog,
- panelClass: 'container-candeactive',
- data: {
- header: 'Leave This Page?',
- content: 'Changes you made may not be saved.',
- btnTrue: 'Stay',
- btnFalse: 'Leave',
- download: false,
- hiddenIcon: true,
- hiddenIconHeader: false,
- hiddenFooter: false,
- hiddenHeader: false,
- hiddenLink: true,
- disableList: true,
- hiddenBtnFalse: false,
- hiddenBtnClose: false,
- hiddenBtnTrue: false,
- hiddenChecked: true,
- hiddenBtnDownload: true
- }
- });
- dialogRef.afterClosed().subscribe((result) => {
- if (result === 'check') {
- dialogRef.close('check');
- this.dialog.closeAll();
- } else {
- dialogRef.close();
- this.dialog.closeAll();
- }
- })
- return dialogRef.afterClosed();
- }
- }
- }
- ngOnInit(): void {
- this.productId = +this.router.url.split('/').slice(-1)[0];
- this.subscriptionData = JSON.parse(localStorage.getItem('subscription'));
- this.getProvince();
- this.getConfig();
- this.getTermsconditions();
- /* istanbul ignore else */
- if (sessionStorage.getItem('order')) {
- this.planId = +JSON.parse(sessionStorage.getItem('order')).plan;
- this.ndaForm.get('step0').get('planId').setValue(this.planId)
- }
- this.getProgress();
- }
- ngAfterViewInit(): void {
- setTimeout(() => {
- this.first = false;
- }, 1500);
- }
- onChange(e, formName) {
- this.ndaForm.get('step3').get(formName).setValue(e)
- this.blurNda(formName);
- this.validateForm;
- }
- async getProvince() {
- await this.storeFrontService.getAllProvincev2().subscribe(
- prov => {
- this.allProvince = prov;
- },
- _error => {
- }
- );
- }
- getConfig() {
- this.storeFrontService.getConfig().subscribe(
- data => {
- this.configFile = data.econtract;
- },
- _error => {
- });
- }
- async getTermsconditions() {
- await this.footerService.getTncContent().subscribe(
- (res: any) => {
- this.data = res?.data[0];
- this.content = this.data.description;
- if (this.data.title) {
- this.title = this.data.title;
- }
- }
- );
- }
- getCity(id) {
- this.openProvince = !this.openProvince;
- this.provincePlaceholder = id.name;
- this.provinceId = id.id;
- this.cityPlaceholder = '';
- this.storeFrontService.getAllCityv2(id.id).subscribe(
- data => {
- this.allCity = data;
- },
- _error => {
- }
- );
- this.openCity = false;
- }
- idBox = 0;
- getDataAllDraft() {
- this.ndaForm.get('step0').get('companyName').setValue(this.historyData?.companyName);
- this.ndaForm.get('step0').get('typeOfLegal').setValue(this.historyData?.typeOfLegal);
- this.legalPlaceholder = this.company.find(x => x.name === this.historyData?.typeOfLegal)?.name;
- this.ndaForm.get('step0').get('businessField').setValue(this.historyData?.businessField);
- if (this.isDraft || this.statusDraft) {
- this.ndaForm.get('step0').get('planId').setValue(this.historyData?.planId);
- }
- this.ndaForm.get('step0').get('cityId').setValue(this.historyData?.city.id);
- this.ndaForm.get('step0').get('postalCode').setValue(this.historyData?.postalCode);
- this.ndaForm.get('step0').get('companyAddress').setValue(this.historyData?.companyAddress);
- this.ndaForm.get('step0').get('siteAddress').setValue(this.historyData?.siteAddress);
- this.ndaForm.get('step1').get('name').setValue(this.historyData?.name);
- this.ndaForm.get('step1').get('position').setValue(this.historyData?.position);
- this.ndaForm.get('step1').get('email').setValue(this.historyData?.email);
- this.ndaForm.get('step1').get('phoneNumber').setValue(this.historyData?.phoneNumber);
- if (this.typeNda === 'enda') {
- this.ndaForm.get('step1').get('privyId').setValue(this.historyData?.privyId);
- this.ndaForm.get('step1').get('privyEmail').setValue(this.historyData?.privyEmail);
- }
- this.ndaForm.get('step2').get('numberOfParties').setValue(this.historyData?.numberOfParties);
- this.ndaForm.get('step2').get('durationAgreement').setValue(this.historyData?.durationAgreement);
- this.ndaForm.get('step2').get('scope').setValue(this.historyData?.scope);
- this.validateForm;
- }
- getLatestDoc() {
- this.apiService.getLatestDraft(this.userId).subscribe(e => {
- if (e) {
- this.historyData = e;
- this.inputDraft();
- }
- })
- }
- getDataNda() {
- const param: DraftParam = {
- ndaId: +this.ndaId,
- userId: +this.userId
- }
- this.apiService.getDataDraft(param)
- .subscribe(
- data => {
- this.historyData = data;
- this.productName = data.product.name;
- this.storeFrontService.sendProductName(data.product.name);
- this.productImg = data.product.image;
- this.categoryName = data.product.category;
- this.typePlan = data.planName;
- this.idOrder = data.orderId;
- if (this.statusDraft && this.firstDraft) {
- this.getDataAllDraft();
- this.firstDraft = false;
- } else {
- this.inputDraft();
- }
- });
- }
- inputDraft() {
- if (this.progress === 1) {
- this.ndaForm.get('step0').get('companyName').setValue(this.historyData?.companyName);
- this.ndaForm.get('step0').get('typeOfLegal').setValue(this.historyData?.typeOfLegal);
- this.legalPlaceholder = this.company.find(x => x.name === this.historyData?.typeOfLegal)?.name;
- const databisnis = this.historyData?.businessField;
- if (databisnis !== 'Banking service' && databisnis !== 'Technology Finance') {
- this.openOther = true;
- }
- this.ndaForm.get('step0').get('businessField').setValue(this.historyData?.businessField);
- let getBussinessField = false;
- this.business.forEach(res => {
- if (res.name === this.historyData?.businessField) {
- res.checked = true;
- getBussinessField = true;
- }
- if (res.name === 'Other' && !getBussinessField) {
- res.checked = true;
- }
- });
- if (this.isDraft) {
- this.ndaForm.get('step0').get('planId').setValue(this.historyData?.planId);
- }
- this.ndaForm.get('step0').get('cityId').setValue(this.historyData?.city.id);
- this.cityPlaceholder = this.historyData?.city.name;
- this.provincePlaceholder = this.historyData?.city.province.name;
- this.ndaForm.get('step0').get('postalCode').setValue(this.historyData?.postalCode);
- this.ndaForm.get('step0').get('companyAddress').setValue(this.historyData?.companyAddress);
- this.ndaForm.get('step0').get('siteAddress').setValue(this.historyData?.siteAddress);
- this.autoFirst = false;
- } else if (this.progress === 2) {
- this.ndaForm.get('step1').get('name').setValue(this.historyData?.name);
- const dataposition = this.historyData?.position;
- if (dataposition !== 'Director' && dataposition !== 'President Director') {
- this.openOtherPosition = true;
- }
- this.ndaForm.get('step1').get('position').setValue(this.historyData?.position);
- let getPosition = false;
- this.position.forEach(res => {
- if (res.name === this.historyData?.position) {
- res.checked = true;
- getPosition = true;
- }
- if (res.name === 'Other' && !getPosition) {
- res.checked = true;
- }
- });
- this.ndaForm.get('step1').get('email').setValue(this.historyData?.email);
- this.ndaForm.get('step1').get('phoneNumber').setValue(this.historyData?.phoneNumber);
- if (this.typeNda === 'enda') {
- this.ndaForm.get('step1').get('privyId').setValue(this.historyData?.privyId);
- this.ndaForm.get('step1').get('privyEmail').setValue(this.historyData?.privyEmail);
- }
- this.autoSecond = false;
- } else if (this.progress === 3) {
- this.ndaForm.get('step2').get('numberOfParties').setValue(this.historyData?.numberOfParties);
- this.numberPlaceholder = this.number.find(x => x.id === +this.historyData?.numberOfParties)?.name;
- this.ndaForm.get('step2').get('durationAgreement').setValue(this.historyData?.durationAgreement);
- this.durationPlaceholder = this.duration.find(x => x.id === +this.historyData?.durationAgreement)?.name;
- this.ndaForm.get('step2').get('scope').setValue(this.historyData?.scope);
- this.scopePlaceholder = this.scope.find(x => x.id === +this.historyData?.scope)?.name;
- this.autoThird = false
- }
- this.validateForm;
- }
- private toFormData<T>(formValue: T) {
- const formData = new FormData();
- for (const key of Object.keys(formValue)) {
- const value = formValue[key];
- formData.append(key, value);
- }
- return formData;
- }
- selectLegalEntity(e) {
- this.legalPlaceholder = e.name;
- this.ndaForm.get('step0').get('typeOfLegal').setValue(e.name);
- this.openCompany = !this.openCompany;
- this.blurNda('typeOfLegal');
- }
- selectCity(e) {
- this.cityPlaceholder = e.name;
- this.openCity = !this.openCity;
- this.ndaForm.get('step0').get('cityId').setValue(e.id);
- this.blurNda('cityId');
- }
- selectPostal(e) {
- this.PostalCodePlaceholder = e.name;
- this.openPostalCode = !this.openPostalCode;
- this.ndaForm.get('step0').get('postalCode').setValue(e.id);
- this.blurNda('postalCode');
- }
- openDdScope() {
- this.openScope = !this.openScope;
- this.openDuration = false;
- this.openNumber = false;
- }
- openDdDuration() {
- this.openDuration = !this.openDuration;
- this.openScope = false;
- this.openNumber = false;
- }
- openDdNumber() {
- this.openNumber = !this.openNumber;
- this.openScope = false;
- this.openDuration = false;
- }
- selectNumber(id, e) {
- this.numberPlaceholder = e;
- this.ndaForm.get('step2').get('numberOfParties').setValue(id);
- this.openNumber = !this.openNumber;
- this.openDuration = false;
- this.openScope = false;
- this.blurNda('numberOfParties');
- this.validateForm;
- }
- selectDuration(id, e) {
- this.durationPlaceholder = e;
- this.ndaForm.get('step2').get('durationAgreement').setValue(id);
- this.openDuration = !this.openDuration;
- this.openScope = false;
- this.openNumber = false;
- this.blurNda('durationAgreement');
- this.validateForm;
- }
- selectScope(id, e) {
- this.scopePlaceholder = e;
- this.ndaForm.get('step2').get('scope').setValue(id.toString());
- this.openScope = !this.openScope;
- this.openDuration = false;
- this.openNumber = false;
- this.blurNda('scope');
- this.validateForm;
- }
- selectRadio(item, e) {
- if (item.id === 3) {
- if (e === 'bisnis') {
- this.openOther = true;
- this.ndaForm.get('step0').get('businessField').setValue('')
- } else {
- this.openOtherPosition = true;
- this.ndaForm.get('step1').get('position').setValue('');
- }
- } else {
- if (e === 'bisnis') {
- this.openOther = false;
- this.ndaForm.get('step0').get('businessField').setValue(item.name)
- } else {
- this.openOtherPosition = false;
- this.ndaForm.get('step1').get('position').setValue(item.name);
- }
- }
- }
- selectType() {
- if (this.typeNda === 'enda') {
- this.ndaForm.get('step1').get('privyId').setValidators([Validators.required]);
- this.ndaForm.get('step1').get('privyId').updateValueAndValidity();
- this.ndaForm.get('step1').get('privyEmail').setValidators([Validators.required, ValidationService.emailValidator]);
- this.ndaForm.get('step1').get('privyEmail').updateValueAndValidity();
- this.ndaForm.get('step3').get('documentCredential').setValue('');
- this.ndaForm.get('step3').get('documentCredential').clearValidators();
- this.ndaForm.get('step3').get('documentCredential').updateValueAndValidity();
- if (!this.statusRecaptcha) {
- this.ndaForm.get('step3').get('gResponseRecaptcha').setValidators([Validators.required]);
- this.ndaForm.get('step3').get('gResponseRecaptcha').updateValueAndValidity();
- } else {
- this.ndaForm.get('step3').get('gResponseRecaptcha').setValue('');
- this.ndaForm.get('step3').get('gResponseRecaptcha').clearValidators();
- this.ndaForm.get('step3').get('gResponseRecaptcha').updateValueAndValidity();
- }
- } else {
- this.ndaForm.get('step1').get('privyId').setValue('');
- this.ndaForm.get('step1').get('privyId').clearValidators();
- this.ndaForm.get('step1').get('privyId').updateValueAndValidity();
- this.ndaForm.get('step1').get('privyEmail').setValue('');
- this.ndaForm.get('step1').get('privyEmail').clearValidators();
- this.ndaForm.get('step1').get('privyEmail').updateValueAndValidity();
- this.ndaForm.get('step3').get('documentCredential').setValidators([Validators.required, ValidationService.fileValidator]);
- this.ndaForm.get('step3').get('documentCredential').updateValueAndValidity();
- if (this.statusRecaptcha) {
- this.ndaForm.get('step3').get('gResponseRecaptcha').setValue('');
- this.ndaForm.get('step3').get('gResponseRecaptcha').clearValidators();
- this.ndaForm.get('step3').get('gResponseRecaptcha').updateValueAndValidity();
- } else {
- this.ndaForm.get('step3').get('gResponseRecaptcha').setValidators([Validators.required]);
- this.ndaForm.get('step3').get('gResponseRecaptcha').updateValueAndValidity();
- }
- }
- }
- openDialog(): void {
- const widthDialog = this.mobileView ? '322px' : '741px';
- const dialogRef = this.dialog.open(PopupComponent, {
- width: widthDialog,
- height: '542px',
- panelClass: 'modal-popup',
- data: {
- title: this.title,
- iconTitle: 'fi icon-support yellow-icon',
- content: this.content,
- btnTrue: 'Submit',
- btnFalse: 'x',
- showFooter: false
- },
- });
- dialogRef.afterClosed().subscribe(result => {
- if (result === true) {
- this.ndaForm.get('step4').get('accept').setValue('1');
- if (this.typeNda === 'enda') {
- this.reSubmitContract();
- } else {
- if (this.isDraft) {
- this.reSubmitContract();
- } else {
- this.onSubmit();
- }
- }
- } else {
- if (this.typeNda !== 'nda')
- this.saveDraft = true;
- setTimeout(() => {
- this.saveDraft = false;
- }, 5000);
- dialogRef.close(true);
- this.dialog.closeAll();
- }
- });
- }
- tncLink(e) {
- if (this.ndaForm.get('step3').get('accept').value === true) {
- this.ndaForm.get('step3').get('accept').setValue('1');
- } else {
- this.ndaForm.get('step3').get('accept').setValue('0');
- }
- }
- blurNda(val) {
- if (val === 'typeOfLegal' || val === 'businessField' || val === 'cityId' || val === 'postalCode' || val === 'companyAddress' || val === 'siteAddress') {
- this.ndaForm.get('step0').get('companyName').markAsTouched();
- }
- if (val === 'companyName' || val === 'businessField' || val === 'cityId' || val === 'postalCode' || val === 'companyAddress' || val === 'siteAddress') {
- this.ndaForm.get('step0').get('typeOfLegal').markAsTouched();
- }
- if (val === 'companyName' || val === 'typeOfLegal' || val === 'cityId' || val === 'postalCode' || val === 'companyAddress' || val === 'siteAddress') {
- this.ndaForm.get('step0').get('businessField').markAsTouched();
- }
- if (val === 'companyName' || val === 'typeOfLegal' || val === 'businessField' || val === 'postalCode' || val === 'companyAddress' || val === 'siteAddress') {
- this.ndaForm.get('step0').get('cityId').markAsTouched();
- }
- if (val === 'companyName' || val === 'typeOfLegal' || val === 'businessField' || val === 'cityId' || val === 'companyAddress' || val === 'siteAddress') {
- this.ndaForm.get('step0').get('postalCode').markAsTouched();
- }
- if (val === 'companyName' || val === 'typeOfLegal' || val === 'businessField' || val === 'cityId' || val === 'postalCode' || val === 'siteAddress') {
- this.ndaForm.get('step0').get('companyAddress').markAsTouched();
- }
- if (val === 'companyName' || val === 'typeOfLegal' || val === 'businessField' || val === 'cityId' || val === 'postalCode' || val === 'companyAddress') {
- this.ndaForm.get('step0').get('siteAddress').markAsTouched();
- }
- if (this.typeNda === 'enda') {
- if (val === 'position' || val === 'name' || val === 'email' || val === 'phoneNumber' || val === 'privyEmail') {
- this.ndaForm.get('step1').get('privyId').markAsTouched();
- }
- if (val === 'position' || val === 'name' || val === 'email' || val === 'phoneNumber' || val === 'privyId') {
- this.ndaForm.get('step1').get('privyEmail').markAsTouched();
- }
- } else {
- if (val === 'position' || val === 'email' || val === 'phoneNumber') {
- this.ndaForm.get('step1').get('name').markAsTouched();
- }
- if (val === 'name' || val === 'email' || val === 'phoneNumber') {
- this.ndaForm.get('step1').get('position').markAsTouched();
- }
- if (val === 'position' || val === 'name' || val === 'phoneNumber') {
- this.ndaForm.get('step1').get('email').markAsTouched();
- }
- if (val === 'position' || val === 'name' || val === 'email') {
- this.ndaForm.get('step1').get('phoneNumber').markAsTouched();
- }
- }
- if (this.typeNda === 'enda') {
- if (val === 'durationAgreement') {
- this.ndaForm.get('step2').get('numberOfParties').markAsTouched();
- }
- if (val === 'numberOfParties') {
- this.ndaForm.get('step2').get('durationAgreement').markAsTouched();
- }
- } else {
- if (val === 'durationAgreement' || val === 'scope') {
- this.ndaForm.get('step2').get('numberOfParties').markAsTouched();
- }
- if (val === 'numberOfParties' || val === 'scope') {
- this.ndaForm.get('step2').get('durationAgreement').markAsTouched();
- }
- if (val === 'numberOfParties' || val === 'durationAgreement') {
- this.ndaForm.get('step2').get('scope').markAsTouched();
- }
- }
- if (this.typeNda === 'enda') {
- if (val === 'documentDeed' || val === 'documentNpwp') {
- this.ndaForm.get('step3').get('documentSiup').markAsTouched();
- }
- if (val === 'documentSiup' || val === 'documentNpwp') {
- this.ndaForm.get('step3').get('documentDeed').markAsTouched();
- }
- if (val === 'documentSiup' || val === 'documentDeed') {
- this.ndaForm.get('step3').get('documentNpwp').markAsTouched();
- }
- } else {
- if (val === 'documentDeed' || val === 'documentNpwp' || val === 'documentCredential') {
- this.ndaForm.get('step3').get('documentSiup').markAsTouched();
- }
- if (val === 'documentSiup' || val === 'documentNpwp' || val === 'documentCredential') {
- this.ndaForm.get('step3').get('documentDeed').markAsTouched();
- }
- if (val === 'documentSiup' || val === 'documentDeed' || val === 'documentCredential') {
- this.ndaForm.get('step3').get('documentNpwp').markAsTouched();
- }
- if (val === 'documentSiup' || val === 'documentDeed' || val === 'documentNpwp') {
- this.ndaForm.get('step3').get('documentCredential').markAsTouched();
- }
- }
- }
- onSubmit() {
- const files = Object.assign(this.ndaForm.get('step0').value, this.ndaForm.get('step1').value, this.ndaForm.get('step2').value, this.ndaForm.get('step3').value)
- const dataRequest = this.toFormData(files);
- this.apiService.postNdaSandboxPlan(dataRequest).subscribe(
- data => {
- if (data?.success) {
- this.errorMsgBool = false;
- this.errorMsg = data.message;
- this.idOrder = data.data.id;
- if (this.typeNda === 'enda') {
- if (this.progress === 3) {
- this.saveDraft = true;
- setTimeout(() => {
- this.saveDraft = false;
- }, 5000);
- this.progress = 4;
- this.selectType();
- }
- } else {
- localStorage.setItem('invoiceId', data?.data.invoice);
- this.dialog.closeAll();
- sessionStorage.removeItem('dataDraftNda');
- sessionStorage.removeItem('statusDraft');
- this.router.navigateByUrl('/api/success', { state: { data: { status: 'nda' } } });
- }
- }
- },
- error => {
- this.resetRecaptcha();
- this.errorMsg = error.error.message;
- this.errorMsgBool = true;
- this.progress === 2;
- });
- }
- submit() {
- if (this.typeNda === 'enda') {
- this.openDialogPreview();
- } else {
- this.openDialog();
- }
- }
- reSubmitContract() {
- const files = Object.assign(this.ndaForm.get('step0').value, this.ndaForm.get('step1').value, this.ndaForm.get('step2').value, this.ndaForm.get('step3').value, this.ndaForm.get('step4').value)
- const dataRequest = { id: this.idOrder, data: files };
- this.apiService.renewalNda(dataRequest).subscribe(
- data => {
- if (data.success) {
- this.errorMsg = data.message;
- this.dialog.closeAll();
- if (this.progress !== 3) {
- sessionStorage.removeItem('dataDraftNda');
- sessionStorage.removeItem('statusDraft');
- this.router.navigateByUrl('/api/success', { state: { data: { status: 'nda' } } });
- } else if (this.typeNda === 'enda') {
- if (this.progress === 3 && this.isDraft) {
- this.saveDraft = true;
- this.progress = 4;
- this.selectType();
- setTimeout(() => {
- this.saveDraft = false;
- }, 5000);
- }
- }
- }
- },
- error => {
- this.errorMsg = error.error.message;
- });
- }
- resetDoc() {
- }
- resolved(captchaResponse: string) {
- this.alredyResolve = true;
- this.ndaForm.get('step3').get('gResponseRecaptcha').setValue(captchaResponse);
- this.validateForm;
- }
- resetRecaptcha() {
- /* istanbul ignore if */
- if (this.alredyResolve) {
- grecaptcha.reset();
- this.alredyResolve = false;
- this.ndaForm.get('step3').get('gResponseRecaptcha').setValue('')
- }
- }
- nextForm(e) {
- if (e === 1) {
- this.progress = 2;
- this.selectType();
- this.sendProgress('activeButton2');
- if (this.historyData && this.autoSecond) {
- if (this.isDraft) {
- this.getDataNda();
- } else {
- this.getLatestDoc();
- }
- }
- } else if (e === 2) {
- this.progress = 3;
- this.selectType();
- if (this.typeNda === 'enda') {
- this.checkPrivy();
- this.selectType();
- window.scrollTo(0, 0);
- } else {
- this.progress = 3;
- this.selectType();
- window.scrollTo(0, 0);
- }
- this.sendProgress('activeButton3');
- if (this.historyData && this.autoThird) {
- if (this.isDraft) {
- this.getDataNda();
- } else {
- this.getLatestDoc();
- }
- }
- } else {
- if (this.typeNda=== 'enda') {
- this.onSubmit();
- // this.sendProgress('submit');
- this.selectType();
- window.scrollTo(0, 0);
- this.storeFrontService.changeSubject('submit');
- } else {
- this.storeFrontService.changeSubject('submit');
- this.progress = 4;
- this.selectType();
- window.scrollTo(0, 0);
- }
- }
- }
- backForm(e) {
- if (e === 4) {
- this.progress = 3;
- this.resetRecaptcha();
- this.selectType();
- } else if (e === 3) {
- this.progress = 2;
- this.selectType();
- } else {
- this.progress = 1;
- this.selectType();
- }
- }
- openDialogPrivy(): void {
- const widthDialog = this.mobileView ? '254px' : '754px';
- const dialogRef = this.dialog.open(ConfirmPrivyComponent, {
- width: widthDialog,
- height: '254px',
- disableClose: true,
- data: {
- iconTitle: 'fi icon-support yellow-icon',
- btnClose: 'Close',
- btnFalse: 'x',
- showFooter: false,
- message: 'Your Account Has Been Banned',
- },
- panelClass: 'modal-popups'
- });
- dialogRef.afterClosed().subscribe(result => {
- if (result === true) {
- this.storeFrontService.logout();
- this.router.navigateByUrl('/login');
- }
- });
- }
- checkPrivy() {
- const param = {
- userId: this.ndaForm.get('step1').get('privyId').value,
- email: this.ndaForm.get('step1').get('privyEmail').value
- };
- this.apiService.checkPrivyAccount(param)
- .subscribe(res => {
- if (res.status === 200) {
- this.messageRes = res.message;
- this.status = res.status;
- this.progress = 3;
- this.selectType();
- window.scrollTo(0, 0);
- } else if (res.status === 404) {
- this.messageRes = res.message;
- this.status = res.status;
- this.progress = 2;
- this.selectType();
- window.scrollTo(0, 0);
- } else if (res.status === 403) {
- this.openDialogPrivy();
- this.messageRes = res.message;
- this.status = res.status;
- this.progress = 2;
- this.selectType();
- window.scrollTo(0, 0);
- } else {
- this.messageRes = res.message;
- this.status = res.status;
- this.progress = 2;
- this.selectType();
- window.scrollTo(0, 0);
- }
- }, error => {
- this.messageRes = error.message;
- this.status = error.status;
- this.progress = 2;
- this.selectType();
- window.scrollTo(0, 0);
- })
- }
- sendProgress(e) {
- if (e === 'activeButton1') {
- this.storeFrontService.changeSubject('activeButton1');
- } else if (e === 'activeButton2') {
- this.storeFrontService.changeSubject('activeButton2');
- } else if (e === 'activeButton3') {
- this.storeFrontService.changeSubject('activeButton3');
- } else if (e === 'activeButton4') {
- this.storeFrontService.changeSubject('submit');
- }
- }
- get validateForm() {
- if (this.progress === 1) {
- if (this.ndaForm.get('step0').valid) {
- return this.sendProgress('activeButton1');
- } else {
- return this.sendProgress('false');
- }
- }
- else if (this.progress === 2) {
- if (this.ndaForm.get('step1').valid) {
- return this.sendProgress('activeButton2');
- } else {
- return this.sendProgress('false');
- }
- }
- else if (this.progress === 3) {
- if (this.ndaForm.get('step2').valid) {
- return this.sendProgress('activeButton3');
- } else {
- return this.sendProgress('false');
- }
- }
- else if (this.progress === 4) {
- if (this.ndaForm.get('step3').valid) {
- return this.sendProgress('activeButton4');
- } else {
- return this.sendProgress('false');
- }
- }
- }
- getProgress() {
- this.storeFrontService.getProgress().subscribe(res => {
- if (res.text === "0") {
- this.progress = 1;
- this.selectType();
- window.scrollTo(0, 0);
- if (this.historyData && this.autoFirst) {
- if (this.isDraft) {
- this.getDataNda();
- } else {
- this.getLatestDoc();
- }
- }
- } else if (res.text === "1") {
- this.progress = 2;
- this.selectType();
- window.scrollTo(0, 0);
- if (this.historyData && this.autoSecond) {
- if (this.isDraft) {
- this.getDataNda();
- } else {
- this.getLatestDoc();
- }
- }
- } else if (res.text === "2") {
- if (this.typeNda === 'enda') {
- this.checkPrivy();
- // this.progress = 3;
- // this.selectType();
- // window.scrollTo(0, 0);
- } else {
- this.progress = 3;
- this.selectType();
- window.scrollTo(0, 0);
- }
- if (this.historyData && this.autoThird) {
- if (this.isDraft) {
- this.getDataNda();
- } else {
- this.getLatestDoc();
- }
- }
- } else if (res.text === "3") {
- if (this.typeNda === 'enda') {
- if (this.idOrder) {
- this.reSubmitContract();
- } else {
- this.onSubmit();
- }
- } else {
- this.progress = 4;
- this.selectType();
- window.scrollTo(0, 0);
- }
- } else if (res.text === "4") {
- if (this.typeNda === 'enda') {
- this.openDialogPreview();
- } else {
- this.openDialog();
- }
- } else if (res.text === '00') {
- this.location.back();
- }
- })
- }
- openDialogPreview() {
- const widthDialog = this.mobileView ? '322px' : '741px';
- const dialogRef = this.dialog.open(ConfirmNoclickComponent, {
- width: widthDialog,
- panelClass: 'container-download-preview',
- data: {
- header: 'Contract Preview',
- content: 'Before continue to the next step, please make sure that you have preview and read the contract. You can preview it by downloading the contract below.',
- btnTrue: 'Next',
- btnFalse: 'Cancel',
- download: true,
- hiddenIcon: true,
- hiddenIconHeader: true,
- hiddenFooter: false,
- hiddenHeader: false,
- hiddenLink: false,
- disableList: true,
- hiddenBtnFalse: false,
- hiddenBtnClose: false,
- hiddenBtnTrue: false,
- hiddenChecked: false,
- hiddenBtnDownload: false,
- id: this.idOrder,
- type: 'enda'
- }
- });
- dialogRef.afterClosed().subscribe(res => {
- if (res === 'check') {
- this.openDialog();
- dialogRef.close(true);
- } else {
- dialogRef.close(true);
- this.saveDraft = true;
- setTimeout(() => {
- this.saveDraft = false;
- }, 5000);
- }
- })
- }
- ngOnDestroy() {
- sessionStorage.removeItem('dataDraftNda');
- sessionStorage.removeItem('statusDraft');
- this.dialog.closeAll();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement