diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 43f126f..683de90 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -41,6 +41,11 @@ const routes: Routes = [ loadChildren: () => import('./upload-dois/upload-dois.module').then(m => m.UploadDoisModule), data: {title: Irish.METADATA_PREFIX}, canActivate: [HasConsentGuard] }, + { + path: 'contact-us', + loadChildren: () => import('./contact/contact.module').then(m => m.ContactModule), + data: {title: Irish.METADATA_PREFIX} + }, { path: 'admin', loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule), diff --git a/src/app/contact/contact-routing.module.ts b/src/app/contact/contact-routing.module.ts new file mode 100644 index 0000000..9a3c7b7 --- /dev/null +++ b/src/app/contact/contact-routing.module.ts @@ -0,0 +1,13 @@ +import {NgModule} from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {ContactComponent} from './contact.component'; +import {PreviousRouteRecorder} from "../openaireLibrary/utils/piwik/previousRouteRecorder.guard"; + +@NgModule({ + imports: [ + RouterModule.forChild([ + { path: '', component: ContactComponent, canActivate: [], canDeactivate: [PreviousRouteRecorder]} + ]) + ] +}) +export class ContactRoutingModule { } diff --git a/src/app/contact/contact.component.html b/src/app/contact/contact.component.html new file mode 100644 index 0000000..19fa7e5 --- /dev/null +++ b/src/app/contact/contact.component.html @@ -0,0 +1,22 @@ + +
+
+
+ +

+ Contact us. +

+

+ Contact us. +

+
+
+
+
+ +
+ Our team will respond to your submission soon.
+
+
diff --git a/src/app/contact/contact.component.ts b/src/app/contact/contact.component.ts new file mode 100644 index 0000000..beeb6bc --- /dev/null +++ b/src/app/contact/contact.component.ts @@ -0,0 +1,99 @@ +import {Component, OnInit, ViewChild} from '@angular/core'; +import {ActivatedRoute, Router} from '@angular/router'; +import {EmailService} from "../openaireLibrary/utils/email/email.service"; +import {Composer} from "../openaireLibrary/utils/email/composer"; +import {Meta, Title} from "@angular/platform-browser"; +import {PiwikService} from "../openaireLibrary/utils/piwik/piwik.service"; +import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service"; +import {UntypedFormBuilder, UntypedFormGroup, Validators} from "@angular/forms"; +import {NotificationHandler} from "../openaireLibrary/utils/notification-handler"; +import {BaseComponent} from '../openaireLibrary/sharedComponents/base/base.component'; + +@Component({ + selector: 'contact', + templateUrl: './contact.component.html' +}) +export class ContactComponent extends BaseComponent implements OnInit { + public url: string = null; + public sending = false; + public contactForm: UntypedFormGroup; + @ViewChild('modal') modal; + + constructor(protected _route: ActivatedRoute, + protected _router: Router, + protected _title: Title, + protected _meta: Meta, + protected _piwikService: PiwikService, + protected seoService: SEOService, + private emailService: EmailService, + private fb: UntypedFormBuilder) { + super(); + } + + ngOnInit() { + this.title = 'Contact us'; + this.description = 'Contact us'; + this.url = this.properties.domain + this.properties.baseLink + this._router.url; + this.setMetadata(); + this.reset(); + } + + public send(event) { + if(event.valid === true) { + this.sendMail(this.properties.admins); + } + } + + public reset() { + this.contactForm = this.fb.group( { + name: this.fb.control('', Validators.required), + email: this.fb.control('', [Validators.required, Validators.email]), + subject: this.fb.control('', Validators.required), + message: this.fb.control('', Validators.required), + recaptcha: this.fb.control('', Validators.required), + }); + } + + private sendMail(admins: any) { + this.sending = true; + this.subscriptions.push(this.emailService.contact(this.properties, + Composer.composeEmailforIrishMonitor(this.contactForm.value, admins), + this.contactForm.value.recaptcha).subscribe( + res => { + if (res) { + this.sending = false; + this.reset(); + this.modalOpen(); + } else { + this.handleError('Email sent failed! Please try again.'); + } + }, + error => { + this.handleError('Email sent failed! Please try again.', error); + } + )); + } + + public modalOpen() { + this.modal.okButton = true; + this.modal.alertTitle = 'Your request has been successfully submitted'; + this.modal.alertMessage = false; + this.modal.cancelButton = false; + this.modal.okButtonLeft = false; + this.modal.okButtonText = 'OK'; + this.modal.open(); + } + + handleError(message: string, error = null) { + if(error) { + console.error(error); + } + NotificationHandler.rise(message, 'danger'); + this.sending = false; + this.contactForm.get('recaptcha').setValue(''); + } + + public goToHome() { + this._router.navigate(['/']); + } +} diff --git a/src/app/contact/contact.module.ts b/src/app/contact/contact.module.ts new file mode 100644 index 0000000..30aea4d --- /dev/null +++ b/src/app/contact/contact.module.ts @@ -0,0 +1,32 @@ +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {RouterModule} from '@angular/router'; + +import {ContactComponent} from './contact.component'; +import {ContactRoutingModule} from "./contact-routing.module"; +import {EmailService} from "../openaireLibrary/utils/email/email.service"; +import {RecaptchaModule} from "ng-recaptcha"; +import {AlertModalModule} from "../openaireLibrary/utils/modal/alertModal.module"; +import {IsRouteEnabled} from "../openaireLibrary/error/isRouteEnabled.guard"; +import {Schema2jsonldModule} from "../openaireLibrary/sharedComponents/schema2jsonld/schema2jsonld.module"; +import {ContactUsModule} from "../openaireLibrary/contact-us/contact-us.module"; + + +@NgModule({ + imports: [ + ContactRoutingModule, CommonModule, RouterModule, + AlertModalModule, RecaptchaModule, + Schema2jsonldModule, ContactUsModule + ], + declarations: [ + ContactComponent + ], + providers: [ + EmailService, IsRouteEnabled + ], + exports: [ + ContactComponent + ] +}) + +export class ContactModule { } diff --git a/src/app/openaireLibrary b/src/app/openaireLibrary index 21f49bb..5d7e72e 160000 --- a/src/app/openaireLibrary +++ b/src/app/openaireLibrary @@ -1 +1 @@ -Subproject commit 21f49bbc6cd0d4b350a68eabd8c79cb32b310658 +Subproject commit 5d7e72eb3d8585512af39b9775c716e88f7a8aad