ng-easycommerce 0.0.625 → 0.0.626

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11278,7 +11278,7 @@ var __decorate$1n = (this && this.__decorate) || function (decorators, target, k
11278
11278
  return c > 3 && r && Object.defineProperty(target, key, r), r;
11279
11279
  };
11280
11280
  let RegisterFormEcComponent = class RegisterFormEcComponent extends ComponentHelper {
11281
- constructor(authService, toastr, router, analyticsService, formBuilder, channelConfigService) {
11281
+ constructor(authService, toastr, router, analyticsService, formBuilder, channelConfigService, consts) {
11282
11282
  super();
11283
11283
  this.authService = authService;
11284
11284
  this.toastr = toastr;
@@ -11286,6 +11286,13 @@ let RegisterFormEcComponent = class RegisterFormEcComponent extends ComponentHel
11286
11286
  this.analyticsService = analyticsService;
11287
11287
  this.formBuilder = formBuilder;
11288
11288
  this.channelConfigService = channelConfigService;
11289
+ this.consts = consts;
11290
+ this.provincesSubject = new BehaviorSubject([]);
11291
+ this.countriesSubject = new BehaviorSubject([]);
11292
+ this.documentTypesSubject = new BehaviorSubject([]);
11293
+ this.provinces$ = this.provincesSubject.asObservable();
11294
+ this.countries$ = this.countriesSubject.asObservable();
11295
+ this.documentTypes$ = this.documentTypesSubject.asObservable();
11289
11296
  this.isLogged = true;
11290
11297
  this.darkMode = false;
11291
11298
  this.redirect = true;
@@ -11327,7 +11334,8 @@ let RegisterFormEcComponent = class RegisterFormEcComponent extends ComponentHel
11327
11334
  return;
11328
11335
  }
11329
11336
  if (this.registerForm.valid) {
11330
- this.authService.signUp(this.registerForm.value).toPromise().then(res => {
11337
+ const normalizedData = this.normalizeRegisterData(this.registerForm.value);
11338
+ this.authService.signUp(normalizedData).toPromise().then(res => {
11331
11339
  this.register_loading = false;
11332
11340
  let messageKey;
11333
11341
  switch (true) {
@@ -11369,6 +11377,18 @@ let RegisterFormEcComponent = class RegisterFormEcComponent extends ComponentHel
11369
11377
  this.register_loading = false;
11370
11378
  }
11371
11379
  };
11380
+ this.onCountrySelected = (value) => {
11381
+ $('#selectOpPais').attr('disabled', true);
11382
+ this.registerForm.controls['countryCode'].setValue(value);
11383
+ this.registerForm.controls['provinceCode'].setValue('');
11384
+ value != '' && this.provincesSubject.next(this.countriesSubject.value.find(country => country.code == value).provinces);
11385
+ };
11386
+ this.onGenderSelected = (value) => {
11387
+ $('#selectOpSexo').attr('disabled', true);
11388
+ };
11389
+ this.onProvincesSelected = (value) => {
11390
+ $('#selectOpProvincia').attr('disabled', true);
11391
+ };
11372
11392
  this.ecOnConstruct();
11373
11393
  }
11374
11394
  ngOnInit() {
@@ -11380,7 +11400,40 @@ let RegisterFormEcComponent = class RegisterFormEcComponent extends ComponentHel
11380
11400
  plainPassword2: ['', Validators.required],
11381
11401
  newsletter: [false],
11382
11402
  terms: ['', Validators.required],
11383
- birthday: [''],
11403
+ birthday: [null, [this.optionalMaxLengthValidator(11)]],
11404
+ // Dirección (opcional, pero si se envía, se recomienda enviar todos los campos internos)
11405
+ countryCode: [''],
11406
+ provinceCode: [null],
11407
+ street: [null],
11408
+ city: [''],
11409
+ postcode: [''],
11410
+ // Datos empresa (opcionales)
11411
+ companyName: [''],
11412
+ legalDenomination: [''],
11413
+ // Datos personales adicionales (opcionales)
11414
+ gender: [null],
11415
+ phoneNumber: ['', [Validators.pattern('[0-9]+')]],
11416
+ subscribedToNewsletter: [false],
11417
+ documentType: [null],
11418
+ documentNumber: [''],
11419
+ // Comentarios y contacto (opcionales)
11420
+ comments: ['', []],
11421
+ contactFirstName: ['', []],
11422
+ contactLastName: ['', []],
11423
+ contactCompanyPosition: ['', []],
11424
+ contactEmail: ['', []],
11425
+ contactDocumentType: ['', []],
11426
+ contactDocumentNumber: ['', []],
11427
+ }, {
11428
+ validators: [this.direccionCompletaValidator()]
11429
+ });
11430
+ this.authService.getCountriesData().then(res => {
11431
+ this.countriesSubject.next(res);
11432
+ let documentTypes = [];
11433
+ res.map(paises => {
11434
+ this.consts.getLocale().toLocaleLowerCase().includes(paises.code.toLocaleLowerCase()) && (documentTypes = paises.documentTypes || []);
11435
+ });
11436
+ this.documentTypesSubject.next(documentTypes);
11384
11437
  });
11385
11438
  this.channelConfigService.channelConfig$.subscribe((config) => {
11386
11439
  if (config && config.isAccountVerificationRequired !== undefined) {
@@ -11398,8 +11451,38 @@ let RegisterFormEcComponent = class RegisterFormEcComponent extends ComponentHel
11398
11451
  });
11399
11452
  this.ecOnInit();
11400
11453
  }
11401
- prueba() {
11402
- this.toastr.showPersistent('hola');
11454
+ direccionCompletaValidator() {
11455
+ return (control) => {
11456
+ var _a, _b, _c, _d, _e;
11457
+ const street = (_a = control.get('street')) === null || _a === void 0 ? void 0 : _a.value;
11458
+ const city = (_b = control.get('city')) === null || _b === void 0 ? void 0 : _b.value;
11459
+ const provinceCode = (_c = control.get('provinceCode')) === null || _c === void 0 ? void 0 : _c.value;
11460
+ const countryCode = (_d = control.get('countryCode')) === null || _d === void 0 ? void 0 : _d.value;
11461
+ const postcode = (_e = control.get('postcode')) === null || _e === void 0 ? void 0 : _e.value;
11462
+ const hasValue = (val) => val !== null && val !== undefined && val.toString().trim() !== '';
11463
+ const anyFieldSet = [street, city, provinceCode, countryCode, postcode].some(hasValue);
11464
+ const allFieldsSet = [street, city, provinceCode, countryCode, postcode].every(hasValue);
11465
+ // Si al menos un campo de dirección está establecido, todos deben estarlo
11466
+ // Si no hay ningún campo de dirección establecido, no se aplica la validación
11467
+ if (anyFieldSet && !allFieldsSet) {
11468
+ return { direccionIncompleta: true };
11469
+ }
11470
+ return null;
11471
+ };
11472
+ }
11473
+ optionalMaxLengthValidator(max) {
11474
+ return (control) => {
11475
+ if (!control.value)
11476
+ return null;
11477
+ return control.value.length > max ? { maxLength: true } : null;
11478
+ };
11479
+ }
11480
+ normalizeRegisterData(data) {
11481
+ const normalizeString = (val) => val === undefined || val === null || val.toString().trim() === '' ? null : val.toString().trim();
11482
+ const normalizeBool = (val) => typeof val === 'boolean' ? val : val === 'true' ? true : val === 'false' ? false : null;
11483
+ return Object.assign(Object.assign({}, data), { birthday: normalizeString(data.birthday) || '', companyName: normalizeString(data.companyName), legalDenomination: normalizeString(data.legalDenomination), gender: normalizeString(data.gender), phoneNumber: normalizeString(data.phoneNumber), subscribedToNewsletter: normalizeBool(data.subscribedToNewsletter), documentType: normalizeString(data.documentType), documentNumber: normalizeString(data.documentNumber), comments: normalizeString(data.comments), contactFirstName: normalizeString(data.contactFirstName), contactLastName: normalizeString(data.contactLastName), contactCompanyPosition: normalizeString(data.contactCompanyPosition), contactEmail: normalizeString(data.contactEmail), contactDocumentType: normalizeString(data.contactDocumentType), contactDocumentNumber: normalizeString(data.contactDocumentNumber),
11484
+ // Dirección
11485
+ countryCode: normalizeString(data.countryCode), provinceCode: normalizeString(data.provinceCode), street: normalizeString(data.street), city: normalizeString(data.city), postcode: normalizeString(data.postcode) });
11403
11486
  }
11404
11487
  };
11405
11488
  RegisterFormEcComponent.ctorParameters = () => [
@@ -11408,7 +11491,8 @@ RegisterFormEcComponent.ctorParameters = () => [
11408
11491
  { type: Router },
11409
11492
  { type: AnalyticsService },
11410
11493
  { type: FormBuilder },
11411
- { type: ChannelConfigService }
11494
+ { type: ChannelConfigService },
11495
+ { type: Constants }
11412
11496
  ];
11413
11497
  __decorate$1n([
11414
11498
  Input()