From de8b0f8cf1a436c404213b1da15e765fc4205b4a Mon Sep 17 00:00:00 2001 From: lele9h0st Date: Tue, 23 Aug 2022 03:04:42 +0700 Subject: [PATCH] #4 - add contact --- db.json | 9 +++ src/app/_api/apiURL.ts | 3 +- .../register-form/register-form.component.ts | 7 ++- src/app/pages/contact/contact.component.html | 57 +++++++++---------- src/app/pages/contact/contact.component.ts | 30 +++++++++- 5 files changed, 71 insertions(+), 35 deletions(-) diff --git a/db.json b/db.json index 56b2ec1..3e0e318 100644 --- a/db.json +++ b/db.json @@ -203,5 +203,14 @@ ], "id": 2 } + ], + "contact": [ + { + "email": "hoang@gmail.com", + "name": "hoang", + "title": "hoang", + "text": "abcaaaaa", + "id": 1 + } ] } \ No newline at end of file diff --git a/src/app/_api/apiURL.ts b/src/app/_api/apiURL.ts index 15e9daf..4214d3b 100644 --- a/src/app/_api/apiURL.ts +++ b/src/app/_api/apiURL.ts @@ -29,5 +29,6 @@ export const API_URL = { GET_LIST: "https://api-news-vietnamnet.herokuapp.com/api/get/", SEARCH: "https://api-news-vietnamnet.herokuapp.com/api/search/", ARTICLE_DETAILS: "https://api-news-vietnamnet.herokuapp.com/article/", - ARTICLE_SAVED: "http://localhost:3000/saved-post" + ARTICLE_SAVED: "http://localhost:3000/saved-post", + CONTACT:"http://localhost:3000/contact" } diff --git a/src/app/auth/register/register-form/register-form.component.ts b/src/app/auth/register/register-form/register-form.component.ts index cc0efa5..2217e38 100644 --- a/src/app/auth/register/register-form/register-form.component.ts +++ b/src/app/auth/register/register-form/register-form.component.ts @@ -6,6 +6,7 @@ import { } from "@angular/forms"; import {Router} from "@angular/router"; import {AuthService} from "../../../_service/auth.service"; +import {CommonService} from "../../../_service/common.service"; export function comparePassword(c: AbstractControl) { const v = c.value; @@ -24,7 +25,7 @@ export class RegisterFormComponent implements OnInit { public registerForm !: FormGroup; submitted = false; - constructor(private formBuilder: FormBuilder, private http: HttpClient, private router: Router, private authService: AuthService) { + constructor(private formBuilder: FormBuilder, private http: HttpClient,private commonService: CommonService, private router: Router, private authService: AuthService) { } ngOnInit(): void { @@ -53,11 +54,11 @@ export class RegisterFormComponent implements OnInit { alert("email đã đăng kí tài khoản. xin sử dụng email khác !") } else if (!this.registerForm.hasError('passwordnotmatch', ['pw']) && this.registerForm.value['termCheck'] == true) { this.authService.register(this.registerForm.value['email'], this.registerForm.controls['pw'].value.password).subscribe(res => { - alert("register success"); + this.commonService.toastSuccess("Đăng kí thành công thành công!") this.router.navigate(['signin']); }, error => { - alert("register false ") + this.commonService.toastError("Đăng kí thất bại!! Xin vui lòng thử lại") }) } }) diff --git a/src/app/pages/contact/contact.component.html b/src/app/pages/contact/contact.component.html index 1b29e0d..b7ead48 100644 --- a/src/app/pages/contact/contact.component.html +++ b/src/app/pages/contact/contact.component.html @@ -4,36 +4,35 @@

Liên hệ tòa soạn

-
- Họ và Tên - -
-
- Email - -
-
- Tiêu đề - -
-
- Chọn file - -
+
+
+ Họ và Tên + +
+
+ Email + +
+
+ Tiêu đề + +
-
- Nội dung - -
-
- -
+ +
+ Nội dung + +
+
+ +
+
diff --git a/src/app/pages/contact/contact.component.ts b/src/app/pages/contact/contact.component.ts index e492c7d..928b7d2 100644 --- a/src/app/pages/contact/contact.component.ts +++ b/src/app/pages/contact/contact.component.ts @@ -1,4 +1,9 @@ -import { Component, OnInit } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; +import {FormBuilder, FormControl, Validators} from "@angular/forms"; +import {HttpClient} from "@angular/common/http"; +import {Router} from "@angular/router"; +import {API_AUTH, API_URL} from "../../_api/apiURL"; +import {CommonService} from "../../_service/common.service"; @Component({ selector: 'app-contact', @@ -6,10 +11,31 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./contact.component.scss'] }) export class ContactComponent implements OnInit { + contactForm: any; - constructor() { } + constructor(private formBuilder: FormBuilder, private http: HttpClient,private commonService: CommonService, private router: Router) { + } ngOnInit(): void { + this.contactForm = this.formBuilder.group({ + email: new FormControl("", [Validators.required, Validators.email]), + name: new FormControl("", [Validators.required]), + title: new FormControl("", [Validators.required]), + text: new FormControl("", [Validators.required]) + }) } + contact() { + this.http.post(API_URL.CONTACT, { + "email": this.contactForm.value.email, + "name": this.contactForm.value.name, + "title": this.contactForm.value.title, + "text": this.contactForm.value.text + }).subscribe(res => { + this.commonService.toastSuccess("Gửi tin thành công thành công!") + window.location.reload(); + },error => { + this.commonService.toastError("Gửi tin thất bại!!") + }); + } }