Skip to content

Commit

Permalink
feat(match): lock toggle on customer page (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianAndersen authored Jun 17, 2024
1 parent 9a4e8b3 commit b428aa6
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"@angular/platform-browser": "^11.2.4",
"@angular/platform-browser-dynamic": "^11.2.4",
"@angular/router": "^11.2.4",
"@boklisten/bl-connect": "^0.19.21",
"@boklisten/bl-login": "^1.2.18",
"@boklisten/bl-connect": "^0.20.6",
"@boklisten/bl-login": "^1.2.20",
"@boklisten/bl-reporter": "^0.4.13",
"@fortawesome/angular-fontawesome": "^0.8.2",
"@fortawesome/fontawesome-svg-core": "^1.2.34",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
(deleted)="onUserDetailDeleted()"
></app-customer-delete>
</div>
<div class="col-12 mt-4" *ngIf="isAdmin()">
<app-customer-matches
[customer]="customerDetail"
></app-customer-matches>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<app-bl-common-toggle-button
*ngIf="userMatches.length > 0"
[(value)]="userMatchesLocked"
[name]="'Match-lås'"
(update)="onLockChange()"
></app-bl-common-toggle-button>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { CustomerMatchesComponent } from "./customer-matches.component";

describe("CustomerMatchesComponent", () => {
let component: CustomerMatchesComponent;
let fixture: ComponentFixture<CustomerMatchesComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [CustomerMatchesComponent],
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(CustomerMatchesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it("should create", () => {
expect(component).toBeTruthy();
});
});
54 changes: 54 additions & 0 deletions src/app/customer/customer-matches/customer-matches.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Component, Input, OnInit } from "@angular/core";
import { UserService } from "../../user/user.service";
import { ToasterService } from "../../toaster/toaster.service";
import { MatchService } from "@boklisten/bl-connect";
import { MatchVariant, UserDetail, UserMatch } from "@boklisten/bl-model";

@Component({
selector: "app-customer-matches",
templateUrl: "./customer-matches.component.html",
styleUrls: ["./customer-matches.component.scss"],
})
export class CustomerMatchesComponent implements OnInit {
@Input() customer: UserDetail;
public userMatchesLocked: boolean;
public userMatches: UserMatch[];

public isAdmin: boolean;

constructor(
private _userService: UserService,
private _matchService: MatchService,
private _toasterService: ToasterService
) {}

async ngOnInit() {
this.isAdmin = this._userService.havePermission("admin");
try {
this.userMatches = (await this._matchService.get()).filter(
(match): match is UserMatch =>
match._variant === MatchVariant.UserMatch &&
(match.sender === this.customer.id ||
match.receiver === this.customer.id)
);
this.userMatchesLocked = this.userMatches.some(
(match) => match.itemsLockedToMatch
);
} catch (_error) {
// User has no matches
}
}

public onLockChange() {
this._matchService
.updateLocksForCustomer(this.customer.id, this.userMatchesLocked)
.then((result) => {
this._toasterService.add("SUCCESS", "Match-lås ble oppdatert!");
})
.catch((error) => {
this._toasterService.add("WARNING", {
text: "Klarte ikke endre lås for overleveringer",
});
});
}
}
2 changes: 2 additions & 0 deletions src/app/customer/customer.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { CustomerPermissionComponent } from "./customer-permission/customer-perm
import { CustomerInformationComponent } from "./customer-information/customer-information.component";
import { CustomerChangeEmailComponent } from "./customer-change-email/customer-change-email.component";
import { CustomerComponent } from "./customer.component";
import { CustomerMatchesComponent } from "./customer-matches/customer-matches.component";

@NgModule({
imports: [
Expand Down Expand Up @@ -60,6 +61,7 @@ import { CustomerComponent } from "./customer.component";
CustomerInformationComponent,
CustomerChangeEmailComponent,
CustomerComponent,
CustomerMatchesComponent,
],
exports: [
CustomerCurrentComponent,
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1253,20 +1253,20 @@
"@babel/helper-validator-identifier" "^7.22.5"
to-fast-properties "^2.0.0"

"@boklisten/bl-connect@^0.19.17", "@boklisten/bl-connect@^0.19.21":
version "0.19.21"
resolved "https://registry.yarnpkg.com/@boklisten/bl-connect/-/bl-connect-0.19.21.tgz#03ed3829499813112343d8b6f5b9274575c85fd8"
integrity sha512-yGEcrRDpT3jiwiHTjQ0Vimqnsw8zSKQ2husMMDx4Q2OddHo2Qb7+gR+me4aJTckIOung5QbO+6PbiGR0ZYrHtg==
"@boklisten/bl-connect@^0.20.6":
version "0.20.6"
resolved "https://registry.yarnpkg.com/@boklisten/bl-connect/-/bl-connect-0.20.6.tgz#e7659d162322dea9c1f4aeca1b2fae0b54b0ca80"
integrity sha512-n+SHBwZ0C/9vyLIhhGDysbDrT3XuRb5QzNcls9/BN4l25NyYGUr3iWAOsi8Td4JTm0PO7MQANP9alLIrLtDWnA==
dependencies:
tslib "^2.1.0"

"@boklisten/bl-login@^1.2.18":
version "1.2.18"
resolved "https://registry.yarnpkg.com/@boklisten/bl-login/-/bl-login-1.2.18.tgz#905f0c6ca4bdbc8bb1c64988f0f3a2cf482eb849"
integrity sha512-E0pQR4itKgSZqmryv4TjsA0mRfquO6kGquNkjil6xohq2g92AgBlg/krhXwLvZZ4da8WO5xF8pg44PoVncflDg==
"@boklisten/bl-login@^1.2.20":
version "1.2.20"
resolved "https://registry.yarnpkg.com/@boklisten/bl-login/-/bl-login-1.2.20.tgz#95ce24dce03e980dc32b9a0aa6ad2ff5d16d10d2"
integrity sha512-aawPuOMEREKkk5h1FrTOPFCqldg3Xh+m1COhBEkgcfqCSdptU6SVMjpWzIStMkNb7aOxz28kmdyehkQdP6GLtA==
dependencies:
"@auth0/angular-jwt" "5.0.2"
"@boklisten/bl-connect" "^0.19.17"
"@boklisten/bl-connect" "^0.20.6"
date-fns "^2.17.0"
tslib "^2.1.0"

Expand Down

0 comments on commit b428aa6

Please sign in to comment.