From 9849f05c1f75b9ece140155d855b844c09e333b2 Mon Sep 17 00:00:00 2001 From: Gion-Andri Cantieni Date: Mon, 15 Jan 2024 17:48:33 +0100 Subject: [PATCH] feat: implement contact form --- .../static/imprint/imprint.component.html | 19 ++--- .../contact-form/contact-form.component.html | 70 +++++++++++++++++++ .../contact-form/contact-form.component.scss | 3 + .../contact-form.component.spec.ts | 21 ++++++ .../contact-form/contact-form.component.ts | 60 ++++++++++++++++ src/app/shared/data/contact-form.ts | 7 ++ .../services/contact-form.service.spec.ts | 16 +++++ .../shared/services/contact-form.service.ts | 24 +++++++ src/app/shared/shared.module.ts | 1 + 9 files changed, 206 insertions(+), 15 deletions(-) create mode 100644 src/app/shared/components/forms/contact-form/contact-form.component.html create mode 100644 src/app/shared/components/forms/contact-form/contact-form.component.scss create mode 100644 src/app/shared/components/forms/contact-form/contact-form.component.spec.ts create mode 100644 src/app/shared/components/forms/contact-form/contact-form.component.ts create mode 100644 src/app/shared/data/contact-form.ts create mode 100644 src/app/shared/services/contact-form.service.spec.ts create mode 100644 src/app/shared/services/contact-form.service.ts diff --git a/src/app/pages/static/imprint/imprint.component.html b/src/app/pages/static/imprint/imprint.component.html index 932e8dc..cda2051 100644 --- a/src/app/pages/static/imprint/imprint.component.html +++ b/src/app/pages/static/imprint/imprint.component.html @@ -1,18 +1,9 @@
-

Contact ed impressum

+

Contact

-

Tar dumondas davart il cuntegn e la moderaziun da quel pudais Vus gugent contactar:

+ -

- RTR Radiotelevisiun Svizra Rumantscha
- Via da Masans 2
- 7000 Cuira
- Tel. 058 136 30 00
- stab.program@rtr.ch
- www.rtr.ch -

- -

Autras dumondas en connex cun la pagina pudais Vus trametter a:

+

Impressum

Uniun da las Rumantschas
@@ -20,8 +11,6 @@

Contact ed impressum

Roman Pfister
Zimikerried 11
8603 Schwerzenbach
- roman.pfister@uniun-urb.clubdesk.com
- www.uniun-urb.ch + info@chalender.ch

