feedback.page.ts 2.03 KB
Newer Older
gap95's avatar
gap95 committed
1
import { Component, OnInit } from '@angular/core';
2
import { Observable } from 'rxjs';
gap95's avatar
gap95 committed
3
import { HttpClient, HttpHeaders } from '@angular/common/http';
4
import { RestService } from 'src/app/rest.service';
gap95's avatar
gap95 committed
5
import { Storage } from '@ionic/storage';
6
7
8
9
import { Router } from '@angular/router';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { ToastService } from '../services/toast.service';
import { FeedbackService } from '../services/feedback.service';
gap95's avatar
gap95 committed
10
11
12
13
14
15
16

@Component({
  selector: 'app-feedback',
  templateUrl: './feedback.page.html',
  styleUrls: ['./feedback.page.scss'],
})
export class FeedbackPage implements OnInit {
17
18
19
20
  public angForm: FormGroup;
  
 
  
gap95's avatar
gap95 committed
21
22
  feedbackApi:  Observable<any>;
  content: "";
23
  bikeId="";
24
25
26
27
28
  public isDetailsVisible = false;
 
  
  
 
gap95's avatar
gap95 committed
29

30
31
  constructor(private router: Router, 
    public httpClient: HttpClient, 
gap95's avatar
gap95 committed
32
    public restService: RestService,
33
34
    private toastService: ToastService,
    private fb: FormBuilder,
gap95's avatar
gap95 committed
35
    private storage: Storage,
36
37
38
39
    public feedbackService: FeedbackService) {
      this.createForm();

     }
gap95's avatar
gap95 committed
40
41

  ngOnInit() {
42
43
44
45
46
47
48
49
50
51
52
53
  }
  createForm() {
    this.angForm = this.fb.group({
       
       
       feedback: ['', [Validators.required ]],
      
       
 
   
    });
    
gap95's avatar
gap95 committed
54
  }
gap95's avatar
gap95 committed
55
  submitFeedback() {
56
57
58
59
60
    if (this.angForm.invalid) {
      return;
  }
  let Form = JSON.stringify(this.angForm.value);
  
gap95's avatar
gap95 committed
61
62
    this.storage.get('token').then((token) => {
      let url = 'http://193.196.52.237:8081/feedbacks'
63
      let Form = JSON.stringify(this.angForm.value);
gap95's avatar
gap95 committed
64
      const headers = new HttpHeaders().set("Authorization", "Bearer " + token);
65
      this.feedbackApi = this.httpClient.post<any>(url, {"content": Form,"bikeId":this.feedbackService.getBikeid()},{headers});
gap95's avatar
gap95 committed
66
67
      this.feedbackApi.subscribe((resp) => {
        console.log("rides response", resp);
68
69
        this.isDetailsVisible = false;
        this.router.navigateByUrl('/ridehistory');
gap95's avatar
gap95 committed
70
71
72
73
74
        //this.loadingService.hideLoader();
      }, (error) => {console.log(error)
        //this.loadingService.hideLoader();
      });
    });
gap95's avatar
gap95 committed
75
}
76
77
  }