Commit 93ae5f79 authored by Alish's avatar Alish
Browse files

feat: improved redirects and complete cancel order #1030

parent 43b04e89
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
<div class="money-amount-container" *ngIf="!selectedOrder?.isPaid">
<div
	class="money-amount-container"
	*ngIf="!selectedOrder?.isPaid && !selectedOrder?. isCancelled"
>
	<div class="money-amount">
		{{ 'DELIVERY_VIEW.THE_CUSTOMER_HAS_TO_PAY' | translate }} ${{
		selectedOrder?.totalPrice }}!
	</div>
</div>

<div class="already-paid-container" *ngIf="selectedOrder?.isPaid">
<div
	class="already-paid-container"
	*ngIf="selectedOrder?.isPaid && !selectedOrder?. isCancelled"
>
	<div class="already-paid">
		{{ 'DELIVERY_VIEW.CUSTOMER_ALREADY_PAID_WITH_CARD' | translate }}
	</div>
@@ -24,6 +30,7 @@
	<div class="buttons">
		<div class="button-bar">
			<button
				*ngIf="!selectedOrder?.isCancelled"
				[disabled]="disabledButtons"
				class="button button-brand"
				(click)="delivered()"
@@ -36,7 +43,12 @@
				class="button button-assertive"
				(click)="cancel()"
			>
				{{ 'DELIVERY_VIEW.CANCEL' | translate }}
				<span *ngIf="!selectedOrder?.isCancelled"
					>{{ 'DELIVERY_VIEW.CANCEL' | translate }}</span
				>
				<span *ngIf="selectedOrder?.isCancelled"
					>{{ 'OK' | translate }}</span
				>
			</button>
		</div>
	</div>