diff --git a/src/app/shared/components/forms/contact-form/contact-form.component.html b/src/app/shared/components/forms/contact-form/contact-form.component.html new file mode 100644 index 0000000..7c02671 --- /dev/null +++ b/src/app/shared/components/forms/contact-form/contact-form.component.html @@ -0,0 +1,70 @@ +
+ + {{ message.title }}. {{ message.message }} + + +
+ + +
+ Endatescha p.pl. in num. +
+
+ +
+ + +
+ Endatescha p.pl. ina adressa dad e-mail. +
+
+ +
+ + +
+ Endatescha p.pl. ina adressa dad e-mail. +
+
+ +
+ tip da vossa dumonda:
+ + +
+ + + +
+ + + +
+ Tscherna in tip. +
+
+ + +
+ + +
+ Endatescha p.pl. in messadi. +
+
+ + +
diff --git a/src/app/shared/components/forms/contact-form/contact-form.component.scss b/src/app/shared/components/forms/contact-form/contact-form.component.scss new file mode 100644 index 0000000..1a504d9 --- /dev/null +++ b/src/app/shared/components/forms/contact-form/contact-form.component.scss @@ -0,0 +1,3 @@ +.form-check-label { + margin-left: 8px; +} diff --git a/src/app/shared/components/forms/contact-form/contact-form.component.spec.ts b/src/app/shared/components/forms/contact-form/contact-form.component.spec.ts new file mode 100644 index 0000000..9940158 --- /dev/null +++ b/src/app/shared/components/forms/contact-form/contact-form.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ContactFormComponent } from './contact-form.component'; + +describe('ContactFormComponent', () => { + let component: ContactFormComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ContactFormComponent] + }); + fixture = TestBed.createComponent(ContactFormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shared/components/forms/contact-form/contact-form.component.ts b/src/app/shared/components/forms/contact-form/contact-form.component.ts new file mode 100644 index 0000000..de80261 --- /dev/null +++ b/src/app/shared/components/forms/contact-form/contact-form.component.ts @@ -0,0 +1,60 @@ +import { Component } from '@angular/core'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { ContactFormService } from '../../../services/contact-form.service'; +import { Message } from '../../../data/notifications'; + +@Component({ + selector: 'app-contact-form', + templateUrl: './contact-form.component.html', + styleUrls: ['./contact-form.component.scss'] +}) +export class ContactFormComponent { + f: FormGroup = new FormGroup({}); + message = new Message('danger', '', ''); + isSending = false; + + constructor( + private contactFormService: ContactFormService, + ) { + this.initForm(); + } + + onSubmit() { + this.f.markAllAsTouched(); + + if (!this.f.valid) { + return; + } + + this.isSending = true; + + this.contactFormService.sendForm(this.f.value).subscribe(form => { + this.message.type = 'success'; + this.message.title = 'Success'; + this.message.message = 'Tramess cun success il formular da contact.' + + this.initForm(); + this.isSending = false; + }, error => { + this.message.type = 'danger'; + this.message.title = 'Errur'; + this.message.message = 'Impussibel da trametter il formular. Emprova pli tard anc ina giada.' + + this.isSending = false; + }); + } + + isFieldInvalid(fieldName: string) { + return this.f.get(fieldName)!.invalid && (this.f.get(fieldName)!.dirty || this.f.get(fieldName)!.touched); + } + + private initForm() { + this.f = new FormGroup({ + name: new FormControl('', [Validators.required]), + email: new FormControl('', [Validators.required, Validators.email]), + phone: new FormControl('', [Validators.required]), + type: new FormControl('', [Validators.required]), + message: new FormControl('', [Validators.required]) + }); + } +} diff --git a/src/app/shared/data/contact-form.ts b/src/app/shared/data/contact-form.ts new file mode 100644 index 0000000..7ac4554 --- /dev/null +++ b/src/app/shared/data/contact-form.ts @@ -0,0 +1,7 @@ +export class ContactForm { + name?: string; + email?: string; + phone?: string; + type?: string; + message?: string; +} diff --git a/src/app/shared/services/contact-form.service.spec.ts b/src/app/shared/services/contact-form.service.spec.ts new file mode 100644 index 0000000..6530f86 --- /dev/null +++ b/src/app/shared/services/contact-form.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ContactFormService } from './contact-form.service'; + +describe('ContactFormService', () => { + let service: ContactFormService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ContactFormService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/shared/services/contact-form.service.ts b/src/app/shared/services/contact-form.service.ts new file mode 100644 index 0000000..2bdf620 --- /dev/null +++ b/src/app/shared/services/contact-form.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { environment } from '../../../environments/environment'; +import { ContactForm } from '../data/contact-form'; + +@Injectable({ + providedIn: 'root' +}) +export class ContactFormService { + private basePath = 'contact'; + + constructor(private httpClient: HttpClient,) { + } + + public sendForm(contactForm: ContactForm): Observable { + const body: any = Object.assign({}, contactForm); + return this.httpClient.post(this.getUrl('contact-form'), body); + } + + getUrl(type: string) { + return environment.apiBasePath.concat(this.basePath.concat('/' + type)); + } +} diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 5a0faf2..280473e 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -80,6 +80,7 @@ import { ContactFormComponent } from './components/forms/contact-form/contact-fo ShortDomainPipe, InfoButtonComponent, IframeCodeGeneratorComponent, + ContactFormComponent, ] }) export class SharedModule {