diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 9019ffc6..fd25ec03 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -75,6 +75,7 @@ import { environment } from 'src/environments/environment'; import { AppInitService } from './services/app-init.service'; import { appConfigFactory } from './app-config-factory'; import { VerificationComponent } from './pages/admin/verification/verification.component'; +import { EmailComponent } from './pages/admin/email/email.component'; import { InventoryResourcesComponent } from './pages/product-inventory/inventory-resources/inventory-resources.component'; import { InventoryServicesComponent } from './pages/product-inventory/inventory-services/inventory-services.component'; import { ProductInvDetailComponent } from './pages/product-inventory/inventory-items/product-inv-detail/product-inv-detail.component'; @@ -158,6 +159,7 @@ import { OperatorRevenueSharingComponent } from "src/app/pages/admin/operator-re ContactUsComponent, ContactUsFormComponent, VerificationComponent, + EmailComponent, InventoryResourcesComponent, InventoryServicesComponent, ProductInvDetailComponent, diff --git a/src/app/pages/admin/admin.component.html b/src/app/pages/admin/admin.component.html index 362387eb..2feaeef2 100644 --- a/src/app/pages/admin/admin.component.html +++ b/src/app/pages/admin/admin.component.html @@ -25,6 +25,12 @@

{{ 'ADMIN._verification' | translate }} +
  • + {{ 'ADMIN._revenue' | translate }} +
  • +
  • + {{ 'ADMIN._email' | translate }} +
  • @@ -40,6 +46,9 @@

    {{ 'ADMIN._revenue' | translate }} + @@ -58,5 +67,8 @@

    + + + + + +
    +

    {{ 'ADMIN._verification' | translate }}

    +
    + +
    +
    +
    + + + + + + + + + + + + + + +
    + +
    + +
    +
    +
    +
    + + +@if(showError){ + +} diff --git a/src/app/pages/admin/email/email.component.spec.ts b/src/app/pages/admin/email/email.component.spec.ts new file mode 100644 index 00000000..39731655 --- /dev/null +++ b/src/app/pages/admin/email/email.component.spec.ts @@ -0,0 +1,22 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { EmailComponent } from './email.component'; + +describe('EmailComponent', () => { + let component: EmailComponent; + let fixture: ComponentFixture; + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [EmailComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(EmailComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/admin/email/email.component.ts b/src/app/pages/admin/email/email.component.ts new file mode 100644 index 00000000..566db78c --- /dev/null +++ b/src/app/pages/admin/email/email.component.ts @@ -0,0 +1,100 @@ +import { HttpClient } from '@angular/common/http'; +import { Component } from '@angular/core'; +import { FormGroup, FormControl, Validators } from '@angular/forms'; +import { EventMessageService } from 'src/app/services/event-message.service'; +import { environment } from 'src/environments/environment'; + +@Component({ + selector: 'email', + templateUrl: './email.component.html', + styleUrl: './email.component.css' +}) +export class EmailComponent { + + showError: boolean = false; + errorMessage: string = ''; + + emailForm = new FormGroup({ + smtpServer: new FormControl('', [Validators.required]), + smtpPort: new FormControl('', [Validators.required]), + email: new FormControl('', [Validators.required]), + emailUser: new FormControl('', [Validators.required]), + emailPassword: new FormControl('', [Validators.required]) + }); + + constructor( + private eventMessage: EventMessageService, + private http: HttpClient + ) {} + + ngOnInit() { + this.getConfig(); + } + + goBack() { + this.eventMessage.emitAdminCategories(true); + } + + fillData(data: any) { + this.emailForm.setValue({ + smtpServer: data.smtpServer, + smtpPort: data.smtpPort, + email: data.email, + emailUser: data.emailUser, + emailPassword: '' + }); + } + + getConfig() { + const url = `${environment.BASE_URL}/charging/api/orderManagement/notify/config`; + return this.http.get(url).subscribe({ + next: data => { + this.fillData(data); + }, + error: error => { + console.error('There was an error while getting config!', error); + if(error.error.error){ + console.log(error) + this.errorMessage = 'Error: ' + error.error.error; + } else { + this.errorMessage = 'There was an error while getting the config'; + } + this.showError = true; + setTimeout(() => { + this.showError = false; + }, 3000); + } + }) + } + + addConfig() { + // Get the product specification + const url = `${environment.BASE_URL}/charging/api/orderManagement/notify/config`; + const body = { + "smtpServer": this.emailForm.value.smtpServer, + "smtpPort": this.emailForm.value.smtpPort, + "email": this.emailForm.value.email, + "emailUser": this.emailForm.value.emailUser, + "emailPassword": this.emailForm.value.emailPassword + } + + return this.http.post(url, body).subscribe({ + next: data => { + this.fillData(data); + }, + error: error => { + console.error('There was an error while updating!', error); + if(error.error.error){ + console.log(error) + this.errorMessage = 'Error: ' + error.error.error; + } else { + this.errorMessage = 'There was an error while updating the config'; + } + this.showError = true; + setTimeout(() => { + this.showError = false; + }, 3000); + } + }) + } +} diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index a8182c95..7cd44683 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -1006,7 +1006,12 @@ "_productId": "Product ID", "_vc": "Verifiable Credential", "_add": "Add", - "_revenue": "Revenue sharing" + "_revenue": "Revenue sharing", + "_email": "Email", + "_smtpServer": "SMTP Server", + "_smtpPort": "SMTP Port", + "_emailUser": "Email User", + "_emailPass": "Email Password" }, "CATEGORIES":{ "_categories": "Categories", diff --git a/src/assets/i18n/es.json b/src/assets/i18n/es.json index a8182c95..7cd44683 100644 --- a/src/assets/i18n/es.json +++ b/src/assets/i18n/es.json @@ -1006,7 +1006,12 @@ "_productId": "Product ID", "_vc": "Verifiable Credential", "_add": "Add", - "_revenue": "Revenue sharing" + "_revenue": "Revenue sharing", + "_email": "Email", + "_smtpServer": "SMTP Server", + "_smtpPort": "SMTP Port", + "_emailUser": "Email User", + "_emailPass": "Email Password" }, "CATEGORIES":{ "_categories": "Categories",