+62 −57
Original line number Diff line number Diff line
import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { Component, ViewChild, AfterViewInit, OnDestroy } from '@angular/core';
import IOrder from '@modules/server.common/interfaces/IOrder';
import { OrderRouter } from '@modules/client.common.angular2/routers/order-router.service';
import OrderCarrierStatus from '@modules/server.common/enums/OrderCarrierStatus';
@@ -9,9 +9,10 @@ import IGeoLocation from '@modules/server.common/interfaces/IGeoLocation';
import GeoLocation from '@modules/server.common/entities/GeoLocation';
import { GeoLocationService } from '../../../services/geo-location.service';
import { MapComponent } from '../common/map/map.component';
import { Router } from '@angular/router';
import { Store } from 'services/store.service';
import { first } from 'rxjs/operators';
import { first, takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
import { NavController } from '@ionic/angular';

declare var google: any;

@@ -19,7 +20,7 @@ declare var google: any;
	selector: 'page-delivery',
	templateUrl: 'delivery.html'
})
export class DeliveryPage implements AfterViewInit {
export class DeliveryPage implements AfterViewInit, OnDestroy {
	@ViewChild('map', { static: false })
	carrierMap: MapComponent;

@@ -27,6 +28,8 @@ export class DeliveryPage implements AfterViewInit {
	carrierUserDistance: string;
	disabledButtons: boolean = true;

	private destroy$ = new Subject<void>();

	get fullAddress() {
		return this.selectedOrder.user.fullAddress;
	}
@@ -36,16 +39,14 @@ export class DeliveryPage implements AfterViewInit {
		private mixpanel: Mixpanel,
		private geoLocationService: GeoLocationService,
		private geolocation: Geolocation,
		private router: Router,
		private navCtrl: NavController,
		private store: Store
	) {}

	async delivered() {
		this.disabledButtons = true;
		if (this.selectedOrder) {
			this.router.navigateByUrl('/main/home', {
				skipLocationChange: false
			});
			this.navCtrl.navigateRoot('/main/home');

			this.unselectOrder();

@@ -64,9 +65,7 @@ export class DeliveryPage implements AfterViewInit {
	cancel() {
		this.disabledButtons = true;
		this.store.driveToWarehouseFrom = 'delivery';
		this.router.navigateByUrl('/main/drive-to-warehouse', {
			skipLocationChange: false
		});
		this.navCtrl.navigateRoot('/main/drive-to-warehouse');
	}

	ngAfterViewInit(): void {
@@ -79,14 +78,14 @@ export class DeliveryPage implements AfterViewInit {

	private unselectOrder() {
		localStorage.removeItem('orderId');
		this.store.selectedOrder = null;
	}

	private async loadData() {
		const order = await this.orderRouter
	private loadData() {
		this.orderRouter
			.get(localStorage.getItem('orderId'), { populateWarehouse: true })
			.pipe(first())
			.toPromise();

			.pipe(takeUntil(this.destroy$))
			.subscribe(async (order) => {
				this.selectedOrder = order;
				this.store.selectedOrder = order;
				// const carrier = await this.carrierRouter
@@ -128,5 +127,11 @@ export class DeliveryPage implements AfterViewInit {
				this.carrierMap.setCenter(origin);
				this.carrierMap.drawRoute(origin, destination);
				this.disabledButtons = false;
			});
	}

	ngOnDestroy(): void {
		this.destroy$.next();
		this.destroy$.complete();
	}
}
+10 −8
Original line number Diff line number Diff line
@@ -18,24 +18,26 @@
				{{ 'DRIVE_TO_WAREHOUSE_VIEW.SKIP_WORK' | translate }}
			</button>
		</div>
		<div class="button-bar" *ngIf="workTaken">
			<button
				*ngIf="!selectedOrder?.isCancelled || store.driveToWarehouseFrom === 'delivery'"
				class="button button-brand"
				(click)="carrierInWarehouse()"
		<div
			class="button-bar"
			*ngIf="workTaken && (!selectedOrder?.isCancelled || fromDelivery)"
		>
			<button class="button button-brand" (click)="carrierInWarehouse()">
				{{ "DRIVE_TO_WAREHOUSE_VIEW.I'M_THERE" | translate }}
			</button>

			<button
				class="button button-assertive"
				*ngIf="store.driveToWarehouseFrom !== 'delivery'"
				*ngIf="!selectedOrder.isCancelled"
				(click)="cancelWork()"
			>
				{{ 'DRIVE_TO_WAREHOUSE_VIEW.CANCEL' | translate }}
			</button>
		</div>
		<div class="button-bar" *ngIf="selectedOrder?.isCancelled">
		<div
			class="button-bar"
			*ngIf="selectedOrder?.isCancelled && !fromDelivery"
		>
			<button class="button button-assertive" (click)="unselectOrder()">
				{{ 'OK' | translate }}
			</button>
+15 −20
Original line number Diff line number Diff line
import { Component, ViewChild } from '@angular/core';
import { Component, ViewChild, OnInit } from '@angular/core';

import IOrder from '@modules/server.common/interfaces/IOrder';
import { OrderRouter } from '@modules/client.common.angular2/routers/order-router.service';
@@ -13,7 +13,7 @@ import { Geolocation } from '@ionic-native/geolocation/ngx';
import IGeoLocation from '@modules/server.common/interfaces/IGeoLocation';
import { GeoLocationService } from '../../../services/geo-location.service';
import { MapComponent } from '../common/map/map.component';
import { Router } from '@angular/router';
import { NavController } from '@ionic/angular';

declare var google: any;

@@ -21,7 +21,7 @@ declare var google: any;
	selector: 'page-drive-to-warehouse',
	templateUrl: 'drive-to-warehouse.html'
})
export class DriveToWarehousePage {
export class DriveToWarehousePage implements OnInit {
	@ViewChild('map', { static: false })
	carrierMap: MapComponent;

@@ -29,6 +29,7 @@ export class DriveToWarehousePage {
	carrier: ICarrier;
	carrierUserDistance: string;
	workTaken: boolean;
	fromDelivery: boolean;

	carrier$;
	order$;
@@ -40,9 +41,13 @@ export class DriveToWarehousePage {
		public store: Store,
		private geoLocationService: GeoLocationService,
		private geolocation: Geolocation,
		private router: Router
		private navCtrl: NavController
	) {}

	ngOnInit(): void {
		this.fromDelivery = this.store.driveToWarehouseFrom === 'delivery';
	}

	ionViewWillEnter() {
		this.carrier$ = this.carrierRouter
			.get(this.store.carrierId)
@@ -128,16 +133,11 @@ export class DriveToWarehousePage {
	}

	async carrierInWarehouse() {
		if (this.store.driveToWarehouseFrom === 'delivery') {
		if (this.fromDelivery) {
			this.store.returnProductFrom = 'driveToWarehouse';

			this.router.navigate(['/product/return'], {
				skipLocationChange: false
			});
			this.navCtrl.navigateRoot('/product/return');
		} else {
			this.router.navigateByUrl('/product/get', {
				skipLocationChange: false
			});
			this.navCtrl.navigateRoot('/product/get');
		}

		this.unselectDriveToWarehouseFrom();
@@ -145,11 +145,9 @@ export class DriveToWarehousePage {
	}

	async cancelWork() {
		if (this.store.driveToWarehouseFrom === 'delivery') {
		if (this.fromDelivery) {
			this.unselectDriveToWarehouseFrom();
			this.router.navigateByUrl('/main/delivery', {
				skipLocationChange: true
			});
			this.navCtrl.navigateRoot('/main/delivery');
		} else {
			if (this.carrier && this.selectedOrder) {
				await this.carrierOrdersRouter.cancelDelivery(
@@ -169,10 +167,7 @@ export class DriveToWarehousePage {
	unselectOrder() {
		this.store.selectedOrder = null;
		localStorage.removeItem('orderId');

		this.router.navigateByUrl('/main/home', {
			skipLocationChange: false
		});
		this.navCtrl.navigateRoot('/main/home');
	}

	private unsubscribeAll() {
+5 −5
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ import IGeoLocation from '@modules/server.common/interfaces/IGeoLocation';
import { Geolocation } from '@ionic-native/geolocation/ngx';
import { GeoLocationService } from '../../../services/geo-location.service';
import { MapComponent } from '../common/map/map.component';
import { Router } from '@angular/router';
import { NavController } from '@ionic/angular';

declare var google: any;

@@ -39,7 +39,7 @@ export class HomePage {
		private geoLocationOrdersService: GeoLocationOrdersService,
		private geolocation: Geolocation,
		private geoLocationService: GeoLocationService,
		private router: Router
		private navCtrl: NavController
	) {}

	ionViewWillEnter() {
@@ -70,6 +70,7 @@ export class HomePage {

		this.isWorking = res.status === CarrierStatus.Online;
		localStorage.removeItem('orderId');
		this.store.selectedOrder = null;
	}

	notification() {
@@ -139,9 +140,8 @@ export class HomePage {

								this.unsubscribeAll();

								this.router.navigateByUrl(
									'/main/drive-to-warehouse',
									{ skipLocationChange: false }
								this.navCtrl.navigateRoot(
									'/main/drive-to-warehouse'
								);
							}
						});
Loading