From 9e34c0601c8f96afdc841cb89526c598445ea0a4 Mon Sep 17 00:00:00 2001
From: gap95 <gauri.a.pande@gmail.com>
Date: Mon, 13 Jan 2020 19:13:55 +0100
Subject: [PATCH] feedback validations added and change in login url back to
 authenticate

---
 src/app/auth/login/login.page.ts    |  2 +-
 src/app/feedback/feedback.module.ts |  3 +-
 src/app/feedback/feedback.page.html | 37 ++++++++----------
 src/app/feedback/feedback.page.ts   | 59 ++++++++++++++++++++++-------
 src/app/home/home.page.html         |  4 +-
 5 files changed, 67 insertions(+), 38 deletions(-)

diff --git a/src/app/auth/login/login.page.ts b/src/app/auth/login/login.page.ts
index 6a48bb3..1f73808 100644
--- a/src/app/auth/login/login.page.ts
+++ b/src/app/auth/login/login.page.ts
@@ -38,7 +38,7 @@ export class LoginPage implements OnInit {
   }
 
   loginApiCall() {
-    this.loginApi = this.httpClient.post('http://193.196.52.237:8081/login', {
+    this.loginApi = this.httpClient.post('http://193.196.52.237:8081/authenticate', {
       "email": this.username,
       "password": this.password
     });
diff --git a/src/app/feedback/feedback.module.ts b/src/app/feedback/feedback.module.ts
index a9a436a..e31e3e5 100644
--- a/src/app/feedback/feedback.module.ts
+++ b/src/app/feedback/feedback.module.ts
@@ -1,6 +1,6 @@
 import { NgModule } from '@angular/core';
 import { CommonModule } from '@angular/common';
-import { FormsModule } from '@angular/forms';
+import { FormsModule, ReactiveFormsModule } from '@angular/forms';
 
 import { IonicModule } from '@ionic/angular';
 
@@ -13,6 +13,7 @@ import { FeedbackPage } from './feedback.page';
     CommonModule,
     FormsModule,
     IonicModule,
+    ReactiveFormsModule,
     FeedbackPageRoutingModule
   ],
   declarations: [FeedbackPage]
diff --git a/src/app/feedback/feedback.page.html b/src/app/feedback/feedback.page.html
index 206a8fc..82583d4 100644
--- a/src/app/feedback/feedback.page.html
+++ b/src/app/feedback/feedback.page.html
@@ -6,13 +6,12 @@
     <ion-title slot="start">
       Feedback
     </ion-title>
-  
   </ion-toolbar>
 </ion-header>
 
 <ion-content>
         
-          <!--form [formGroup]="angForm" novalidate--><div>
+          <form [formGroup]="angForm" novalidate>
               <ion-grid>
                   <ion-row justify-content-center>
                     <ion-col align-self-center size-md="6" size-lg="5" size-xs="12">
@@ -23,27 +22,23 @@
                     <h3>Feedback</h3>
                    
                   </div>
-                  <div >
+                  
                   <ion-item >
-                  <ion-textarea class="ion-text-content" [(ngModel)]="content" placeholder="Enter Feedback"></ion-textarea>
-                  </ion-item>
+                    
+                    <ion-textarea class="ion-text-content" formControlName="feedback" placeholder="Enter Feedback"></ion-textarea>
+                </ion-item>
+              <div
+                *ngIf="angForm.controls['feedback'].invalid && (angForm.controls['feedback'].dirty || angForm.controls['feedback'].touched)"
+                class="alert-danger"><ion-icon name="alert"></ion-icon>
+                <div *ngIf="angForm.controls['feedback'].errors.required">
+                  Feedback is required.
                 </div>
-             
-               
-            
-              
-
-             
-              
-          
-          
-
-          <div padding>
-            <ion-button  size="large" expand="block" (click)="submitFeedback()">Submit Feedback</ion-button>
-          </div>
+              </div>
+              <div padding>
+                <ion-button  size="large" expand="block" (click)="submitFeedback()">Submit Feedback</ion-button>
+              </div>
         </ion-col>
       </ion-row>
     </ion-grid>
-  </div>
-  <!--/form-->
-</ion-content>
+  </form>
+</ion-content>
\ No newline at end of file
diff --git a/src/app/feedback/feedback.page.ts b/src/app/feedback/feedback.page.ts
index 9fbe393..e1793e3 100644
--- a/src/app/feedback/feedback.page.ts
+++ b/src/app/feedback/feedback.page.ts
@@ -1,11 +1,12 @@
 import { Component, OnInit } from '@angular/core';
-import { Router } from '@angular/router';
+import { Observable } from 'rxjs';
 import { HttpClient, HttpHeaders } from '@angular/common/http';
-import { RestService } from '../rest.service';
-import { UserService } from '../services/user.service';
+import { RestService } from 'src/app/rest.service';
 import { Storage } from '@ionic/storage';
-import { Observable } from 'rxjs';
-import { FeedbackService } from 'src/app/services/feedback.service';
+import { Router } from '@angular/router';
+import { FormGroup, FormBuilder, Validators } from '@angular/forms';
+import { ToastService } from '../services/toast.service';
+import { FeedbackService } from '../services/feedback.service';
 
 @Component({
   selector: 'app-feedback',
@@ -13,32 +14,64 @@ import { FeedbackService } from 'src/app/services/feedback.service';
   styleUrls: ['./feedback.page.scss'],
 })
 export class FeedbackPage implements OnInit {
+  public angForm: FormGroup;
+  
+ 
+  
   feedbackApi:  Observable<any>;
   content: "";
   bikeId="";
+  public isDetailsVisible = false;
+ 
+  
+  
+ 
 
-  constructor(private router: Router,
-    public httpClient: HttpClient,
+  constructor(private router: Router, 
+    public httpClient: HttpClient, 
     public restService: RestService,
-    public userService: UserService,
+    private toastService: ToastService,
+    private fb: FormBuilder,
     private storage: Storage,
-    public feedbackService: FeedbackService) { }
+    public feedbackService: FeedbackService) {
+      this.createForm();
+
+     }
 
   ngOnInit() {
+  }
+  createForm() {
+    this.angForm = this.fb.group({
+       
+       
+       feedback: ['', [Validators.required ]],
+      
+       
+ 
+   
+    });
+    
   }
   submitFeedback() {
+    if (this.angForm.invalid) {
+      return;
+  }
+  let Form = JSON.stringify(this.angForm.value);
+  
     this.storage.get('token').then((token) => {
       let url = 'http://193.196.52.237:8081/feedbacks'
-      
+      let Form = JSON.stringify(this.angForm.value);
       const headers = new HttpHeaders().set("Authorization", "Bearer " + token);
-      this.feedbackApi = this.httpClient.post<any>(url, {"content": this.content,"bikeId":this.feedbackService.getBikeid()},{headers});
+      this.feedbackApi = this.httpClient.post<any>(url, {"content": Form,"bikeId":this.feedbackService.getBikeid()},{headers});
       this.feedbackApi.subscribe((resp) => {
         console.log("rides response", resp);
-        
+        this.isDetailsVisible = false;
+        this.router.navigateByUrl('/ridehistory');
         //this.loadingService.hideLoader();
       }, (error) => {console.log(error)
         //this.loadingService.hideLoader();
       });
     });
 }
-}
\ No newline at end of file
+  }
+
diff --git a/src/app/home/home.page.html b/src/app/home/home.page.html
index 2c25d36..91f7f46 100644
--- a/src/app/home/home.page.html
+++ b/src/app/home/home.page.html
@@ -112,9 +112,9 @@
             <ion-col>
               <ion-button size="medium" expand="block" (click)="reserveBike()">Reserve</ion-button>
             </ion-col>
-            <ion-col>
+           <!--<ion-col>
               <ion-button size="medium" expand="block" (click)="navigatetoBike()">Navigate</ion-button>
-            </ion-col>
+            </ion-col>--> 
           </ion-row>
         </ion-grid>
       </div>
-- 
GitLab