File

src/app/feedback/feedback.page.ts

Implements

OnInit

Metadata

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

Index

Properties
Methods

Constructor

constructor(_formBuilder: FormBuilder, afs: AngularFirestore, loadingCtrl: LoadingController, swal: SwalService)
Parameters :
Name Type Optional
_formBuilder FormBuilder No
afs AngularFirestore No
loadingCtrl LoadingController No
swal SwalService No

Methods

ngOnInit
ngOnInit()
Returns : void

Properties

firstFormGroup
Type : FormGroup
options
Type : []
Default value : ['new feature', 'error/bug', 'improvement']
secondFormGroup
Type : FormGroup
submitFeedback
Default value : () => {...}
import { SwalService } from './../services/swal/swal.service';
import { Feedback } from './../models/feedback';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { Component, OnInit } from '@angular/core';
import { AngularFirestore } from '@angular/fire/firestore';
import { LoadingController } from '@ionic/angular';

@Component({
  selector: 'app-feedback',
  templateUrl: './feedback.page.html',
  styleUrls: ['./feedback.page.scss']
})
export class FeedbackPage implements OnInit {
  firstFormGroup: FormGroup;
  secondFormGroup: FormGroup;
  options = ['new feature', 'error/bug', 'improvement'];
  constructor(
    private _formBuilder: FormBuilder,
    private afs: AngularFirestore,
    private loadingCtrl: LoadingController,
    private swal: SwalService
  ) {}

  ngOnInit() {
    this.firstFormGroup = this._formBuilder.group({
      firstCtrl: ['', Validators.required]
    });
    this.secondFormGroup = this._formBuilder.group({
      firstCtrl: ['', Validators.required]
    });
  }

  submitFeedback = async () => {
    const loading = await this.loadingCtrl.create({
      message: 'Sending your feedback',
      spinner: 'crescent'
    });
    loading.present();
    const feedback: Feedback = {
      creationDate: new Date(),
      type: this.firstFormGroup.controls['firstCtrl'].value,
      message: this.secondFormGroup.controls['firstCtrl'].value
    };
    this.afs
      .collection('Feedback')
      .add({ ...feedback })
      .then(() => {
        this.swal.viewSuccessMessage('Successful', 'Feedback submitted!');
      })
      .catch(error => {
        console.error('Error occured when sending the feedback', error);
        this.swal.viewErrorMessage('Error', 'Error occurred while sending feedback!');
      })
      .finally(() => {
        loading.dismiss();
      });
  };
}
<app-menu-title title="Feedback"></app-menu-title>

<ion-content class="ion-padding">
  <ion-text>
    We are highly appreciating feedback about the application. You can send us feature request, bug
    report or anything related to the application
  </ion-text>
  <mat-vertical-stepper linear #stepper>
    <mat-step [stepControl]="firstFormGroup">
      <form [formGroup]="firstFormGroup">
        <ng-template matStepLabel>Select what kind of feedback you are providing</ng-template>
        <mat-form-field>
          <mat-label>Type of feedback</mat-label>
          <mat-error *ngIf="firstFormGroup.controls['firstCtrl']">
            Select type of feedback
          </mat-error>
          <mat-select formControlName="firstCtrl">
            <mat-option *ngFor="let option of options" [value]="option">
              {{ option }}
            </mat-option>
          </mat-select>
        </mat-form-field>
        <div>
          <button mat-raised-button matStepperNext color="primary">Next</button>
        </div>
      </form>
    </mat-step>
    <mat-step [stepControl]="secondFormGroup">
      <form [formGroup]="secondFormGroup">
        <ng-template matStepLabel>Give us details</ng-template>
        <mat-form-field style="width:100%">
          <mat-error *ngIf="secondFormGroup.controls['firstCtrl']">
            Please elaborate more about the feedback
          </mat-error>
          <textarea matInput placeholder="Details" formControlName="firstCtrl" required></textarea>
        </mat-form-field>
        <div>
          <button mat-raised-button matStepperPrevious color="warn" style="margin-right: 2rem;">
            Back
          </button>
          <button mat-raised-button matStepperNext color="primary">Next</button>
        </div>
      </form>
    </mat-step>
    <mat-step>
      <ng-template matStepLabel>Submit</ng-template>
      Submit your feedback
      <div style="padding: 5px;">
        <button mat-raised-button matStepperPrevious color="primary">
          Back
        </button>
        <button mat-raised-button matStepperPrevious color="accent" (click)="submitFeedback()">
          Submit
        </button>
        <button mat-raised-button (click)="stepper.reset()" color="warn">Reset</button>
      </div>
    </mat-step>
  </mat-vertical-stepper>
</ion-content>

./feedback.page.scss

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""