diff --git a/bizmatch-server/src/mail/mail.controller.ts b/bizmatch-server/src/mail/mail.controller.ts index 1ce880c..54e08b7 100644 --- a/bizmatch-server/src/mail/mail.controller.ts +++ b/bizmatch-server/src/mail/mail.controller.ts @@ -7,6 +7,10 @@ export class MailController { constructor(private mailService: MailService) {} @Post() sendEMail(@Body() mailInfo: MailInfo): Promise { - return this.mailService.sendInquiry(mailInfo); + if (mailInfo.listing) { + return this.mailService.sendInquiry(mailInfo); + } else { + return this.mailService.sendRequest(mailInfo); + } } } diff --git a/bizmatch-server/src/mail/mail.service.ts b/bizmatch-server/src/mail/mail.service.ts index 2da58d6..839868a 100644 --- a/bizmatch-server/src/mail/mail.service.ts +++ b/bizmatch-server/src/mail/mail.service.ts @@ -41,4 +41,23 @@ export class MailService { }, }); } + async sendRequest(mailInfo: MailInfo): Promise { + if (isEmpty(mailInfo.sender.name)) { + return { fields: [{ fieldname: 'name', message: 'Required' }] }; + } + await this.mailerService.sendMail({ + to: 'support@bizmatch.net', + from: `"Bizmatch Support Team" `, + subject: `Support Request from ${mailInfo.sender.name}`, + //template: './inquiry', // `.hbs` extension is appended automatically + template: join(__dirname, '../..', 'mail/templates/request.hbs'), + context: { + // ✏️ filling curly brackets with content + request: mailInfo.sender.comments, + iname: mailInfo.sender.name, + phone: mailInfo.sender.phoneNumber, + email: mailInfo.sender.email, + }, + }); + } } diff --git a/bizmatch-server/src/mail/templates/request.hbs b/bizmatch-server/src/mail/templates/request.hbs new file mode 100644 index 0000000..77f5b3a --- /dev/null +++ b/bizmatch-server/src/mail/templates/request.hbs @@ -0,0 +1,83 @@ + + + + + + Notification: New User Request + + + +
+
Notification: New request from a user of the Bizmatch Network
+
+
Requester Information
+
+ Contact Name: + {{iname}} +
+
+ Contact Email: + {{email}} +
+
+ Contact Phone: + {{phone}} +
+
+ Question: + {{request}} +
+
+
+ + \ No newline at end of file diff --git a/bizmatch/src/app/pages/subscription/email-us/email-us.component.html b/bizmatch/src/app/pages/subscription/email-us/email-us.component.html index dcf8808..0d8cf69 100644 --- a/bizmatch/src/app/pages/subscription/email-us/email-us.component.html +++ b/bizmatch/src/app/pages/subscription/email-us/email-us.component.html @@ -1,35 +1,34 @@ -
-
- -
-
Contact Us
- -
-
-
-
- - -
-
- - -
-
-
- - -
-
- - -
-
- -
-
+
+ +
+
Contact Us
+ +
+
+
+
+ +
+
+ + +
+
+
+ + +
+
+ + +
+
+ +
+
-
\ No newline at end of file +
+
diff --git a/bizmatch/src/app/pages/subscription/email-us/email-us.component.ts b/bizmatch/src/app/pages/subscription/email-us/email-us.component.ts index f6530fd..7b69c9d 100644 --- a/bizmatch/src/app/pages/subscription/email-us/email-us.component.ts +++ b/bizmatch/src/app/pages/subscription/email-us/email-us.component.ts @@ -1,28 +1,50 @@ import { Component } from '@angular/core'; -import { ButtonModule } from 'primeng/button'; -import { CheckboxModule } from 'primeng/checkbox'; -import { InputTextModule } from 'primeng/inputtext'; -import { StyleClassModule } from 'primeng/styleclass'; -import { SelectOptionsService } from '../../../services/select-options.service'; -import { DropdownModule } from 'primeng/dropdown'; -import { FormsModule } from '@angular/forms'; -import { CommonModule } from '@angular/common'; -import { ToggleButtonModule } from 'primeng/togglebutton'; -import { TagModule } from 'primeng/tag'; -import data from '../../../../assets/data/user.json'; -import { ActivatedRoute } from '@angular/router'; -import { InputTextareaModule } from 'primeng/inputtextarea'; -import { ChipModule } from 'primeng/chip'; -import { MenuAccountComponent } from '../../menu-account/menu-account.component'; -import { DividerModule } from 'primeng/divider'; -import { TableModule } from 'primeng/table'; +import { KeycloakService } from 'keycloak-angular'; + +import { MessageService } from 'primeng/api'; +import { InputMaskModule } from 'primeng/inputmask'; +import { User } from '../../../../../../bizmatch-server/src/models/db.model'; +import { ErrorResponse, KeycloakUser, MailInfo } from '../../../../../../bizmatch-server/src/models/main.model'; +import { environment } from '../../../../environments/environment'; +import { MailService } from '../../../services/mail.service'; +import { UserService } from '../../../services/user.service'; +import { SharedModule } from '../../../shared/shared/shared.module'; +import { map2User } from '../../../utils/utils'; @Component({ selector: 'app-email-us', standalone: true, - imports: [CommonModule, StyleClassModule, MenuAccountComponent, DividerModule,ButtonModule, CheckboxModule, InputTextModule, DropdownModule, FormsModule, ChipModule,InputTextareaModule], + imports: [SharedModule, InputMaskModule], + providers: [MessageService], templateUrl: './email-us.component.html', - styleUrl: './email-us.component.scss' + styleUrl: './email-us.component.scss', }) export class EmailUsComponent { - + mailinfo: MailInfo; + keycloakUser: KeycloakUser; + user: User; + errorResponse: ErrorResponse; + constructor(private mailService: MailService, private userService: UserService, public keycloakService: KeycloakService, private messageService: MessageService) { + this.mailinfo = { sender: {}, userId: '', email: '', url: environment.mailinfoUrl }; + } + async ngOnInit() { + const token = await this.keycloakService.getToken(); + this.keycloakUser = map2User(token); + if (this.keycloakUser) { + this.user = await this.userService.getByMail(this.keycloakUser.email); + this.mailinfo.sender = { name: `${this.user.firstname} ${this.user.lastname}`, email: this.user.email, phoneNumber: this.user.phoneNumber, state: this.user.companyLocation }; + } + } + async mail() { + this.mailinfo.email = 'support@bizmatch.net'; + const result = await this.mailService.mail(this.mailinfo); + if (result) { + this.errorResponse = result as ErrorResponse; + } else { + this.errorResponse = null; + this.messageService.add({ severity: 'info', summary: 'Confirmed', detail: 'Your request has been forwarded to the support team of bizmatch.', life: 3000 }); + } + } + containsError(fieldname: string) { + return this.errorResponse?.fields.map(f => f.fieldname).includes(fieldname); + } }