File

src/app/signup/signup.page.ts

Implements

OnInit

Metadata

selector app-signup
styleUrls ./signup.page.scss
templateUrl ./signup.page.html

Index

Properties
Methods

Constructor

constructor(fb: FormBuilder, loadingCtrl: LoadingController, fcm: FcmService, swal: SwalService, user: UserService, customValidation: CustomValidatorService, logger: EventLoggerService)
Parameters :
Name Type Optional
fb FormBuilder No
loadingCtrl LoadingController No
fcm FcmService No
swal SwalService No
user UserService No
customValidation CustomValidatorService No
logger EventLoggerService No

Methods

checkFormControlIsValid
checkFormControlIsValid(control: string)
Parameters :
Name Type Optional
control string No
Returns : any
ngOnInit
ngOnInit()
Returns : void
onSubmit
onSubmit()
Returns : void

Properties

getErrorMessage
Default value : () => {...}
hideLoading
Default value : () => {...}
loading
presentLoading
Default value : () => {...}
signupForm
Type : FormGroup
import { UserService } from './../services/user/user.service';
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { LoadingController } from '@ionic/angular';
import { FcmService } from '../fcm.service';
import { SwalService } from '../services/swal/swal.service';
import { CustomValidatorService } from '../services/custom-validator/custom-validator.service';
import { EventLoggerService } from '../services/logger/event-logger.service';
@Component({
  selector: 'app-signup',
  templateUrl: './signup.page.html',
  styleUrls: ['./signup.page.scss']
})
export class SignupPage implements OnInit {
  signupForm: FormGroup;
  loading;
  constructor(
    private fb: FormBuilder,
    private loadingCtrl: LoadingController,
    private fcm: FcmService,
    private swal: SwalService,
    private user: UserService,
    private customValidation: CustomValidatorService,
    private logger: EventLoggerService
  ) {
    this.signupForm = this.fb.group({
      displayName: ['', Validators.required],
      email: ['', [Validators.required, Validators.email]],
      libraryId: new FormControl(null, {
        validators: [Validators.required],
        asyncValidators: this.customValidation.libraryIdValidator,
        updateOn: 'blur'
      }),
      password: ['', Validators.required],
      confirmPassword: ['', Validators.required],
      telephoneNumber: ['', Validators.required]
    });
  }

  ngOnInit() {}

  getErrorMessage = (controller: string) => {
    const formController = this.signupForm.controls[controller];
    return formController.hasError('required')
      ? 'You must enter a value'
      : formController.hasError('email')
      ? 'Not a valid email'
      : '';
  };

  checkFormControlIsValid(control: string) {
    return this.signupForm.controls[control].invalid;
  }

  onSubmit() {
    const userEmail = this.signupForm.controls['email'].value;
    const userPassword = this.signupForm.controls['password'].value;
    const displayName: string = this.signupForm.controls['displayName'].value;
    const phoneNumber: string = this.signupForm.controls['telephoneNumber'].value;
    const libraryId: string = this.signupForm.controls['libraryId'].value;

    console.log('userEmail :', typeof userEmail);
    console.log('userPassword :', typeof userPassword);
    this.presentLoading();
    try {
      this.user
        .createUser(userEmail, userPassword)
        .then(() => {
          this.hideLoading();
          return this.user.updateUserDetails(displayName, phoneNumber, libraryId);
        })
        .then(() => {
          console.log('Successfully updated the additional user information');
          return this.user.sendConfirmationEmail();
        })
        .then(() => {
          this.swal.viewSuccessMessage(
            'Welcome!',
            'Registration Successful, please confirm your email address!'
          );
          return this.fcm.getPermission();
        })
        .then(() => this.fcm.sub('notices'))
        .then(() => this.logger.registerAttempt())
        .catch(error => {
          this.hideLoading();
          console.log('error :', error.message);
          this.swal.viewErrorMessage('Error!', error.message);
        });
    } catch (error) {
      this.hideLoading();
      console.log('error :', error);
    }
  }

  presentLoading = async () => {
    this.loading = await this.loadingCtrl.create({
      spinner: 'crescent',
      message: 'Processing your request'
    });
    await this.loading.present();
  };

  hideLoading = () => {
    this.loading.dismiss();
  };
}
<ion-header>
  <ion-toolbar color="primary">
    <ion-buttons slot="start">
      <ion-button id="back-button" routerLink="../"
        ><ion-icon name="arrow-back"></ion-icon
      ></ion-button>
    </ion-buttons>
    <ion-title>Signup</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content class="ion-padding">
  <form [formGroup]="signupForm">
    <mat-form-field style="display: block" appearance="outline">
      <mat-label>Enter your University email</mat-label>
      <input matInput placeholder="Email" formControlName="email" />
      <mat-error *ngIf="checkFormControlIsValid('email')">{{ getErrorMessage('email') }}</mat-error>
    </mat-form-field>
    <mat-form-field style="display: block" appearance="outline">
      <mat-label>Enter your Library ID</mat-label>
      <input matInput placeholder="Library ID" formControlName="libraryId" on />
      <mat-error *ngIf="checkFormControlIsValid('libraryId')">{{
        getErrorMessage('libraryId')
      }}</mat-error>
    </mat-form-field>
    <mat-form-field style="display: block" appearance="outline">
      <input matInput placeholder="password" formControlName="password" />
      <mat-error *ngIf="checkFormControlIsValid('password')">{{
        getErrorMessage('password')
      }}</mat-error>
    </mat-form-field>
    <mat-form-field style="display: block" appearance="outline">
      <input matInput placeholder="Confirm Password" formControlName="confirmPassword" />
      <mat-error *ngIf="checkFormControlIsValid('confirmPassword')">{{
        getErrorMessage('confirmPassword')
      }}</mat-error>
    </mat-form-field>
    <mat-form-field style="display: block" appearance="outline">
      <input matInput placeholder="Name with initials" formControlName="displayName" />
      <mat-error *ngIf="checkFormControlIsValid('displayName')">{{
        getErrorMessage('displayName')
      }}</mat-error>
    </mat-form-field>
    <mat-form-field style="display: block" appearance="outline">
      <input matInput placeholder="Contact Number" formControlName="telephoneNumber" />
      <mat-error *ngIf="checkFormControlIsValid('telephoneNumber')">{{
        getErrorMessage('telephoneNumber')
      }}</mat-error>
    </mat-form-field>
    <ion-button type="submit" color="danger" [disabled]="signupForm.invalid" (click)="onSubmit()"
      >Register</ion-button
    >
  </form>
</ion-content>

./signup.page.scss

#back-button {
  border: 1px solid white;
  border-radius: 5px;
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""