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" class="user-input font-body-small-bold file-input"
placeholder="Upload sales file" placeholder="Upload sales file"
(change)="addfile($event)" (change)="addfile($event)"
#fileUploader
/> />
<!-- formControlName="fileUpload" --> <!-- formControlName="fileUpload" -->
</div> </div>
<!-- [disabled]="!fileUploadForm.valid || isLoading" --> <!-- [disabled]="!fileUploadForm.valid || isLoading" -->
<button type="submit">
<button type="submit" [disabled]="!submitButton">
{{ isLoading ? "Sending messages..." : "Submit" }} {{ isLoading ? "Sending messages..." : "Submit" }}
</button> </button>
<p
style="color: green; margin-top: 1rem; text-align: center"
*ngIf="submitted"
>
File Uploaded Successfully
</p>
</form> </form>
</section> </section>
<section>
<button style="margin-top: 12rem" routerLink="/feedbacks">
Feedbacks
</button>
</section>
<p class="error font-body-small">{{ error }}</p> <p class="error font-body-small">{{ error }}</p>
</main> </main>
</div> </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 IHeaderProps from 'src/app/models/header';
import { logOutButton, login, home } from 'src/app/constants/constants'; import { logOutButton, login, home } from 'src/app/constants/constants';
@ -18,6 +18,8 @@ import { HomeService } from './home.service';
styleUrls: ['./home.component.scss'], styleUrls: ['./home.component.scss'],
}) })
export class HomeComponent { export class HomeComponent {
@ViewChild('fileUploader') fileUploader: ElementRef;
headerProps: IHeaderProps = { headerProps: IHeaderProps = {
rightIcon: logOutButton, rightIcon: logOutButton,
rightIconRoute: 'logout', rightIconRoute: 'logout',
@ -26,13 +28,14 @@ export class HomeComponent {
fileUploadForm: FormGroup; fileUploadForm: FormGroup;
isLoading = false; isLoading = false;
submitButton = false;
error = ''; error = '';
isSalesForm = true; isSalesForm = true;
submitted = false;
file: any; file: any;
arrayBuffer: any; arrayBuffer: any;
filelist: any = []; filelist: any = [];
arrayToBeSend: any = [];
customerPhonenumbers: string[] = []; customerPhonenumbers: string[] = [];
constructor( constructor(
@ -57,29 +60,54 @@ export class HomeComponent {
} }
switchSalesServiceTab() { switchSalesServiceTab() {
this.arrayToBeSend = [];
this.submitButton = false;
this.removeSelectedFile();
this.isSalesForm = !this.isSalesForm; this.isSalesForm = !this.isSalesForm;
} }
triggerWhatsappMessages(messages: object[]) { 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) => { (res) => {
console.log('success', res); console.log('success', res);
this.isLoading = false; this.isLoading = false;
// this.submitButton = true;
this.submitted = true;
this.removeSelectedFile();
}, },
(err) => { (err) => {
console.log('failed', err); console.log('failed', err);
this.isLoading = false; this.isLoading = false;
// this.submitButton = true;
} }
)
);
} }
readExcelFile() { readExcelFile() {
this.isLoading = true; this.isLoading = true;
this.submitButton = false;
let fileReader = new FileReader(); let fileReader = new FileReader();
fileReader.readAsArrayBuffer(this.file); fileReader.readAsArrayBuffer(this.file);
@ -103,18 +131,9 @@ export class HomeComponent {
if (this.isSalesForm) { if (this.isSalesForm) {
for (let i = 0; i < this.filelist.length; i++) { for (let i = 0; i < this.filelist.length; i++) {
let data = { 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']],
},
},
language: 'en_GB',
to: {
phoneNumber: '91' + this.filelist[i]['PHONE NUMBER'],
}, },
callbackData: 'Callback data',
}; };
phoneNumber.push(data); phoneNumber.push(data);
@ -122,31 +141,28 @@ export class HomeComponent {
} else { } else {
for (let i = 0; i < this.filelist.length; i++) { for (let i = 0; i < this.filelist.length; i++) {
let data = { let data = {
from: '447491163530',
to: this.filelist[i]['Mobile No'],
content: {
templateName: 'infobip_kz_test_hsm_2',
templateData: {
body: {
placeholders: [this.filelist[i]['Customer']],
},
},
language: 'en_GB',
to: {
phoneNumber: '91' + this.filelist[i]['Mobile No'],
}, },
callbackData: 'Callback data',
}; };
phoneNumber.push(data); phoneNumber.push(data);
} }
phoneNumber.shift();
} }
// after reading file and storing all phonenumbers in an array // after reading file and storing all phonenumbers in an array
// call whatsapp sending api function here // call whatsapp sending api function here
this.triggerWhatsappMessages(phoneNumber); this.triggerWhatsappMessages(phoneNumber);
}; };
} }
addfile(event: any) { addfile(event: any) {
this.submitButton = true;
this.file = event.target.files[0]; 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 = { const httpOptions = {
headers: new HttpHeaders({ headers: new HttpHeaders({
'authorization':
authorization:
'App 2b8cba9008e1da2f2733ff8300cf1973-dc928670-56f9-4a29-8725-69239d669e74', 'App 2b8cba9008e1da2f2733ff8300cf1973-dc928670-56f9-4a29-8725-69239d669e74',
}), }),
}; };
@ -15,14 +15,18 @@ const httpOptions = {
const whatsAppUrl = const whatsAppUrl =
'https://mpwyr4.api.infobip.com/whatsapp/1/message/template'; 'https://mpwyr4.api.infobip.com/whatsapp/1/message/template';
const omniUrl = 'https://mpwyr4.api.infobip.com/omni/1/advanced';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class HomeService { export class HomeService {
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {}
sendWhatsApp(body: any): Observable<any> { sendWhatsApp(body: any): Observable<any> {
return this.http.post(whatsAppUrl, body, httpOptions); 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": "./", "baseUrl": "./",
"outDir": "./dist/out-tsc", "outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"strictPropertyInitialization": false,
"strict": true, "strict": true,
"noImplicitReturns": true, "noImplicitReturns": true,
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
@ -16,10 +17,7 @@
"importHelpers": true, "importHelpers": true,
"target": "es2017", "target": "es2017",
"module": "es2020", "module": "es2020",
"lib": [
"es2018",
"dom"
]
"lib": ["es2018", "dom"]
}, },
"angularCompilerOptions": { "angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false, "enableI18nLegacyMessageIdFormat": false,

Loading…
Cancel
Save