Skip to content

Commit 06b5cac

Browse files
Merge pull request #3471 from ita-social-projects/bugfix/#7749-cancelled-order-unable-to-edit
[Bugfix] #7749 order with status cancelled/brought_by_himself/done unable to edit
2 parents 88644d6 + a4f0b47 commit 06b5cac

30 files changed

+278
-134
lines changed

src/app/shared/address-input/address-input.component.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AfterViewInit, ChangeDetectorRef, Component, Input, OnDestroy, OnInit } from '@angular/core';
1+
import { AfterViewInit, ChangeDetectorRef, Component, Input, OnChanges, OnDestroy, OnInit } from '@angular/core';
22
import {
33
AbstractControl,
44
ControlValueAccessor,
@@ -43,12 +43,13 @@ import { AddressService } from '../services/address/address.service';
4343
}
4444
]
4545
})
46-
export class AddressInputComponent implements OnInit, AfterViewInit, OnDestroy, ControlValueAccessor, Validator {
46+
export class AddressInputComponent implements OnInit, AfterViewInit, OnDestroy, OnChanges, ControlValueAccessor, Validator {
4747
@Input() edit: boolean;
4848
@Input() address: Address;
4949
@Input() addFromProfile: boolean;
5050
@Input() isShowCommentInput = true;
5151
@Input() isFromAdminPage: boolean;
52+
@Input() isUneditableStatus: boolean;
5253

5354
addressForm: FormGroup;
5455
currentLanguage: string;
@@ -69,6 +70,7 @@ export class AddressInputComponent implements OnInit, AfterViewInit, OnDestroy,
6970

7071
private buildingPattern = Patterns.numericAndAlphabetic;
7172
private $destroy: Subject<void> = new Subject();
73+
private viewInitialized = false;
7274

7375
autocompleteRegionRequest = {
7476
input: '',
@@ -170,6 +172,28 @@ export class AddressInputComponent implements OnInit, AfterViewInit, OnDestroy,
170172
}
171173

172174
ngAfterViewInit(): void {
175+
if (this.isUneditableStatus) {
176+
this.disableAllFields();
177+
}
178+
this.initializeFieldStates();
179+
this.viewInitialized = true;
180+
this.cdr.detectChanges();
181+
}
182+
183+
ngOnChanges(): void {
184+
if (!this.viewInitialized) {
185+
return;
186+
}
187+
188+
if (this.isUneditableStatus) {
189+
this.disableAllFields();
190+
} else {
191+
this.enableAllFields();
192+
this.initializeFieldStates();
193+
}
194+
}
195+
196+
private initializeFieldStates(): void {
173197
if (!this.edit) {
174198
this.region.value ? this.city.enable() : this.city.disable();
175199
this.street.disable();
@@ -180,11 +204,29 @@ export class AddressInputComponent implements OnInit, AfterViewInit, OnDestroy,
180204
} else {
181205
this.updateDistrictEditState();
182206
}
207+
183208
if (this.isFromAdminPage) {
184209
this.addressComment.disable();
185210
this.region.disable();
186211
}
187-
this.cdr.detectChanges();
212+
}
213+
214+
private disableAllFields(): void {
215+
this.city.disable();
216+
this.street.disable();
217+
this.houseNumber.disable();
218+
this.houseCorpus.disable();
219+
this.entranceNumber.disable();
220+
this.district.disable();
221+
}
222+
223+
private enableAllFields(): void {
224+
this.city.enable();
225+
this.street.enable();
226+
this.houseNumber.enable();
227+
this.houseCorpus.enable();
228+
this.entranceNumber.enable();
229+
this.district.enable();
188230
}
189231

190232
initListeners(): void {

src/app/ubs/ubs-admin/components/ubs-admin-address-details/ubs-admin-address-details.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ <h1 class="form__headline py-3">{{ 'address-details.title' | translate }}</h1>
1010
[address]="address"
1111
[edit]="true"
1212
[isFromAdminPage]="true"
13+
[isUneditableStatus]="isEditableStatus$ | async"
1314
></app-address-input>
1415
<hr />
1516
</div>
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1-
import { Component, Input } from '@angular/core';
1+
import { Component, Input, OnChanges } from '@angular/core';
22
import { FormControl } from '@angular/forms';
3+
import { OrderStatus } from '@ubs/ubs/order-status.enum';
4+
import { BehaviorSubject } from 'rxjs';
35
import { Address } from 'src/app/ubs/ubs/models/ubs.interface';
46

57
@Component({
68
selector: 'app-ubs-admin-address-details',
79
templateUrl: './ubs-admin-address-details.component.html',
810
styleUrls: ['./ubs-admin-address-details.component.scss']
911
})
10-
export class UbsAdminAddressDetailsComponent {
12+
export class UbsAdminAddressDetailsComponent implements OnChanges {
1113
@Input() addressExportDetailsDto: FormControl;
1214
@Input() address: Address;
15+
@Input() orderStatus: string;
1316
pageOpen: boolean;
17+
isEditableStatus$ = new BehaviorSubject<boolean>(false);
18+
1419
openDetails(): void {
1520
this.pageOpen = !this.pageOpen;
1621
}
22+
23+
ngOnChanges(): void {
24+
const status =
25+
this.orderStatus === OrderStatus.CANCELED ||
26+
this.orderStatus === OrderStatus.DONE ||
27+
this.orderStatus === OrderStatus.BROUGHT_IT_HIMSELF;
28+
this.isEditableStatus$.next(status);
29+
}
1730
}

src/app/ubs/ubs-admin/components/ubs-admin-export-details/ubs-admin-export-details.component.html

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
<div class="container mb-3">
22
<div class="form" [formGroup]="exportDetailsDto">
33
<div class="empty_card" (click)="openDetails()">
4-
<img
5-
*ngIf="!pageOpen && (exportDetailsDto.valid || isOrderStatusCancelOrDone)"
6-
src="assets/img/ubs-admin-orders/arrow_up.svg"
7-
alt="arrow up"
8-
/>
9-
<img
10-
*ngIf="pageOpen && (exportDetailsDto.valid || isOrderStatusCancelOrDone)"
11-
src="assets/img/ubs-admin-orders/arrow_down.svg"
12-
alt="arrow down"
13-
/>
14-
<img
15-
*ngIf="pageOpen && !exportDetailsDto.valid && !isOrderStatusCancelOrDone"
16-
src="assets/img/ubs-admin-orders/red_arrow_down.svg"
17-
alt="arrow down"
18-
/>
19-
<img *ngIf="isFormRequired" src="assets/img/ubs-admin-orders/red_arrow_up.svg" alt="arrow up" />
20-
4+
<img [src]="loadArrowImage().imgUrl" [alt]="loadArrowImage().imgAlt" />
215
<h1 class="form__headline">{{ 'export-details.title' | translate }}</h1>
226
<div *ngIf="isFormRequired" class="alert-message">{{ 'export-details.alert-message' | translate }}</div>
237
</div>

src/app/ubs/ubs-admin/components/ubs-admin-export-details/ubs-admin-export-details.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('UbsAdminExportDetailsComponent', () => {
105105

106106
it('should return true when pageOpen is false, exportDetailsDto is invalid and orderStatus is not cancel or done', () => {
107107
component.pageOpen = false;
108-
component.isOrderStatusCancelOrDone = false;
108+
component.isUneditableStatus = false;
109109
expect(component.isFormRequired).toBeFalsy();
110110
});
111111
});

src/app/ubs/ubs-admin/components/ubs-admin-export-details/ubs-admin-export-details.component.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { formatDate } from '@angular/common';
2-
import { Component, Input, OnDestroy, OnInit, AfterViewChecked, ChangeDetectorRef, AfterViewInit, OnChanges } from '@angular/core';
2+
import { Component, Input, OnDestroy, OnInit, ChangeDetectorRef, OnChanges } from '@angular/core';
33
import { FormGroup, Validators } from '@angular/forms';
44
import { Subject } from 'rxjs';
55
import { IExportDetails } from '../../models/ubs-admin.interface';
@@ -29,12 +29,12 @@ export class UbsAdminExportDetailsComponent implements OnInit, OnDestroy, OnChan
2929
currentHour: string;
3030
allReceivingStations: string[];
3131
currentDate: string;
32-
isOrderStatusCancelOrDone = false;
32+
isUneditableStatus = false;
3333
resetFieldImg = './assets/img/ubs-tariff/bigClose.svg';
34-
private statuses = [OrderStatus.BROUGHT_IT_HIMSELF, OrderStatus.CANCELED];
34+
private readonly statuses = [OrderStatus.BROUGHT_IT_HIMSELF, OrderStatus.CANCELED];
3535

3636
constructor(
37-
private cdr: ChangeDetectorRef,
37+
private readonly cdr: ChangeDetectorRef,
3838
public orderService: OrderService
3939
) {}
4040

@@ -57,8 +57,12 @@ export class UbsAdminExportDetailsComponent implements OnInit, OnDestroy, OnChan
5757
this.exportDetailsDto.updateValueAndValidity();
5858
});
5959

60-
if (this.orderStatus === OrderStatus.CANCELED || this.orderStatus === OrderStatus.DONE) {
61-
this.isOrderStatusCancelOrDone = true;
60+
if (
61+
this.orderStatus === OrderStatus.CANCELED ||
62+
this.orderStatus === OrderStatus.DONE ||
63+
this.orderStatus === OrderStatus.BROUGHT_IT_HIMSELF
64+
) {
65+
this.isUneditableStatus = true;
6266
}
6367

6468
this.cdr.detectChanges();
@@ -70,6 +74,10 @@ export class UbsAdminExportDetailsComponent implements OnInit, OnDestroy, OnChan
7074
this.currentDate = new Date().toISOString().split('T')[0];
7175
}
7276

77+
loadArrowImage() {
78+
return this.orderService.getArrowImageSrc(this.isFormRequired, this.pageOpen, this.exportDetailsDto.valid, this.isUneditableStatus);
79+
}
80+
7381
resetValue(): void {
7482
this.exportDetailsDto.get('receivingStationId').setValue(null);
7583
}
@@ -79,11 +87,7 @@ export class UbsAdminExportDetailsComponent implements OnInit, OnDestroy, OnChan
7987
}
8088

8189
get isFormRequired(): boolean {
82-
const isNotOpen = !this.pageOpen;
83-
const isNotValid = !this.exportDetailsDto.valid;
84-
const isNotCancelOrDone = !this.isOrderStatusCancelOrDone;
85-
86-
return isNotOpen && isNotValid && isNotCancelOrDone;
90+
return !this.pageOpen && !this.exportDetailsDto.valid && !this.isUneditableStatus;
8791
}
8892

8993
showTimePickerClick(): void {

src/app/ubs/ubs-admin/components/ubs-admin-order-client-info/ubs-admin-order-client-info.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ <h3 class="form__headline">{{ 'customer-info.title' | translate }}</h3>
5757
class="form-control name-input"
5858
type="text"
5959
id="recipient-name"
60-
[readonly]="isOrderCanceled || !this.isEmployeeCanEditOrder"
60+
[readonly]="uneditableStatus || !this.isEmployeeCanEditOrder"
6161
formControlName="recipientName"
6262
/>
6363
<div *ngIf="userInfoDto.controls['recipientName'].invalid && userInfoDto.controls['recipientName'].touched">
@@ -69,7 +69,7 @@ <h3 class="form__headline">{{ 'customer-info.title' | translate }}</h3>
6969
<div>
7070
<input
7171
class="form-control name-input"
72-
[readonly]="isOrderCanceled || !this.isEmployeeCanEditOrder"
72+
[readonly]="uneditableStatus || !this.isEmployeeCanEditOrder"
7373
type="text"
7474
id="recipient-surname"
7575
formControlName="recipientSurName"
@@ -88,7 +88,7 @@ <h3 class="form__headline">{{ 'customer-info.title' | translate }}</h3>
8888
</label>
8989
<input
9090
class="form-control"
91-
[readonly]="isOrderCanceled || !this.isEmployeeCanEditOrder"
91+
[readonly]="uneditableStatus || !this.isEmployeeCanEditOrder"
9292
type="tel"
9393
id="recipient-tel"
9494
placeholder="{{ 'customer-info.recipient.tel-placeholder' | translate }}"
@@ -108,7 +108,7 @@ <h3 class="form__headline">{{ 'customer-info.title' | translate }}</h3>
108108
</label>
109109
<input
110110
class="form-control"
111-
[readonly]="isOrderCanceled || !this.isEmployeeCanEditOrder"
111+
[readonly]="uneditableStatus || !this.isEmployeeCanEditOrder"
112112
type="email"
113113
id="recipient-email"
114114
placeholder="{{ 'customer-info.recipient.email-placeholder' | translate }}"

src/app/ubs/ubs-admin/components/ubs-admin-order-client-info/ubs-admin-order-client-info.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class UbsAdminOrderClientInfoComponent implements OnInit, OnChanges, OnDe
2929
totalUserViolations: number;
3030
isOrderDone: boolean;
3131
isOrderNotTakenOut: boolean;
32-
isOrderCanceled: boolean;
32+
uneditableStatus: boolean;
3333

3434
constructor(private dialog: MatDialog) {}
3535

@@ -44,7 +44,10 @@ export class UbsAdminOrderClientInfoComponent implements OnInit, OnChanges, OnDe
4444
ngOnChanges(changes: SimpleChanges): void {
4545
if (changes.orderStatus?.currentValue) {
4646
this.isOrderDone = changes.orderStatus.currentValue === OrderStatus.DONE;
47-
this.isOrderCanceled = changes.orderStatus.currentValue === OrderStatus.CANCELED;
47+
this.uneditableStatus =
48+
this.isOrderDone ||
49+
changes.orderStatus.currentValue === OrderStatus.CANCELED ||
50+
changes.orderStatus.currentValue === OrderStatus.BROUGHT_IT_HIMSELF;
4851
this.isOrderNotTakenOut = changes.orderStatus.currentValue === OrderStatus.NOT_TAKEN_OUT;
4952
}
5053
}

src/app/ubs/ubs-admin/components/ubs-admin-order-details-form/ubs-admin-order-details-form.component.html

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,25 @@ <h3 class="form__headline">{{ 'order-details.title' | translate }}</h3>
199199
[unmask]="false"
200200
placeholder="XXXXXXXXXX"
201201
formControlName="{{ i }}"
202-
[readonly]="!isEmployeeCanEditOrder"
202+
[readonly]="isDisabledStatus || !isEmployeeCanEditOrder"
203+
[ngClass]="{ 'disabled-field': isDisabledStatus }"
203204
/>
204-
<span input-close-button (click)="deleteOrder(i)">&times;</span>
205+
<span
206+
input-close-button
207+
tabindex="0"
208+
role="button"
209+
(click)="deleteOrder(i)"
210+
(keydown.enter)="deleteOrder(i)"
211+
*ngIf="isEmployeeCanEditOrder && !isDisabledStatus"
212+
>&times;</span
213+
>
205214
</div>
206215
</ng-container>
207-
<button *ngIf="checkMaxOrdersFromShop() && isEmployeeCanEditOrder" class="add-order-num" (click)="addOrderNumberFromShop()">
216+
<button
217+
*ngIf="checkMaxOrdersFromShop() && isEmployeeCanEditOrder && !isDisabledStatus"
218+
class="add-order-num"
219+
(click)="addOrderNumberFromShop()"
220+
>
208221
{{ 'order-details.additional-orders' | translate }}
209222
</button>
210223
</div>

src/app/ubs/ubs-admin/components/ubs-admin-order-details-form/ubs-admin-order-details-form.component.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FormArray, FormControl, FormGroup, Validators } from '@angular/forms';
33
import { OrderService } from 'src/app/ubs/ubs-admin/services/order.service';
44
import { OrderStatus, PaymnetStatus } from 'src/app/ubs/ubs/order-status.enum';
55
import { Masks, Patterns } from 'src/assets/patterns/patterns';
6-
import { IOrderDetails, IOrderInfo, IPaymentInfo, orderPaymentInfo } from '../../models/ubs-admin.interface';
6+
import { IOrderDetails, IOrderInfo, orderPaymentInfo } from '../../models/ubs-admin.interface';
77
import { limitStatus } from '../ubs-admin-tariffs/ubs-tariffs.enum';
88

99
@Component({
@@ -17,8 +17,6 @@ export class UbsAdminOrderDetailsFormComponent implements OnInit, OnChanges {
1717
SHOP_NUMBER_MASK = Masks.ecoStoreMask;
1818
SHOP_NUMBER_PATTERN = Patterns.ordersPattern;
1919
amountOfBigBags: number;
20-
payMore = true;
21-
isInputDisabled = false;
2220
isVisible: boolean;
2321
isOrderBroughtByHimself = false;
2422
bagsInfo;
@@ -38,7 +36,8 @@ export class UbsAdminOrderDetailsFormComponent implements OnInit, OnChanges {
3836
isOrderDone = false;
3937
isOrderNotTakenOut = false;
4038
isDisabledWriteOffStation = false;
41-
sumOrder: number;
39+
isDisabledStatus = false;
40+
4241
@Output() deleteNumberOrderFromEcoShopChanged = new EventEmitter<boolean>();
4342
@Output() checkMinOrder = new EventEmitter<boolean>();
4443
@Output() changeCurrentPrice = new EventEmitter<number>();
@@ -56,7 +55,7 @@ export class UbsAdminOrderDetailsFormComponent implements OnInit, OnChanges {
5655
@Input() updateBonusAccount: number;
5756
@Input() paymentInfo: orderPaymentInfo;
5857

59-
constructor(private orderService: OrderService) {}
58+
constructor(private readonly orderService: OrderService) {}
6059

6160
ngOnChanges(changes: SimpleChanges) {
6261
const curStatus = changes.orderStatusInfo?.currentValue;
@@ -86,8 +85,8 @@ export class UbsAdminOrderDetailsFormComponent implements OnInit, OnChanges {
8685
this.isVisible = !this.isVisible;
8786
}
8887

89-
if (!changes?.orderStatusInfo?.firstChange) {
90-
this.isDisabledConfirmQuantity();
88+
if (changes?.orderStatusInfo) {
89+
this.isDisabledOrderDetails();
9190
}
9291
this.recalculateSum();
9392
}
@@ -114,12 +113,23 @@ export class UbsAdminOrderDetailsFormComponent implements OnInit, OnChanges {
114113
this.orderDetails = JSON.parse(JSON.stringify(this.orderDetailsOriginal));
115114
}
116115

117-
private isDisabledConfirmQuantity() {
118-
if (this.isOrderBroughtByHimself || this.isOrderCancelled || this.isOrderNotTakenOut || this.isOrderDone) {
116+
private isDisabledOrderDetails() {
117+
const shouldDisable = this.isOrderBroughtByHimself || this.isOrderCancelled || this.isOrderNotTakenOut || this.isOrderDone;
118+
119+
if (shouldDisable) {
119120
this.orderDetails.bags.forEach((bag) => {
120121
this.orderDetailsForm.controls[`confirmedQuantity${bag.id}`].disable();
121122
});
123+
this.orderDetailsForm.controls['certificates'].disable();
124+
this.orderDetailsForm.controls['storeOrderNumbers'].disable();
125+
} else {
126+
this.orderDetails.bags.forEach((bag) => {
127+
this.orderDetailsForm.controls[`confirmedQuantity${bag.id}`].enable();
128+
});
129+
this.orderDetailsForm.controls['certificates'].enable();
130+
this.orderDetailsForm.controls['storeOrderNumbers'].enable();
122131
}
132+
this.isDisabledStatus = shouldDisable;
123133
}
124134

125135
recalculateSum() {

0 commit comments

Comments
 (0)