Created
July 26, 2018 10:34
-
-
Save Sampath-Lokuge/f0323028fc2b6944eaf1e77608ba4fb3 to your computer and use it in GitHub Desktop.
contact.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from "@angular/core"; | |
import { FormBuilder, FormGroup, Validators } from "@angular/forms"; | |
import Mixpanel from "../../mixpanel.functions"; | |
import { RegexValidators } from "../constants/validator"; | |
import { UserSessionService } from "../services/security/user-session.service"; | |
import { SiteNotificationService } from "../services/common/sitenotification.service"; | |
import { HttpCommonService } from "../services/common/httpcommon.service"; | |
import { JwtHelperService } from '@auth0/angular-jwt'; | |
@Component({ | |
selector: "contact", | |
templateUrl: "./contact.component.html" | |
}) | |
export class ContactComponent implements OnInit { | |
form: FormGroup; | |
loggedIn: boolean = false; | |
jwtHelper: JwtHelperService = new JwtHelperService(); | |
constructor(private fb: FormBuilder, | |
private notification: SiteNotificationService, | |
private httpCommonService: HttpCommonService, | |
private session: UserSessionService | |
) { } | |
ngOnInit() { | |
this.init(); | |
} | |
//init | |
init() { | |
Mixpanel.trackEvent("View Screen", { | |
"Screen Name": "ContactUs" | |
}); | |
this.createForm(); | |
if (this.session.get("Session")) { | |
this.loggedIn = true; | |
var token = this.jwtHelper.decodeToken(this.session.get("Session").token); | |
this.form.controls["fname"].setValue(token.name.split(" ")[0]); | |
this.form.controls["lname"].setValue(token.name.split(" ")[1]); | |
this.form.controls["email"].setValue(token.email); | |
} | |
} | |
//create Form | |
createForm() { | |
this.form = this.fb.group({ | |
fname: ["", Validators.required], | |
lname: ["", Validators.required], | |
email: ["", Validators.compose([Validators.required, Validators.pattern(RegexValidators.email)])], | |
message: ["", Validators.required] | |
}); | |
} | |
//send | |
send() { | |
this.httpCommonService.post("contactus", this.form.value).subscribe(response => { | |
this.notification.showSuccess("Thank you for your message, we will get back to you soon!"); | |
this.ngOnInit(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment