Browse Source

excel remove and basic UI changes

master
Karan 3 years ago
parent
commit
371b444e1f
  1. 16
      src/app/pages/home/home.component.html
  2. 74
      src/app/pages/home/home.component.ts
  3. 8
      src/app/pages/home/home.service.ts
  4. 6
      tsconfig.json

16
src/app/pages/home/home.component.html

@ -21,17 +21,31 @@
class="user-input font-body-small-bold file-input"
placeholder="Upload sales file"
(change)="addfile($event)"
#fileUploader
/>
<!-- formControlName="fileUpload" -->
</div>
<!-- [disabled]="!fileUploadForm.valid || isLoading" -->
<button type="submit">
<button type="submit" [disabled]="!submitButton">
{{ isLoading ? "Sending messages..." : "Submit" }}
</button>
<p
style="color: green; margin-top: 1rem; text-align: center"
*ngIf="submitted"
>
File Uploaded Successfully
</p>
</form>
</section>
<section>
<button style="margin-top: 12rem" routerLink="/feedbacks">
Feedbacks
</button>
</section>
<p class="error font-body-small">{{ error }}</p>
</main>
</div>

74
src/app/pages/home/home.component.ts

@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import IHeaderProps from 'src/app/models/header';
import { logOutButton, login, home } from 'src/app/constants/constants';
@ -18,6 +18,8 @@ import { HomeService } from './home.service';
styleUrls: ['./home.component.scss'],
})
export class HomeComponent {
@ViewChild('fileUploader') fileUploader: ElementRef;
headerProps: IHeaderProps = {
rightIcon: logOutButton,
rightIconRoute: 'logout',
@ -26,13 +28,14 @@ export class HomeComponent {
fileUploadForm: FormGroup;
isLoading = false;
submitButton = false;
error = '';
isSalesForm = true;
submitted = false;
file: any;
arrayBuffer: any;
filelist: any = [];
arrayToBeSend: any = [];
customerPhonenumbers: string[] = [];
constructor(
@ -57,29 +60,54 @@ export class HomeComponent {
}
switchSalesServiceTab() {
this.arrayToBeSend = [];
this.submitButton = false;
this.removeSelectedFile();
this.isSalesForm = !this.isSalesForm;
}
triggerWhatsappMessages(messages: object[]) {
const httpBody = {
messages
let feedbackURL = 'https://be18n8dnwum.typeform.com/to/OBJbe7fB';
if (!this.isSalesForm) {
feedbackURL = 'https://be18n8dnwum.typeform.com/to/OBJbe7fB';
}
const omniBody = {
scenarioKey: '0A9B6D3A044E5EF5D38E688900202DD8',
destinations: messages,
sms: {
text: 'Hi, Thank you. Bajaj Auto Test Message.',
regional: {
indiaDlt: {
contentTemplateId: '1107161477011893589',
principalEntityId: '1101635620000025441',
},
},
},
whatsApp: {
templateName: 'infobip_kz_test_hsm_2',
templateData: ['feedback URL: ' + feedbackURL],
language: 'en_GB',
},
};
this.homeService.sendWhatsApp(httpBody).subscribe(
this.homeService.sendOmni(omniBody).subscribe(
(res) => {
console.log('success', res);
this.isLoading = false;
// this.submitButton = true;
this.submitted = true;
this.removeSelectedFile();
},
(err) => {
console.log('failed', err);
this.isLoading = false;
// this.submitButton = true;
}
)
);
}
readExcelFile() {
this.isLoading = true;
this.submitButton = false;
let fileReader = new FileReader();
fileReader.readAsArrayBuffer(this.file);
@ -103,18 +131,9 @@ export class HomeComponent {
if (this.isSalesForm) {
for (let i = 0; i < this.filelist.length; i++) {
let data = {
from: '447491163530',
to: this.filelist[i]['PHONE NUMBER'],
content: {
templateName: 'infobip_kz_test_hsm_2',
templateData: {
body: {
placeholders: [this.filelist[i]['CUSTOMER NAME']],
to: {
phoneNumber: '91' + this.filelist[i]['PHONE NUMBER'],
},
},
language: 'en_GB',
},
callbackData: 'Callback data',
};
phoneNumber.push(data);
@ -122,31 +141,28 @@ export class HomeComponent {
} else {
for (let i = 0; i < this.filelist.length; i++) {
let data = {
from: '447491163530',
to: this.filelist[i]['Mobile No'],
content: {
templateName: 'infobip_kz_test_hsm_2',
templateData: {
body: {
placeholders: [this.filelist[i]['Customer']],
},
to: {
phoneNumber: '91' + this.filelist[i]['Mobile No'],
},
language: 'en_GB',
},
callbackData: 'Callback data',
};
phoneNumber.push(data);
}
phoneNumber.shift();
}
// after reading file and storing all phonenumbers in an array
// call whatsapp sending api function here
this.triggerWhatsappMessages(phoneNumber);
};
}
addfile(event: any) {
this.submitButton = true;
this.file = event.target.files[0];
}
removeSelectedFile() {
this.fileUploader.nativeElement.value = null;
}
}

8
src/app/pages/home/home.service.ts

@ -7,7 +7,7 @@ import { IHomeRequest, IHomeResponse } from '../../../app/model/home';
const httpOptions = {
headers: new HttpHeaders({
'authorization':
authorization:
'App 2b8cba9008e1da2f2733ff8300cf1973-dc928670-56f9-4a29-8725-69239d669e74',
}),
};
@ -15,14 +15,18 @@ const httpOptions = {
const whatsAppUrl =
'https://mpwyr4.api.infobip.com/whatsapp/1/message/template';
const omniUrl = 'https://mpwyr4.api.infobip.com/omni/1/advanced';
@Injectable({
providedIn: 'root',
})
export class HomeService {
constructor(private http: HttpClient) {}
sendWhatsApp(body: any): Observable<any> {
return this.http.post(whatsAppUrl, body, httpOptions);
}
sendOmni(body: any): Observable<any> {
return this.http.post(omniUrl, body, httpOptions);
}
}

6
tsconfig.json

@ -5,6 +5,7 @@
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strictPropertyInitialization": false,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
@ -16,10 +17,7 @@
"importHelpers": true,
"target": "es2017",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
"lib": ["es2018", "dom"]
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,

Loading…
Cancel
Save