HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/src/app/pages/address-list/address-list.ts
import { Component, OnInit } from "@angular/core";
import { TranslateService } from "@ngx-translate/core";
import { LoadingController, AlertController } from "@ionic/angular";
import { NavigationStart, Router } from "@angular/router";
import { AddressService } from "../../services/address.service";
import { UserService } from "../../services/user.service";
import { UtilsService } from "../../services/utils.service";
import { StorageService } from '../../services/storage.service';

@Component({
  selector: "page-address-list",
  templateUrl: "address-list.html",
  styleUrls: ["./address-list.scss"],
})
export class AddressListPage implements OnInit {
  toastMessageText: any;
  constructor(
    private storage: StorageService,
    private translateService: TranslateService,
    public loadingCtrl: LoadingController,
    public alertCtrl: AlertController,
    public addressProvider: AddressService,
    public userProvider: UserService,
    public utilsService: UtilsService,
    private router: Router
  ) {
    this.translateService.get(["TITLE_ALERT_DELETE_ADDRESS", "TEXT_ALERT_DELETE_ADDRESS"]).subscribe((values) => {
      this.toastMessageText = {
        titleDelete: values.TITLE_ALERT_DELETE_ADDRESS,
        textDelete: values.TEXT_ALERT_DELETE_ADDRESS,
      };
    });

    router.events.subscribe((event: NavigationStart) => {
      if (event.navigationTrigger === 'popstate' && event.url.includes('address-list')) {
        setTimeout(() => {
          this.updateInfoUser();
        }, 100);
      }
    });
  }

  ngOnInit() {
  }

  ionViewDidEnter() {
    this.updateInfoUser();
  }

  addNewAddress() {
    this.router.navigate(["/address/addressListCreate/true"]);
  }

  async deleteAddress(address_id) {
    const confirm = await this.alertCtrl.create({
      header: this.toastMessageText.titleDelete,
      message: this.toastMessageText.textDelete,
      buttons: [
        {
          text: "No",
          handler: () => {
            console.log("Disagree clicked");
          },
        },
        {
          text: "Si",
          handler: () => {
            this.storage.get("token").then(async (token) => {
              if (token) {
                this.utilsService.presentLoading(this.translateService.instant("all.loading"));
                (await this.addressProvider.deleteAddress(address_id, token.access_token)).subscribe(
                  (resp) => {
                    if (resp["status"] == "success") {
                      this.storage.get("infoUser").then((res) => {
                        let dataUser = res;
                        dataUser.addresses = resp["addresses"];
                        // se actualiza la informacion del usuario en el localstorage
                        this.storage.set("infoUser", dataUser);
                        this.updateInfoUser();
                        this.utilsService.dismissLoading();
                      });
                    }
                  },
                  (error) => {
                    console.log("error generateOrder", error);
                    this.utilsService.dismissLoading();
                  }
                );
              }
            });
          },
        },
      ],
    });
    confirm.present();
  }

  updateInfoUser() {
    setTimeout(() => {
      this.userProvider.getInfoUser();
    }, 500);
  }

  async changeAddressUser(id) {
    await this.userProvider.updateLastUsedAddress(id);
    this.updateInfoUser();
  }
}