Skip to content

Commit

Permalink
Merge 1c4f2b5 into c35f3ce
Browse files Browse the repository at this point in the history
  • Loading branch information
EagleEye25 committed Mar 13, 2019
2 parents c35f3ce + 1c4f2b5 commit b4adc9d
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/app/core/market/api/bid/bid.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export class Bid extends Product {
return this.order.listing;
}

get BidDatas(): any {
return this.order.BidDatas;
}

setActiveOrders() {
this.activeBuySell = ['Accept bid', 'Mark as shipped', 'Mark as delivered', 'Make payment']
.includes(this.messages.action_button);
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/market/api/bid/bid.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export class BidService {
});
}

rejectBidCommand(id: number): Observable<any> {
const params = ['reject', id];
rejectBidCommand(id: number, rejectReason: string): Observable<any> {
const params = ['reject', id, rejectReason];
return this.market.call('bid', params);
}

Expand Down
5 changes: 5 additions & 0 deletions src/app/core/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ export const Messages = {
}


export const rejectMessages = {
OUT_OF_STOCK: 'Item not currently in stock.'
}

export const isPrerelease = (release?: string): boolean => {
let version = release;
let found = false;
Expand All @@ -398,3 +402,4 @@ export const isMainnetRelease = (release?: string): boolean => {

return !version.includes('testnet');
}

19 changes: 19 additions & 0 deletions src/app/market/_order.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,25 @@
border-radius: $radius;
}
}

.reject-message-info {
margin-top: 8px;
.title {
font-size: 13px;
text-transform: uppercase;
font-weight: 500;
color: $text;
}
.more-info {
@extend %enable-select;
margin-left: 10px;
color: darken($color, 7%);
background: rgba($color-alert, 0.1);
padding: 3px 8px;
border-radius: $radius;
}
}

