-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(match): lock toggle on customer page (#724)
- Loading branch information
1 parent
9a4e8b3
commit b428aa6
Showing
8 changed files
with
102 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/app/customer/customer-matches/customer-matches.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
24 changes: 24 additions & 0 deletions
24
src/app/customer/customer-matches/customer-matches.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
54
src/app/customer/customer-matches/customer-matches.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters