Skip to content

Commit 48a1d99

Browse files
company page: upload logo on file select
1 parent 479b6ca commit 48a1d99

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

frontend/src/app/app.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ export class AppComponent {
194194
});
195195
this._company.getCompanyLogo(res.company.id).subscribe( logo => {
196196
this.logo = logo;
197-
console.log(logo);
198197
})
199198
this._uiSettings.getUiSettings().subscribe(settings => {
200199
console.log(settings);

frontend/src/app/components/company/company.component.html

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -263,22 +263,15 @@ <h2 class="heading-2 tableHeader__heading">Members <span *ngIf="currentPlan ===
263263

264264
<form #uploadLogoForm="ngForm" (ngSubmit)="uploadLogo()" class="upload-logo-form">
265265
<div class="file-uploader-appearance">
266-
<button mat-stroked-button type="button" (click)="fileInput.click()">Browse File</button>
267-
<span>{{ companyLogoFile && companyLogoFile.name ? companyLogoFile.name : 'No file selected.' }}</span>
266+
<button mat-stroked-button type="button" (click)="fileInput.click()">
267+
<mat-icon fontSet="material-icons-outlined">upload</mat-icon>
268+
Company logo
269+
</button>
268270
<input #fileInput type="file" class="file-input" name="db-table-file" (change)="onCompanyLogoSelected($event)" hidden>
269271
</div>
270-
<button mat-flat-button type="submit" color="primary" [disabled]="submittingLogo">
271-
Upload
272-
</button>
273-
<div *ngIf="companyLogoPreview" class="image-preview">
274-
<img [src]="companyLogoPreview" alt="Logo preview" style="max-width: 200px; max-height: 200px; margin-top: 10px;" />
275-
</div>
276-
<div *ngIf="logo">
277-
<img [src]="logo" alt="Logo" style="max-width: 200px; max-height: 200px; margin-top: 10px;" />
278-
</div>
279272
</form>
280273

281-
<svg class="white-label-preview" width="4539" height="1982" viewBox="0 0 4539 1982" fill="none" xmlns="http://www.w3.org/2000/svg">
274+
<svg class="white-label-preview" width="4539" height="2082" viewBox="0 0 4539 2082" fill="none" xmlns="http://www.w3.org/2000/svg">
282275
<g clip-path="url(#clip0_474_332)">
283276
<rect width="4538.62" height="1482" fill="white"/>
284277
<g filter="url(#filter0_d_474_332)">
@@ -332,12 +325,13 @@ <h2 class="heading-2 tableHeader__heading">Members <span *ngIf="currentPlan ===
332325
<path d="M1490.41 415.663H1458.31C1453.55 415.663 1451.18 411.963 1452.96 407.647L1464.85 379.283C1467.23 373.117 1463.66 366.951 1457.12 366.951H1427.4C1423.83 366.951 1420.86 369.418 1419.67 372.501L1404.81 406.414C1402.43 412.58 1405.4 416.896 1411.34 416.896H1442.26C1445.83 416.896 1448.8 418.746 1449.99 421.829L1464.26 455.742C1466.04 460.058 1463.66 463.758 1458.31 463.758H1386.97C1384 463.758 1381.03 466.224 1379.24 468.691L1366.76 501.987C1363.79 508.153 1366.76 514.319 1373.89 514.319H1444.04C1447.01 514.319 1449.99 511.236 1451.18 508.153L1467.23 471.157C1468.42 467.458 1471.39 465.608 1474.36 465.608H1505.87C1511.82 465.608 1514.79 460.675 1511.82 455.125L1498.74 421.212C1497.55 418.746 1493.98 416.279 1491.01 416.279L1490.41 415.663Z" fill="white"/>
333326
</g>
334327

335-
<rect x="0" y="1482" width="100%" height="500" fill="#212121" />
336-
<image
328+
<rect x="0" y="1482" width="100%" height="600" fill="#212121" />
329+
330+
<image *ngIf="logo"
337331
x="100"
338332
y="1570"
339-
width="300"
340-
height="300"
333+
width="400"
334+
height="400"
341335
[attr.href]="logo" />
342336

343337
<defs>
@@ -355,7 +349,7 @@ <h2 class="heading-2 tableHeader__heading">Members <span *ngIf="currentPlan ===
355349
<rect width="4538.62" height="1482" fill="white"/>
356350
</clipPath>
357351
</defs>
358-
</svg>
352+
</svg>
359353

360354

361355
<mat-slide-toggle class="test-connections-toggle" *ngIf="currentUser && currentUser.role === 'ADMIN'"

frontend/src/app/components/company/company.component.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ export class CompanyComponent {
128128
this.getCompanyMembers(this.company.id);
129129
} else if (arg === 'domain') {
130130
this.getCompanyCustomDomain(this.company.id);
131+
}
132+
else if (arg === 'logo') {
133+
// this.submittingLogo = true;
134+
this._company.getCompanyLogo(this.company.id).subscribe();
131135
};
132136
});
133137
}
@@ -300,21 +304,32 @@ export class CompanyComponent {
300304
}
301305

302306
onCompanyLogoSelected(event: any) {
307+
this.submittingLogo = true;
308+
303309
const input = event.target as HTMLInputElement;
304310
const file = input.files?.[0];
305311

306312
if (file) {
307313
this.companyLogoFile = file;
308314

309-
const reader = new FileReader();
310-
reader.onload = () => {
311-
this.companyLogoPreview = reader.result as string;
312-
};
313-
reader.readAsDataURL(file);
315+
// const reader = new FileReader();
316+
// reader.onload = () => {
317+
// this.companyLogoPreview = reader.result as string;
318+
// };
319+
// reader.readAsDataURL(file);
314320
} else {
315321
this.companyLogoFile = null;
316-
this.companyLogoPreview = null;
322+
// this.companyLogoPreview = null;
317323
}
324+
325+
this._company.uploadLogo(this.company.id, this.companyLogoFile).subscribe(res => {
326+
this.submittingLogo = false;
327+
this.angulartics2.eventTrack.next({
328+
action: 'Company: logo is uploaded successfully',
329+
});
330+
}, err => {
331+
this.submittingLogo = false;
332+
});
318333
}
319334

320335
uploadLogo() {

frontend/src/app/services/company.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ export class CompanyService {
331331
map(res => {
332332
this._notifications.showSuccessSnackbar('Logo has been updated.');
333333
this.company.next('logo');
334+
// this.getCompanyLogo(companyId);
334335
return res
335336
}),
336337
catchError((err) => {
@@ -345,8 +346,8 @@ export class CompanyService {
345346
return this._http.get<any>(`/company/logo/${companyId}`)
346347
.pipe(
347348
map(res => {
348-
this.companyLogo = `data:image/svg+xml;base64,${res.logo}`;
349-
return `data:image/svg+xml;base64,${res.logo}`;
349+
this.companyLogo = `data:${res.logo.mimeType};base64,${res.logo.image}`;
350+
return `data:${res.logo.mimeType};base64,${res.logo.image}`;
350351
}),
351352
catchError((err) => {
352353
console.log(err);

0 commit comments

Comments
 (0)