Advertisement
coffeecode12

Untitled

Oct 4th, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.66 KB | None | 0 0
  1. import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
  2. import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
  3. import { MatDialog, MatDialogRef } from '@angular/material/dialog';
  4. import { MatStepper } from '@angular/material/stepper';
  5. import { PopupComponent } from '@shared/component/popup/popup.component';
  6. import { FooterService } from 'app/store-front/services/footer.service';
  7. import { StoreFrontService } from 'app/store-front/services/store-front.service';
  8. import { ValidationService } from 'app/validation.service';
  9. import { environment } from 'environments/environment';
  10. import { ApiService } from '../api.service';
  11. import { Location } from '@angular/common';
  12. import { Router } from '@angular/router';
  13. import { CanExit } from 'app/_guard/auth-guard.service';
  14. import { Observable } from 'rxjs';
  15. import { ConfirmNoclickComponent } from '@shared/component/confirm-noclick/confirm-noclick.component';
  16. import { DraftParam } from 'app/_core/domain/enda';
  17. import { Econtract } from 'app/_core/domain/econtract';
  18. import { ConfirmPrivyComponent } from '@shared/component/confirm-privy/confirm-privy.component';
  19. declare var grecaptcha: any;
  20.  
  21. @Component({
  22. selector: 'app-nda',
  23. templateUrl: './nda.component.html',
  24. styleUrls: ['./nda.component.scss']
  25. })
  26. export class NDAComponent implements OnInit, CanExit, AfterViewInit, OnDestroy {
  27.  
  28. @ViewChild('stepper') stepper: MatStepper;
  29.  
  30. userEnterprise: boolean = false;
  31. errorMsg: string;
  32. errorMsgBool: boolean = false;
  33. result: boolean = true;
  34. public loading = false;
  35. openContent: boolean = false;
  36. openCompany: boolean = false;
  37. openProvince: boolean = false;
  38. openCity: boolean = false;
  39. openPostalCode: boolean = false;
  40. openNumber: boolean = false;
  41. openDuration: boolean = false;
  42. openScope: boolean = false;
  43. select: boolean = false;
  44. openOther: boolean = false;
  45. openOtherPosition: boolean = false;
  46. statusRecaptcha: boolean = environment.disableRecaptcha;
  47. // ndaForm: FormGroup;
  48. btnDisable: boolean = false;
  49. alredyResolve = false;
  50. selectBussiness = '';
  51. selectPosition = '';
  52. fieldTigalabel = '';
  53. accountInformation: any;
  54. allProvince: any;
  55. allCity: any;
  56. companyPlaceholder = 'Company Name';
  57. provincePlaceholder = '';
  58. cityPlaceholder = '';
  59. PostalCodePlaceholder = '';
  60. siteAddPlaceholder = 'Enter Your Site Address';
  61. legalPlaceholder = '';
  62. numberPlaceholder = '';
  63. durationPlaceholder = '';
  64. scopePlaceholder = '';
  65. provinceId: number;
  66. otherPlaceholder = 'Enter Your Other Bussiness Field';
  67. otherAttPlaceholder = 'Enter Your Position of Representative or Attorney';
  68. attorneyPlaceholder = 'Enter Your Name of Representative or Attorney';
  69. progress: number = 1;
  70. idProv: number;
  71. plandId: number;
  72. title: string;
  73. content: string;
  74. data: any;
  75. name: any;
  76. configFile;
  77. configDoc;
  78. count;
  79. fields;
  80. productName: string = ''
  81. categoryName: string = '';
  82. productImg: string = '';
  83. typePlan: string = '';
  84.  
  85. targetFilename: any;
  86.  
  87. business = [{
  88. id: 1,
  89. name: 'Banking service',
  90. checked: false
  91. }, {
  92. id: 2,
  93. name: 'Technology Finance',
  94. checked: false
  95. }, {
  96. id: 3,
  97. name: 'Other',
  98. checked: false
  99. }]
  100.  
  101. position = [{
  102. id: 1,
  103. name: 'Director',
  104. checked: false
  105. }, {
  106. id: 2,
  107. name: 'President Director',
  108. checked: false
  109. }, {
  110. id: 3,
  111. name: 'Other',
  112. checked: false
  113. }]
  114.  
  115. company = [{
  116. id: 1,
  117. name: 'PT Perseroan Terbatas'
  118. },
  119. {
  120. id: 2,
  121. name: 'Koperasi'
  122. },
  123. {
  124. id: 3,
  125. name: 'Instansi Pemerintah'
  126. },
  127. {
  128. id: 4,
  129. name: 'CV Persekutuan Komanditer'
  130. }]
  131.  
  132. number = [{
  133. id: 1,
  134. name: 'Bipartit'
  135. },
  136. {
  137. id: 2,
  138. name: 'Tripartit'
  139. }]
  140.  
  141.  
  142. duration = [{
  143. id: 1,
  144. name: '1 Years'
  145. },
  146. {
  147. id: 2,
  148. name: '2 Years'
  149. }]
  150.  
  151. scope = [{
  152. id: 1,
  153. name: 'Testing Mechanism'
  154. },
  155. {
  156. id: 2,
  157. name: 'Non-Testing Mechanism'
  158. }]
  159.  
  160. messageRes = '';
  161. status: number;
  162. productId: number;
  163. ndaForm = new FormGroup({
  164. step0: this.formBuilder.group({
  165. companyName: ['', Validators.required],
  166. typeOfLegal: ['', Validators.required],
  167. businessField: ['', Validators.required],
  168. planId: ['', Validators.required],
  169. cityId: ['', Validators.required],
  170. postalCode: ['', [Validators.required, Validators.minLength(4), Validators.maxLength(5), ValidationService.onlyNumber]],
  171. companyAddress: ['', Validators.required],
  172. siteAddress: ['', [Validators.required, ValidationService.websiteValidator]]
  173. }),
  174. step1: this.formBuilder.group({
  175. name: ['', Validators.required],
  176. position: ['', Validators.required],
  177. email: ['', [Validators.required, ValidationService.emailValidator, Validators.minLength(4)]],
  178. phoneNumber: ['', [Validators.required, ValidationService.checkTselNumber, ValidationService.onlyNumber]],
  179. privyId: ['', Validators.required],
  180. privyEmail: ['', [Validators.required, ValidationService.emailValidator, Validators.minLength(4)]]
  181. }),
  182. step2: this.formBuilder.group({
  183. numberOfParties: ['', Validators.required],
  184. durationAgreement: ['', Validators.required],
  185. scope: ['', Validators.required]
  186. }),
  187. step3: this.formBuilder.group({
  188. documentDeed: ['', [Validators.required, ValidationService.fileValidator]],
  189. documentSiup: ['', [Validators.required, ValidationService.fileValidator]],
  190. documentNpwp: ['', [Validators.required, ValidationService.fileValidator]],
  191. documentCredential: ['', [Validators.required, ValidationService.fileValidator]],
  192. gResponseRecaptcha: ['', Validators.required]
  193. }),
  194. step4: this.formBuilder.group({
  195. accept: ['', Validators.required],
  196. })
  197. });
  198. planId: any;
  199. subscriptionData: any;
  200. openSummary: boolean = false;
  201. mobileView;
  202. econtract: boolean = false;
  203. typeNda;
  204. progressActive;
  205. subjects: any[] = [];
  206. activeButton: boolean = false;
  207. saveDraft: boolean = false;
  208. idOrder: number;
  209. typeId;
  210. dataType: string;
  211. ndaId: number;
  212. userId: number;
  213. historyData: Econtract;
  214. first = true;
  215. placeholderBussinesField = '';
  216. isDraft = false;
  217. autoFirst = false;
  218. autoSecond = false;
  219. autoThird = false;
  220. statusDraft = false;
  221. firstDraft = false;
  222.  
  223. constructor(
  224. private formBuilder: FormBuilder,
  225. private storeFrontService: StoreFrontService,
  226. public dialog: MatDialog,
  227. private footerService: FooterService,
  228. private apiService: ApiService,
  229. private location: Location,
  230. private router: Router
  231. ) {
  232. this.typeNda = this.router.url.split('/').slice(-1)[0];
  233. this.userId = JSON.parse(sessionStorage.getItem('data'))?.id;
  234. this.statusDraft = Boolean(sessionStorage.getItem('statusDraft'));
  235. if (this.statusDraft) {
  236. this.idOrder = +this.router.url.split('/').slice(-2)[0];
  237.  
  238. this.progress = 4;
  239. this.firstDraft = true;
  240. this.selectType();
  241. }
  242. this.ndaId = +JSON.parse(sessionStorage.getItem('dataDraftNda'))?.ndaId;
  243.  
  244. if (this.ndaId) {
  245. this.isDraft = true;
  246. } else {
  247. this.getLatestDoc();
  248. this.isDraft = false;
  249. this.autoFirst = true;
  250. this.autoSecond = true;
  251. this.autoThird = true;
  252. this.productImg = localStorage.getItem('imgProduct');
  253. this.productName = sessionStorage.getItem('productName');
  254. this.categoryName = sessionStorage.getItem('productCat');
  255. }
  256.  
  257. if (this.isDraft) {
  258. this.idOrder = +this.router.url.split('/').slice(-2)[0];
  259. this.getDataNda();
  260. this.autoFirst = true;
  261. this.autoSecond = true;
  262. this.autoThird = true;
  263. }
  264. this.typeId = history.state?.id
  265. }
  266.  
  267. // @HostListener('window:beforeunload', ['$event'])
  268. // canExit($event) {
  269. // return $event.returnValue = 'Your Change';
  270. // }
  271.  
  272. canDeactivate(): boolean | Observable<boolean> {
  273. const widthDialog = this.mobileView ? '322px' : '557px';
  274. if (!this.first) {
  275. if (this.progress === 4 && this.typeNda === 'enda') {
  276. const dialogRef = this.dialog.open(ConfirmNoclickComponent, {
  277. width: widthDialog,
  278. panelClass: 'container-candeactive',
  279. data: {
  280. header: 'Leave This Page?',
  281. content: 'Changes you made may not be saved. <br> Do you want to save your changes as draft?',
  282. btnTrue: 'Save as Draft',
  283. btnFalse: 'Leave',
  284. download: false,
  285. hiddenIcon: true,
  286. hiddenIconHeader: false,
  287. hiddenFooter: false,
  288. hiddenHeader: false,
  289. hiddenLink: true,
  290. disableList: true,
  291. hiddenBtnFalse: false,
  292. hiddenBtnClose: true,
  293. hiddenBtnTrue: false,
  294. hiddenChecked: true,
  295. hiddenBtnDownload: true
  296. }
  297. });
  298.  
  299. dialogRef.afterClosed().subscribe((result) => {
  300. if (result === true) {
  301. dialogRef.close(true);
  302. this.dialog.closeAll();
  303. } else {
  304. dialogRef.close();
  305. this.dialog.closeAll();
  306. }
  307. })
  308. return dialogRef.afterClosed();
  309.  
  310. } else {
  311. const dialogRef = this.dialog.open(ConfirmNoclickComponent, {
  312. width: widthDialog,
  313. panelClass: 'container-candeactive',
  314. data: {
  315. header: 'Leave This Page?',
  316. content: 'Changes you made may not be saved.',
  317. btnTrue: 'Stay',
  318. btnFalse: 'Leave',
  319. download: false,
  320. hiddenIcon: true,
  321. hiddenIconHeader: false,
  322. hiddenFooter: false,
  323. hiddenHeader: false,
  324. hiddenLink: true,
  325. disableList: true,
  326. hiddenBtnFalse: false,
  327. hiddenBtnClose: false,
  328. hiddenBtnTrue: false,
  329. hiddenChecked: true,
  330. hiddenBtnDownload: true
  331. }
  332. });
  333. dialogRef.afterClosed().subscribe((result) => {
  334. if (result === 'check') {
  335. dialogRef.close('check');
  336. this.dialog.closeAll();
  337. } else {
  338. dialogRef.close();
  339. this.dialog.closeAll();
  340. }
  341. })
  342. return dialogRef.afterClosed();
  343. }
  344. }
  345. }
  346.  
  347. ngOnInit(): void {
  348. this.productId = +this.router.url.split('/').slice(-1)[0];
  349. this.subscriptionData = JSON.parse(localStorage.getItem('subscription'));
  350. this.getProvince();
  351. this.getConfig();
  352. this.getTermsconditions();
  353. /* istanbul ignore else */
  354. if (sessionStorage.getItem('order')) {
  355. this.planId = +JSON.parse(sessionStorage.getItem('order')).plan;
  356. this.ndaForm.get('step0').get('planId').setValue(this.planId)
  357. }
  358. this.getProgress();
  359. }
  360.  
  361. ngAfterViewInit(): void {
  362. setTimeout(() => {
  363. this.first = false;
  364. }, 1500);
  365. }
  366.  
  367. onChange(e, formName) {
  368. this.ndaForm.get('step3').get(formName).setValue(e)
  369. this.blurNda(formName);
  370. this.validateForm;
  371. }
  372.  
  373. async getProvince() {
  374. await this.storeFrontService.getAllProvincev2().subscribe(
  375. prov => {
  376. this.allProvince = prov;
  377. },
  378. _error => {
  379. }
  380. );
  381. }
  382.  
  383. getConfig() {
  384. this.storeFrontService.getConfig().subscribe(
  385. data => {
  386. this.configFile = data.econtract;
  387. },
  388. _error => {
  389. });
  390. }
  391.  
  392. async getTermsconditions() {
  393. await this.footerService.getTncContent().subscribe(
  394. (res: any) => {
  395. this.data = res?.data[0];
  396. this.content = this.data.description;
  397. if (this.data.title) {
  398. this.title = this.data.title;
  399. }
  400. }
  401. );
  402. }
  403.  
  404. getCity(id) {
  405. this.openProvince = !this.openProvince;
  406. this.provincePlaceholder = id.name;
  407. this.provinceId = id.id;
  408. this.cityPlaceholder = '';
  409. this.storeFrontService.getAllCityv2(id.id).subscribe(
  410. data => {
  411. this.allCity = data;
  412. },
  413. _error => {
  414. }
  415. );
  416. this.openCity = false;
  417. }
  418. idBox = 0;
  419.  
  420. getDataAllDraft() {
  421. this.ndaForm.get('step0').get('companyName').setValue(this.historyData?.companyName);
  422. this.ndaForm.get('step0').get('typeOfLegal').setValue(this.historyData?.typeOfLegal);
  423. this.legalPlaceholder = this.company.find(x => x.name === this.historyData?.typeOfLegal)?.name;
  424. this.ndaForm.get('step0').get('businessField').setValue(this.historyData?.businessField);
  425. if (this.isDraft || this.statusDraft) {
  426. this.ndaForm.get('step0').get('planId').setValue(this.historyData?.planId);
  427. }
  428. this.ndaForm.get('step0').get('cityId').setValue(this.historyData?.city.id);
  429. this.ndaForm.get('step0').get('postalCode').setValue(this.historyData?.postalCode);
  430. this.ndaForm.get('step0').get('companyAddress').setValue(this.historyData?.companyAddress);
  431. this.ndaForm.get('step0').get('siteAddress').setValue(this.historyData?.siteAddress);
  432. this.ndaForm.get('step1').get('name').setValue(this.historyData?.name);
  433. this.ndaForm.get('step1').get('position').setValue(this.historyData?.position);
  434. this.ndaForm.get('step1').get('email').setValue(this.historyData?.email);
  435. this.ndaForm.get('step1').get('phoneNumber').setValue(this.historyData?.phoneNumber);
  436.  
  437. if (this.typeNda === 'enda') {
  438. this.ndaForm.get('step1').get('privyId').setValue(this.historyData?.privyId);
  439. this.ndaForm.get('step1').get('privyEmail').setValue(this.historyData?.privyEmail);
  440. }
  441. this.ndaForm.get('step2').get('numberOfParties').setValue(this.historyData?.numberOfParties);
  442. this.ndaForm.get('step2').get('durationAgreement').setValue(this.historyData?.durationAgreement);
  443. this.ndaForm.get('step2').get('scope').setValue(this.historyData?.scope);
  444.  
  445.  
  446. this.validateForm;
  447. }
  448.  
  449. getLatestDoc() {
  450. this.apiService.getLatestDraft(this.userId).subscribe(e => {
  451. if (e) {
  452. this.historyData = e;
  453. this.inputDraft();
  454. }
  455. })
  456. }
  457. getDataNda() {
  458. const param: DraftParam = {
  459. ndaId: +this.ndaId,
  460. userId: +this.userId
  461. }
  462. this.apiService.getDataDraft(param)
  463. .subscribe(
  464. data => {
  465. this.historyData = data;
  466. this.productName = data.product.name;
  467. this.storeFrontService.sendProductName(data.product.name);
  468. this.productImg = data.product.image;
  469. this.categoryName = data.product.category;
  470. this.typePlan = data.planName;
  471. this.idOrder = data.orderId;
  472. if (this.statusDraft && this.firstDraft) {
  473. this.getDataAllDraft();
  474. this.firstDraft = false;
  475. } else {
  476. this.inputDraft();
  477. }
  478. });
  479. }
  480.  
  481. inputDraft() {
  482. if (this.progress === 1) {
  483. this.ndaForm.get('step0').get('companyName').setValue(this.historyData?.companyName);
  484. this.ndaForm.get('step0').get('typeOfLegal').setValue(this.historyData?.typeOfLegal);
  485. this.legalPlaceholder = this.company.find(x => x.name === this.historyData?.typeOfLegal)?.name;
  486. const databisnis = this.historyData?.businessField;
  487. if (databisnis !== 'Banking service' && databisnis !== 'Technology Finance') {
  488. this.openOther = true;
  489. }
  490. this.ndaForm.get('step0').get('businessField').setValue(this.historyData?.businessField);
  491.  
  492.  
  493. let getBussinessField = false;
  494. this.business.forEach(res => {
  495. if (res.name === this.historyData?.businessField) {
  496. res.checked = true;
  497. getBussinessField = true;
  498. }
  499. if (res.name === 'Other' && !getBussinessField) {
  500. res.checked = true;
  501. }
  502. });
  503. if (this.isDraft) {
  504. this.ndaForm.get('step0').get('planId').setValue(this.historyData?.planId);
  505. }
  506. this.ndaForm.get('step0').get('cityId').setValue(this.historyData?.city.id);
  507. this.cityPlaceholder = this.historyData?.city.name;
  508. this.provincePlaceholder = this.historyData?.city.province.name;
  509. this.ndaForm.get('step0').get('postalCode').setValue(this.historyData?.postalCode);
  510. this.ndaForm.get('step0').get('companyAddress').setValue(this.historyData?.companyAddress);
  511. this.ndaForm.get('step0').get('siteAddress').setValue(this.historyData?.siteAddress);
  512. this.autoFirst = false;
  513. } else if (this.progress === 2) {
  514. this.ndaForm.get('step1').get('name').setValue(this.historyData?.name);
  515. const dataposition = this.historyData?.position;
  516. if (dataposition !== 'Director' && dataposition !== 'President Director') {
  517. this.openOtherPosition = true;
  518. }
  519. this.ndaForm.get('step1').get('position').setValue(this.historyData?.position);
  520. let getPosition = false;
  521. this.position.forEach(res => {
  522. if (res.name === this.historyData?.position) {
  523. res.checked = true;
  524. getPosition = true;
  525. }
  526. if (res.name === 'Other' && !getPosition) {
  527. res.checked = true;
  528. }
  529. });
  530. this.ndaForm.get('step1').get('email').setValue(this.historyData?.email);
  531. this.ndaForm.get('step1').get('phoneNumber').setValue(this.historyData?.phoneNumber);
  532.  
  533. if (this.typeNda === 'enda') {
  534. this.ndaForm.get('step1').get('privyId').setValue(this.historyData?.privyId);
  535. this.ndaForm.get('step1').get('privyEmail').setValue(this.historyData?.privyEmail);
  536. }
  537. this.autoSecond = false;
  538. } else if (this.progress === 3) {
  539. this.ndaForm.get('step2').get('numberOfParties').setValue(this.historyData?.numberOfParties);
  540. this.numberPlaceholder = this.number.find(x => x.id === +this.historyData?.numberOfParties)?.name;
  541.  
  542. this.ndaForm.get('step2').get('durationAgreement').setValue(this.historyData?.durationAgreement);
  543. this.durationPlaceholder = this.duration.find(x => x.id === +this.historyData?.durationAgreement)?.name;
  544.  
  545. this.ndaForm.get('step2').get('scope').setValue(this.historyData?.scope);
  546. this.scopePlaceholder = this.scope.find(x => x.id === +this.historyData?.scope)?.name;
  547. this.autoThird = false
  548. }
  549.  
  550. this.validateForm;
  551. }
  552.  
  553.  
  554.  
  555. private toFormData<T>(formValue: T) {
  556. const formData = new FormData();
  557. for (const key of Object.keys(formValue)) {
  558. const value = formValue[key];
  559. formData.append(key, value);
  560. }
  561. return formData;
  562. }
  563.  
  564. selectLegalEntity(e) {
  565. this.legalPlaceholder = e.name;
  566. this.ndaForm.get('step0').get('typeOfLegal').setValue(e.name);
  567. this.openCompany = !this.openCompany;
  568. this.blurNda('typeOfLegal');
  569. }
  570.  
  571. selectCity(e) {
  572. this.cityPlaceholder = e.name;
  573. this.openCity = !this.openCity;
  574. this.ndaForm.get('step0').get('cityId').setValue(e.id);
  575. this.blurNda('cityId');
  576. }
  577.  
  578. selectPostal(e) {
  579. this.PostalCodePlaceholder = e.name;
  580. this.openPostalCode = !this.openPostalCode;
  581. this.ndaForm.get('step0').get('postalCode').setValue(e.id);
  582. this.blurNda('postalCode');
  583. }
  584.  
  585. openDdScope() {
  586. this.openScope = !this.openScope;
  587. this.openDuration = false;
  588. this.openNumber = false;
  589. }
  590.  
  591. openDdDuration() {
  592. this.openDuration = !this.openDuration;
  593. this.openScope = false;
  594. this.openNumber = false;
  595. }
  596.  
  597. openDdNumber() {
  598. this.openNumber = !this.openNumber;
  599. this.openScope = false;
  600. this.openDuration = false;
  601. }
  602.  
  603. selectNumber(id, e) {
  604. this.numberPlaceholder = e;
  605. this.ndaForm.get('step2').get('numberOfParties').setValue(id);
  606. this.openNumber = !this.openNumber;
  607. this.openDuration = false;
  608. this.openScope = false;
  609. this.blurNda('numberOfParties');
  610. this.validateForm;
  611. }
  612.  
  613. selectDuration(id, e) {
  614. this.durationPlaceholder = e;
  615. this.ndaForm.get('step2').get('durationAgreement').setValue(id);
  616. this.openDuration = !this.openDuration;
  617. this.openScope = false;
  618. this.openNumber = false;
  619. this.blurNda('durationAgreement');
  620. this.validateForm;
  621. }
  622.  
  623. selectScope(id, e) {
  624. this.scopePlaceholder = e;
  625. this.ndaForm.get('step2').get('scope').setValue(id.toString());
  626. this.openScope = !this.openScope;
  627. this.openDuration = false;
  628. this.openNumber = false;
  629. this.blurNda('scope');
  630. this.validateForm;
  631. }
  632.  
  633. selectRadio(item, e) {
  634. if (item.id === 3) {
  635. if (e === 'bisnis') {
  636. this.openOther = true;
  637. this.ndaForm.get('step0').get('businessField').setValue('')
  638. } else {
  639. this.openOtherPosition = true;
  640. this.ndaForm.get('step1').get('position').setValue('');
  641. }
  642. } else {
  643. if (e === 'bisnis') {
  644. this.openOther = false;
  645. this.ndaForm.get('step0').get('businessField').setValue(item.name)
  646. } else {
  647. this.openOtherPosition = false;
  648. this.ndaForm.get('step1').get('position').setValue(item.name);
  649. }
  650. }
  651. }
  652.  
  653. selectType() {
  654. if (this.typeNda === 'enda') {
  655. this.ndaForm.get('step1').get('privyId').setValidators([Validators.required]);
  656. this.ndaForm.get('step1').get('privyId').updateValueAndValidity();
  657. this.ndaForm.get('step1').get('privyEmail').setValidators([Validators.required, ValidationService.emailValidator]);
  658. this.ndaForm.get('step1').get('privyEmail').updateValueAndValidity();
  659. this.ndaForm.get('step3').get('documentCredential').setValue('');
  660. this.ndaForm.get('step3').get('documentCredential').clearValidators();
  661. this.ndaForm.get('step3').get('documentCredential').updateValueAndValidity();
  662. if (!this.statusRecaptcha) {
  663. this.ndaForm.get('step3').get('gResponseRecaptcha').setValidators([Validators.required]);
  664. this.ndaForm.get('step3').get('gResponseRecaptcha').updateValueAndValidity();
  665. } else {
  666. this.ndaForm.get('step3').get('gResponseRecaptcha').setValue('');
  667. this.ndaForm.get('step3').get('gResponseRecaptcha').clearValidators();
  668. this.ndaForm.get('step3').get('gResponseRecaptcha').updateValueAndValidity();
  669. }
  670. } else {
  671. this.ndaForm.get('step1').get('privyId').setValue('');
  672. this.ndaForm.get('step1').get('privyId').clearValidators();
  673. this.ndaForm.get('step1').get('privyId').updateValueAndValidity();
  674. this.ndaForm.get('step1').get('privyEmail').setValue('');
  675. this.ndaForm.get('step1').get('privyEmail').clearValidators();
  676. this.ndaForm.get('step1').get('privyEmail').updateValueAndValidity();
  677. this.ndaForm.get('step3').get('documentCredential').setValidators([Validators.required, ValidationService.fileValidator]);
  678. this.ndaForm.get('step3').get('documentCredential').updateValueAndValidity();
  679. if (this.statusRecaptcha) {
  680. this.ndaForm.get('step3').get('gResponseRecaptcha').setValue('');
  681. this.ndaForm.get('step3').get('gResponseRecaptcha').clearValidators();
  682. this.ndaForm.get('step3').get('gResponseRecaptcha').updateValueAndValidity();
  683. } else {
  684. this.ndaForm.get('step3').get('gResponseRecaptcha').setValidators([Validators.required]);
  685. this.ndaForm.get('step3').get('gResponseRecaptcha').updateValueAndValidity();
  686. }
  687. }
  688. }
  689.  
  690. openDialog(): void {
  691. const widthDialog = this.mobileView ? '322px' : '741px';
  692. const dialogRef = this.dialog.open(PopupComponent, {
  693. width: widthDialog,
  694. height: '542px',
  695. panelClass: 'modal-popup',
  696. data: {
  697. title: this.title,
  698. iconTitle: 'fi icon-support yellow-icon',
  699. content: this.content,
  700. btnTrue: 'Submit',
  701. btnFalse: 'x',
  702. showFooter: false
  703. },
  704. });
  705. dialogRef.afterClosed().subscribe(result => {
  706. if (result === true) {
  707. this.ndaForm.get('step4').get('accept').setValue('1');
  708. if (this.typeNda === 'enda') {
  709. this.reSubmitContract();
  710. } else {
  711. if (this.isDraft) {
  712. this.reSubmitContract();
  713. } else {
  714. this.onSubmit();
  715. }
  716. }
  717. } else {
  718. if (this.typeNda !== 'nda')
  719. this.saveDraft = true;
  720. setTimeout(() => {
  721. this.saveDraft = false;
  722. }, 5000);
  723. dialogRef.close(true);
  724. this.dialog.closeAll();
  725. }
  726. });
  727. }
  728.  
  729.  
  730. tncLink(e) {
  731. if (this.ndaForm.get('step3').get('accept').value === true) {
  732. this.ndaForm.get('step3').get('accept').setValue('1');
  733. } else {
  734. this.ndaForm.get('step3').get('accept').setValue('0');
  735. }
  736. }
  737.  
  738. blurNda(val) {
  739. if (val === 'typeOfLegal' || val === 'businessField' || val === 'cityId' || val === 'postalCode' || val === 'companyAddress' || val === 'siteAddress') {
  740. this.ndaForm.get('step0').get('companyName').markAsTouched();
  741. }
  742. if (val === 'companyName' || val === 'businessField' || val === 'cityId' || val === 'postalCode' || val === 'companyAddress' || val === 'siteAddress') {
  743. this.ndaForm.get('step0').get('typeOfLegal').markAsTouched();
  744. }
  745. if (val === 'companyName' || val === 'typeOfLegal' || val === 'cityId' || val === 'postalCode' || val === 'companyAddress' || val === 'siteAddress') {
  746. this.ndaForm.get('step0').get('businessField').markAsTouched();
  747. }
  748. if (val === 'companyName' || val === 'typeOfLegal' || val === 'businessField' || val === 'postalCode' || val === 'companyAddress' || val === 'siteAddress') {
  749. this.ndaForm.get('step0').get('cityId').markAsTouched();
  750. }
  751. if (val === 'companyName' || val === 'typeOfLegal' || val === 'businessField' || val === 'cityId' || val === 'companyAddress' || val === 'siteAddress') {
  752. this.ndaForm.get('step0').get('postalCode').markAsTouched();
  753. }
  754. if (val === 'companyName' || val === 'typeOfLegal' || val === 'businessField' || val === 'cityId' || val === 'postalCode' || val === 'siteAddress') {
  755. this.ndaForm.get('step0').get('companyAddress').markAsTouched();
  756. }
  757. if (val === 'companyName' || val === 'typeOfLegal' || val === 'businessField' || val === 'cityId' || val === 'postalCode' || val === 'companyAddress') {
  758. this.ndaForm.get('step0').get('siteAddress').markAsTouched();
  759. }
  760.  
  761. if (this.typeNda === 'enda') {
  762. if (val === 'position' || val === 'name' || val === 'email' || val === 'phoneNumber' || val === 'privyEmail') {
  763. this.ndaForm.get('step1').get('privyId').markAsTouched();
  764. }
  765. if (val === 'position' || val === 'name' || val === 'email' || val === 'phoneNumber' || val === 'privyId') {
  766. this.ndaForm.get('step1').get('privyEmail').markAsTouched();
  767. }
  768. } else {
  769. if (val === 'position' || val === 'email' || val === 'phoneNumber') {
  770. this.ndaForm.get('step1').get('name').markAsTouched();
  771. }
  772. if (val === 'name' || val === 'email' || val === 'phoneNumber') {
  773. this.ndaForm.get('step1').get('position').markAsTouched();
  774. }
  775. if (val === 'position' || val === 'name' || val === 'phoneNumber') {
  776. this.ndaForm.get('step1').get('email').markAsTouched();
  777. }
  778. if (val === 'position' || val === 'name' || val === 'email') {
  779. this.ndaForm.get('step1').get('phoneNumber').markAsTouched();
  780. }
  781. }
  782.  
  783. if (this.typeNda === 'enda') {
  784. if (val === 'durationAgreement') {
  785. this.ndaForm.get('step2').get('numberOfParties').markAsTouched();
  786. }
  787. if (val === 'numberOfParties') {
  788. this.ndaForm.get('step2').get('durationAgreement').markAsTouched();
  789. }
  790. } else {
  791. if (val === 'durationAgreement' || val === 'scope') {
  792. this.ndaForm.get('step2').get('numberOfParties').markAsTouched();
  793. }
  794. if (val === 'numberOfParties' || val === 'scope') {
  795. this.ndaForm.get('step2').get('durationAgreement').markAsTouched();
  796. }
  797. if (val === 'numberOfParties' || val === 'durationAgreement') {
  798. this.ndaForm.get('step2').get('scope').markAsTouched();
  799. }
  800. }
  801.  
  802. if (this.typeNda === 'enda') {
  803. if (val === 'documentDeed' || val === 'documentNpwp') {
  804. this.ndaForm.get('step3').get('documentSiup').markAsTouched();
  805. }
  806. if (val === 'documentSiup' || val === 'documentNpwp') {
  807. this.ndaForm.get('step3').get('documentDeed').markAsTouched();
  808. }
  809. if (val === 'documentSiup' || val === 'documentDeed') {
  810. this.ndaForm.get('step3').get('documentNpwp').markAsTouched();
  811. }
  812. } else {
  813. if (val === 'documentDeed' || val === 'documentNpwp' || val === 'documentCredential') {
  814. this.ndaForm.get('step3').get('documentSiup').markAsTouched();
  815. }
  816. if (val === 'documentSiup' || val === 'documentNpwp' || val === 'documentCredential') {
  817. this.ndaForm.get('step3').get('documentDeed').markAsTouched();
  818. }
  819. if (val === 'documentSiup' || val === 'documentDeed' || val === 'documentCredential') {
  820. this.ndaForm.get('step3').get('documentNpwp').markAsTouched();
  821. }
  822. if (val === 'documentSiup' || val === 'documentDeed' || val === 'documentNpwp') {
  823. this.ndaForm.get('step3').get('documentCredential').markAsTouched();
  824. }
  825. }
  826. }
  827.  
  828. onSubmit() {
  829. const files = Object.assign(this.ndaForm.get('step0').value, this.ndaForm.get('step1').value, this.ndaForm.get('step2').value, this.ndaForm.get('step3').value)
  830. const dataRequest = this.toFormData(files);
  831. this.apiService.postNdaSandboxPlan(dataRequest).subscribe(
  832. data => {
  833. if (data?.success) {
  834. this.errorMsgBool = false;
  835. this.errorMsg = data.message;
  836. this.idOrder = data.data.id;
  837. if (this.typeNda === 'enda') {
  838. if (this.progress === 3) {
  839. this.saveDraft = true;
  840. setTimeout(() => {
  841. this.saveDraft = false;
  842. }, 5000);
  843. this.progress = 4;
  844. this.selectType();
  845. }
  846. } else {
  847. localStorage.setItem('invoiceId', data?.data.invoice);
  848. this.dialog.closeAll();
  849. sessionStorage.removeItem('dataDraftNda');
  850. sessionStorage.removeItem('statusDraft');
  851. this.router.navigateByUrl('/api/success', { state: { data: { status: 'nda' } } });
  852. }
  853. }
  854. },
  855. error => {
  856. this.resetRecaptcha();
  857. this.errorMsg = error.error.message;
  858. this.errorMsgBool = true;
  859. this.progress === 2;
  860. });
  861.  
  862. }
  863.  
  864. submit() {
  865. if (this.typeNda === 'enda') {
  866. this.openDialogPreview();
  867. } else {
  868. this.openDialog();
  869. }
  870. }
  871.  
  872. reSubmitContract() {
  873. 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)
  874. const dataRequest = { id: this.idOrder, data: files };
  875. this.apiService.renewalNda(dataRequest).subscribe(
  876. data => {
  877. if (data.success) {
  878. this.errorMsg = data.message;
  879. this.dialog.closeAll();
  880. if (this.progress !== 3) {
  881. sessionStorage.removeItem('dataDraftNda');
  882. sessionStorage.removeItem('statusDraft');
  883. this.router.navigateByUrl('/api/success', { state: { data: { status: 'nda' } } });
  884. } else if (this.typeNda === 'enda') {
  885. if (this.progress === 3 && this.isDraft) {
  886. this.saveDraft = true;
  887. this.progress = 4;
  888. this.selectType();
  889. setTimeout(() => {
  890. this.saveDraft = false;
  891. }, 5000);
  892. }
  893. }
  894. }
  895. },
  896. error => {
  897. this.errorMsg = error.error.message;
  898. });
  899. }
  900.  
  901. resetDoc() {
  902.  
  903. }
  904.  
  905. resolved(captchaResponse: string) {
  906. this.alredyResolve = true;
  907. this.ndaForm.get('step3').get('gResponseRecaptcha').setValue(captchaResponse);
  908. this.validateForm;
  909. }
  910.  
  911. resetRecaptcha() {
  912. /* istanbul ignore if */
  913. if (this.alredyResolve) {
  914. grecaptcha.reset();
  915. this.alredyResolve = false;
  916. this.ndaForm.get('step3').get('gResponseRecaptcha').setValue('')
  917. }
  918. }
  919.  
  920. nextForm(e) {
  921. if (e === 1) {
  922. this.progress = 2;
  923. this.selectType();
  924. this.sendProgress('activeButton2');
  925. if (this.historyData && this.autoSecond) {
  926. if (this.isDraft) {
  927. this.getDataNda();
  928. } else {
  929. this.getLatestDoc();
  930. }
  931. }
  932. } else if (e === 2) {
  933. this.progress = 3;
  934. this.selectType();
  935. if (this.typeNda === 'enda') {
  936. this.checkPrivy();
  937. this.selectType();
  938. window.scrollTo(0, 0);
  939. } else {
  940. this.progress = 3;
  941. this.selectType();
  942. window.scrollTo(0, 0);
  943. }
  944. this.sendProgress('activeButton3');
  945. if (this.historyData && this.autoThird) {
  946. if (this.isDraft) {
  947. this.getDataNda();
  948. } else {
  949. this.getLatestDoc();
  950. }
  951. }
  952. } else {
  953. if (this.typeNda=== 'enda') {
  954. this.onSubmit();
  955. // this.sendProgress('submit');
  956. this.selectType();
  957. window.scrollTo(0, 0);
  958. this.storeFrontService.changeSubject('submit');
  959. } else {
  960. this.storeFrontService.changeSubject('submit');
  961. this.progress = 4;
  962. this.selectType();
  963. window.scrollTo(0, 0);
  964. }
  965. }
  966. }
  967.  
  968. backForm(e) {
  969. if (e === 4) {
  970. this.progress = 3;
  971. this.resetRecaptcha();
  972. this.selectType();
  973. } else if (e === 3) {
  974. this.progress = 2;
  975. this.selectType();
  976. } else {
  977. this.progress = 1;
  978. this.selectType();
  979. }
  980. }
  981.  
  982. openDialogPrivy(): void {
  983. const widthDialog = this.mobileView ? '254px' : '754px';
  984. const dialogRef = this.dialog.open(ConfirmPrivyComponent, {
  985. width: widthDialog,
  986. height: '254px',
  987. disableClose: true,
  988. data: {
  989. iconTitle: 'fi icon-support yellow-icon',
  990. btnClose: 'Close',
  991. btnFalse: 'x',
  992. showFooter: false,
  993. message: 'Your Account Has Been Banned',
  994. },
  995. panelClass: 'modal-popups'
  996. });
  997. dialogRef.afterClosed().subscribe(result => {
  998. if (result === true) {
  999. this.storeFrontService.logout();
  1000. this.router.navigateByUrl('/login');
  1001. }
  1002. });
  1003. }
  1004.  
  1005. checkPrivy() {
  1006. const param = {
  1007. userId: this.ndaForm.get('step1').get('privyId').value,
  1008. email: this.ndaForm.get('step1').get('privyEmail').value
  1009. };
  1010. this.apiService.checkPrivyAccount(param)
  1011. .subscribe(res => {
  1012. if (res.status === 200) {
  1013. this.messageRes = res.message;
  1014. this.status = res.status;
  1015. this.progress = 3;
  1016. this.selectType();
  1017. window.scrollTo(0, 0);
  1018. } else if (res.status === 404) {
  1019. this.messageRes = res.message;
  1020. this.status = res.status;
  1021. this.progress = 2;
  1022. this.selectType();
  1023. window.scrollTo(0, 0);
  1024. } else if (res.status === 403) {
  1025. this.openDialogPrivy();
  1026. this.messageRes = res.message;
  1027. this.status = res.status;
  1028. this.progress = 2;
  1029. this.selectType();
  1030. window.scrollTo(0, 0);
  1031. } else {
  1032. this.messageRes = res.message;
  1033. this.status = res.status;
  1034. this.progress = 2;
  1035. this.selectType();
  1036. window.scrollTo(0, 0);
  1037. }
  1038. }, error => {
  1039. this.messageRes = error.message;
  1040. this.status = error.status;
  1041. this.progress = 2;
  1042. this.selectType();
  1043. window.scrollTo(0, 0);
  1044. })
  1045. }
  1046.  
  1047.  
  1048. sendProgress(e) {
  1049. if (e === 'activeButton1') {
  1050. this.storeFrontService.changeSubject('activeButton1');
  1051. } else if (e === 'activeButton2') {
  1052. this.storeFrontService.changeSubject('activeButton2');
  1053. } else if (e === 'activeButton3') {
  1054. this.storeFrontService.changeSubject('activeButton3');
  1055. } else if (e === 'activeButton4') {
  1056. this.storeFrontService.changeSubject('submit');
  1057. }
  1058. }
  1059.  
  1060. get validateForm() {
  1061. if (this.progress === 1) {
  1062. if (this.ndaForm.get('step0').valid) {
  1063. return this.sendProgress('activeButton1');
  1064. } else {
  1065. return this.sendProgress('false');
  1066. }
  1067. }
  1068. else if (this.progress === 2) {
  1069. if (this.ndaForm.get('step1').valid) {
  1070. return this.sendProgress('activeButton2');
  1071. } else {
  1072. return this.sendProgress('false');
  1073. }
  1074. }
  1075. else if (this.progress === 3) {
  1076. if (this.ndaForm.get('step2').valid) {
  1077. return this.sendProgress('activeButton3');
  1078. } else {
  1079. return this.sendProgress('false');
  1080. }
  1081. }
  1082. else if (this.progress === 4) {
  1083. if (this.ndaForm.get('step3').valid) {
  1084. return this.sendProgress('activeButton4');
  1085. } else {
  1086. return this.sendProgress('false');
  1087. }
  1088. }
  1089. }
  1090.  
  1091. getProgress() {
  1092. this.storeFrontService.getProgress().subscribe(res => {
  1093. if (res.text === "0") {
  1094. this.progress = 1;
  1095. this.selectType();
  1096. window.scrollTo(0, 0);
  1097. if (this.historyData && this.autoFirst) {
  1098. if (this.isDraft) {
  1099. this.getDataNda();
  1100. } else {
  1101. this.getLatestDoc();
  1102. }
  1103. }
  1104. } else if (res.text === "1") {
  1105. this.progress = 2;
  1106. this.selectType();
  1107. window.scrollTo(0, 0);
  1108. if (this.historyData && this.autoSecond) {
  1109. if (this.isDraft) {
  1110. this.getDataNda();
  1111. } else {
  1112. this.getLatestDoc();
  1113. }
  1114. }
  1115. } else if (res.text === "2") {
  1116. if (this.typeNda === 'enda') {
  1117. this.checkPrivy();
  1118. // this.progress = 3;
  1119. // this.selectType();
  1120. // window.scrollTo(0, 0);
  1121. } else {
  1122. this.progress = 3;
  1123. this.selectType();
  1124. window.scrollTo(0, 0);
  1125. }
  1126. if (this.historyData && this.autoThird) {
  1127. if (this.isDraft) {
  1128. this.getDataNda();
  1129. } else {
  1130. this.getLatestDoc();
  1131. }
  1132. }
  1133. } else if (res.text === "3") {
  1134. if (this.typeNda === 'enda') {
  1135. if (this.idOrder) {
  1136. this.reSubmitContract();
  1137. } else {
  1138. this.onSubmit();
  1139. }
  1140. } else {
  1141. this.progress = 4;
  1142. this.selectType();
  1143. window.scrollTo(0, 0);
  1144. }
  1145. } else if (res.text === "4") {
  1146. if (this.typeNda === 'enda') {
  1147. this.openDialogPreview();
  1148. } else {
  1149. this.openDialog();
  1150. }
  1151. } else if (res.text === '00') {
  1152. this.location.back();
  1153. }
  1154. })
  1155. }
  1156.  
  1157.  
  1158. openDialogPreview() {
  1159. const widthDialog = this.mobileView ? '322px' : '741px';
  1160. const dialogRef = this.dialog.open(ConfirmNoclickComponent, {
  1161. width: widthDialog,
  1162. panelClass: 'container-download-preview',
  1163. data: {
  1164. header: 'Contract Preview',
  1165. 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.',
  1166. btnTrue: 'Next',
  1167. btnFalse: 'Cancel',
  1168. download: true,
  1169. hiddenIcon: true,
  1170. hiddenIconHeader: true,
  1171. hiddenFooter: false,
  1172. hiddenHeader: false,
  1173. hiddenLink: false,
  1174. disableList: true,
  1175. hiddenBtnFalse: false,
  1176. hiddenBtnClose: false,
  1177. hiddenBtnTrue: false,
  1178. hiddenChecked: false,
  1179. hiddenBtnDownload: false,
  1180. id: this.idOrder,
  1181. type: 'enda'
  1182. }
  1183. });
  1184.  
  1185. dialogRef.afterClosed().subscribe(res => {
  1186. if (res === 'check') {
  1187. this.openDialog();
  1188. dialogRef.close(true);
  1189. } else {
  1190. dialogRef.close(true);
  1191. this.saveDraft = true;
  1192. setTimeout(() => {
  1193. this.saveDraft = false;
  1194. }, 5000);
  1195. }
  1196. })
  1197. }
  1198.  
  1199. ngOnDestroy() {
  1200. sessionStorage.removeItem('dataDraftNda');
  1201. sessionStorage.removeItem('statusDraft');
  1202. this.dialog.closeAll();
  1203. }
  1204.  
  1205. }
  1206.  
  1207.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement