diff --git a/src/app/core/components/contact/contact.component.html b/src/app/core/components/contact/contact.component.html index 1c0316f4d18f0e7cb16aa58ab586243578865aee..a1b63b4aed848162fe0fe359361652d85308c235 100644 --- a/src/app/core/components/contact/contact.component.html +++ b/src/app/core/components/contact/contact.component.html @@ -15,21 +15,6 @@ </div> --> <div class="column is-10-touch is-9"> <div class="fields-container"> - <div class="field"> - <label class="label">Civilité</label> - <div class="field"> - <p class="control"> - <label class="radio button is-outlined title-label" [ngClass]="{'is-danger': title === 'mr'}"> - <input class="is-hidden" type="radio" value="mr" formControlName="title"> - Monsieur - </label> - <label class="radio button is-outlined title-label" [ngClass]="{'is-danger': title === 'mrs'}"> - <input class="is-hidden" type="radio" value="mrs" formControlName="title"> - Madame - </label> - </p> - </div> - </div> <div class="field"> <label class="label">Nom</label> @@ -58,14 +43,15 @@ </div> </div> - <div class="field"> + <!-- <div class="field"> <label class="label">Confirmez l'adresse mail</label> <div class="field"> <p class="control"> <input class="input" type="email" formControlName="emailConfirmation"> </p> </div> - </div> + </div> --> + </div> </div> @@ -88,14 +74,13 @@ <label class="label">Message</label> <div class="field"> <p class="control"> - <input class="input" type="textarea" formControlName="message"> + <textarea class="input" type="textarea" formControlName="text"></textarea> </p> </div> </div> <div class="has-text-centered button-wrapper"> - <!-- [disabled]="form.invalid" --> - <button class="button is-primary" (click)="send()">Envoyer</button> + <button class="button is-primary" [disabled]="form.invalid" (click)="send()">Envoyer</button> </div> </div> </div> diff --git a/src/app/core/components/contact/contact.component.ts b/src/app/core/components/contact/contact.component.ts index d1cc620e79bfb6eaa218f075b783894601ee69fa..4ac230863ea5e17e69a35b7c2e78517bb30484f6 100644 --- a/src/app/core/components/contact/contact.component.ts +++ b/src/app/core/components/contact/contact.component.ts @@ -1,5 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { EmailService } from '../../services'; +import { Email } from '../../models'; @Component({ selector: 'app-contact', @@ -12,15 +14,15 @@ export class ContactComponent implements OnInit { constructor( private _fb: FormBuilder, + private emailService: EmailService, ) { this.form = this._fb.group({ - title: ['', Validators.required], firstname: ['', Validators.required], lastname: ['', Validators.required], email: ['', [Validators.required, Validators.email]], - emailConfirmation: ['', [Validators.required, Validators.email]], + // emailConfirmation: ['', [Validators.required, Validators.email]], subject: ['', Validators.required], - message: ['', Validators.required], + text: ['', Validators.required], }); } @@ -30,10 +32,15 @@ export class ContactComponent implements OnInit { send() { console.log(this.form.value); + const email = new Email(this.form.value); + console.log(email); + this.emailService.send(email).subscribe( + (res) => { + console.log(res); + }, + (err) => { + console.log(err); + }, + ); } - - get title() { - return this.form.get('title').value; - } - } diff --git a/src/app/core/models/email.model.ts b/src/app/core/models/email.model.ts new file mode 100644 index 0000000000000000000000000000000000000000..603b44846e28704e9235df4f6960e3e20a53346c --- /dev/null +++ b/src/app/core/models/email.model.ts @@ -0,0 +1,25 @@ +import { environment } from '../../../environments/environment'; + +export interface IEmail { + to: string[]; + email: string; + subject: string; + text: string; + firstname: string; + lastname: string; +} + +export class Email { + to: string[]; + from: string; + subject: string; + text: string; + + constructor(email: IEmail) { + this.to = [environment.emailService.contact]; + this.subject = email.subject; + this.text = email.text; + + this.from = `${email.firstname} ${email.lastname} ${email.email}`; + } +} diff --git a/src/app/core/models/index.ts b/src/app/core/models/index.ts index 804ec59ded0ef6ad842ec93fe8c958a85456e135..3465a2638380b55ca22fe8bd0ea1e69cd4ac50d2 100644 --- a/src/app/core/models/index.ts +++ b/src/app/core/models/index.ts @@ -1,5 +1,7 @@ import { Notification, INotification } from './notification.model'; import { IMatomoResponse } from './matomo.model'; +import { IEmail, Email } from './email.model'; export { Notification, INotification }; export { IMatomoResponse }; +export { IEmail, Email }; diff --git a/src/app/core/services/email.service.ts b/src/app/core/services/email.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..af75b19f832fb47906557f276ab417026842a820 --- /dev/null +++ b/src/app/core/services/email.service.ts @@ -0,0 +1,16 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { environment } from '../../../environments/environment'; +import { Email } from '../models'; + +@Injectable() +export class EmailService { + + constructor( + private _httpClient: HttpClient, + ) {} + + send(email: Email) { + return this._httpClient.post(environment.emailService.url + '/send', email); + } +} diff --git a/src/app/core/services/index.ts b/src/app/core/services/index.ts index ed90907ea1e9a8b600f61fe1ae841317c93fb80e..15ae6b2712fa5254fde435de2ef7bf1e5028a5ac 100644 --- a/src/app/core/services/index.ts +++ b/src/app/core/services/index.ts @@ -3,8 +3,9 @@ import { NotificationService } from './notification.service'; import { MatomoService } from './matomo.service'; import { NavigationHistoryService } from './navigation-history.service'; import { StorageService } from './storage.service'; +import { EmailService } from './email.service'; -export { ErrorService, NotificationService, MatomoService, NavigationHistoryService }; +export { ErrorService, NotificationService, MatomoService, NavigationHistoryService, EmailService }; // tslint:disable-next-line:variable-name export const CoreServices = [ @@ -13,4 +14,5 @@ export const CoreServices = [ MatomoService, NavigationHistoryService, StorageService, + EmailService, ]; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 29775bc4d505500f4312618a2bf2f3a71d4a4329..4ad3bf6a4148411a0493396b3458301ab1459758 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -23,6 +23,11 @@ export const environment = { url: 'http://localhost:3000/api', }, + emailService: { + url: 'https://kong.alpha.grandlyon.com/email', + contact: 'fab.forestier42@gmail.com', + }, + // Path to the built app in a particular language angularAppHost: { fr: '/fr',