.action-buttons {
.single .mat-icon {
margin: 0;
Expand Down
14 changes: 11 additions & 3 deletions src/app/market/shared/orders/order-item/order-item.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
</div>
</div>

<div class="status-info" *ngIf="order?.status === 'rejected'">
<div class="reject-message-info">
<p>
<span class="title">Reason for rejection</span>
<code class="more-info">{{ checkRejectMessage() }}</code>
</p>

</div>
</div>

<div class="detail" fxLayout="row" fxLayoutGap="30px">

<div class="buyer-info" fxFlex="65%">
Expand Down Expand Up @@ -72,9 +82,7 @@

<mat-action-row class="action-buttons" fxLayout fxLayoutAlign="space-between stretch">
<div class="left">
<button mat-button color="warn"
(click)="callBid('reject')"
*ngIf="order?.messages?.allow_reject_order"
<button mat-button color="warn" (click)="openRejectBidModal()" *ngIf="order?.messages?.allow_reject_order"
class="small">
<mat-icon fontSet="partIcon" fontIcon="part-cross"></mat-icon>
Reject bid &amp; cancel order
Expand Down
32 changes: 30 additions & 2 deletions src/app/market/shared/orders/order-item/order-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { SnackbarService } from '../../../../core/snackbar/snackbar.service';
import { PlaceOrderComponent } from '../../../../modals/market-place-order/place-order.component';
import { ShippingComponent } from '../../../../modals/market-shipping/shipping.component';
import { BidConfirmationModalComponent } from 'app/modals/market-bid-confirmation-modal/bid-confirmation-modal.component';

import { RejectBidComponent } from 'app/modals/reject-bid/reject-bid.component';
import { rejectMessages } from '../../../../core/util/utils';
import { ProcessingModalComponent } from 'app/modals/processing-modal/processing-modal.component';

@Component({
Expand All @@ -24,6 +27,8 @@ export class OrderItemComponent implements OnInit {
@Input() order: Bid;
trackNumber: string;
country: string = '';
selectedMessage: string;

constructor(
private listingService: ListingService,
private bid: BidService,
Expand Down Expand Up @@ -128,7 +133,7 @@ export class OrderItemComponent implements OnInit {
}

rejectBid() {
this.bid.rejectBidCommand(this.order.id).take(1).subscribe(res => {
this.bid.rejectBidCommand(this.order.id, this.selectedMessage).take(1).subscribe(res => {
this.snackbarService.open(`Order rejected ${this.order.listing.title}`);
this.order.OrderItem.status = 'REJECTED';
this.order = new Bid(this.order, this.order.type);
Expand Down Expand Up @@ -179,6 +184,30 @@ export class OrderItemComponent implements OnInit {
});
}

openRejectBidModal(): void {
const dialogRef = this.dialog.open(RejectBidComponent, {
disableClose: true,
data: {selectedMessage: this.selectedMessage}
});
dialogRef.afterClosed().subscribe(result => {
this.selectedMessage = result;
if (result !== 'CANCEL') {
this.callAction('reject');
}
});
}

checkRejectMessage() {
if (this.order.status === 'rejected') {
for (let k = this.order.BidDatas.length - 1; k >= 0; k--) {
if (rejectMessages[this.order.BidDatas[k].dataValue]) {
return rejectMessages[this.order.BidDatas[k].dataValue];
}
}
return 'No information provided'
}
}

openProcessingModal() {
const dialog = this.dialog.open(ProcessingModalComponent, {
disableClose: true,
Expand All @@ -187,5 +216,4 @@ export class OrderItemComponent implements OnInit {
}
});
}

}
4 changes: 4 additions & 0 deletions src/app/modals/modals.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ import {

import { BidConfirmationModalComponent } from 'app/modals/market-bid-confirmation-modal/bid-confirmation-modal.component';
import { ListingExpirationComponent } from './market-listing-expiration/listing-expiration.component';
import { RejectBidComponent } from './reject-bid/reject-bid.component';
import { ProcessingModalComponent } from './processing-modal/processing-modal.component';
import { AlphaMainnetWarningComponent } from './alpha-mainnet-warning/alpha-mainnet-warning.component';


@NgModule({
imports: [
CommonModule,
Expand Down Expand Up @@ -80,6 +82,7 @@ import { AlphaMainnetWarningComponent } from './alpha-mainnet-warning/alpha-main
ProposalVoteConfirmationComponent,
BidConfirmationModalComponent,
ListingExpirationComponent,
RejectBidComponent,
ProcessingModalComponent,
AlphaMainnetWarningComponent
],
Expand Down Expand Up @@ -112,6 +115,7 @@ import { AlphaMainnetWarningComponent } from './alpha-mainnet-warning/alpha-main
ProposalVoteConfirmationComponent,
BidConfirmationModalComponent,
ListingExpirationComponent,
RejectBidComponent,
ProcessingModalComponent,
AlphaMainnetWarningComponent
],
Expand Down
33 changes: 33 additions & 0 deletions src/app/modals/reject-bid/reject-bid.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div mat-dialog-title>Choose reason for rejecting bid</div>
<button class="small-close-button pull-right" (click)="dialogClose()">
<mat-icon fontSet="partIcon" fontIcon="part-circle-remove"></mat-icon>
</button>

<div mat-dialog-content class="dialog-content">

<p class="lead">
Please indicate a reason for rejecting this bid.
</p>

<div class="row" fxLayout fxLayoutAlign="center center">
<mat-form-field class="full-width" fxFlex="50%">
<mat-select value="{{data?.selectedMessage}}" placeholder="Reason For Rejection">
<mat-option *ngFor="let rMsg of rejectMessages" [value]="rMsg.value">
{{rMsg.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
</div>

</div><!-- .dialog-content -->

<mat-dialog-actions fxLayoutAlign="space-between center">
<button mat-button mat-dialog-close (click)="dialogClose()">
<mat-icon fontSet="partIcon" fontIcon="part-cross"></mat-icon>
Cancel
</button>
<button [disabled]="!data?.selectedMessage" mat-raised-button color="primary" [mat-dialog-close]="data?.selectedMessage">
<mat-icon fontSet="partIcon" fontIcon="part-check"></mat-icon>
Reject Bid
</button>
</mat-dialog-actions>
Empty file.
39 changes: 39 additions & 0 deletions src/app/modals/reject-bid/reject-bid.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { CoreModule } from '../../core/core.module';
import { SharedModule } from '../../wallet/shared/shared.module';
import { CoreUiModule } from '../../core-ui/core-ui.module';
import { RejectBidComponent } from './reject-bid.component';

describe('RejectBidComponent', () => {
let component: RejectBidComponent;
let fixture: ComponentFixture<RejectBidComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ RejectBidComponent ],
imports: [
BrowserAnimationsModule,
SharedModule,
CoreModule.forRoot(),
CoreUiModule.forRoot(),
],
providers: [
{ provide: MatDialogRef },
{ provide: MAT_DIALOG_DATA }
]
})
.compileComponents();
}));

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
51 changes: 51 additions & 0 deletions src/app/modals/reject-bid/reject-bid.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Component, Output, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { rejectMessages } from '../../core/util/utils';

@Component({
selector: 'app-reject-bid',
templateUrl: './reject-bid.component.html',
styleUrls: ['./reject-bid.component.scss']
})
export class RejectBidComponent implements OnInit {

rejectMessages: RejectionMessages[] = [];

constructor(
private dialogRef: MatDialogRef<RejectBidComponent>,
@Inject(MAT_DIALOG_DATA) public data: DialogData,
) {
this.createMessages();
}

ngOnInit() {
}

createMessages () {
const keys = Object.keys(rejectMessages);
for (let k = 0; k < keys.length; k++) {
this.rejectMessages.push({
value: keys[k],
viewValue: rejectMessages[keys[k]]
})
}
}

confirm(): void {
this.dialogRef.close(this.data.selectedMessage);
}

dialogClose(): void {
this.dialogRef.close('CANCEL');
}
}

export interface RejectionMessages {
value: string;
viewValue: string;
}

export interface DialogData {
selectedMessage: string;
}

0 comments on commit b4adc9d

Please sign in to comment.