Skip to content

Commit

Permalink
Fixed add edit mileage
Browse files Browse the repository at this point in the history
  • Loading branch information
Julias0 committed Mar 4, 2024
1 parent b13046c commit fd76c62
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// TODO: Very hard to fix this file without making massive changes
/* eslint-disable complexity */
import { Component, ElementRef, EventEmitter, HostListener, OnInit, ViewChild } from '@angular/core';
import { ChangeDetectorRef, Component, ElementRef, EventEmitter, HostListener, OnInit, ViewChild } from '@angular/core';
import { AbstractControl, FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar';
import { ActivatedRoute, Router } from '@angular/router';
Expand Down Expand Up @@ -342,7 +342,8 @@ export class AddEditMileagePage implements OnInit {
private platformHandlerService: PlatformHandlerService,
private storageService: StorageService,
private expenseService: ExpensesService,
private employeesService: EmployeesService
private employeesService: EmployeesService,
private changeDetectorRef: ChangeDetectorRef
) {}

get showSaveAndNext(): boolean {
Expand Down Expand Up @@ -1319,14 +1320,15 @@ export class AddEditMileagePage implements OnInit {
console.log(commuteDeductedDistance);
if (commuteDeductedDistance < 0) {
this.previousCommuteDeductionType = null;
this.fg.controls.route.patchValue({ distance: 0 }, { emitEvent: false });
this.fg.controls.route.patchValue({ ...this.fg.controls.route.value, distance: 0 }, { emitEvent: false });
} else {
this.previousCommuteDeductionType = commuteDeductionType;
this.fg.controls.route.patchValue({ distance: 1 }, { emitEvent: false });
this.fg.controls.route.patchValue({ ...this.fg.controls.route.value, distance: 1 }, { emitEvent: false });
console.log(this.fg.value);
console.log(commuteDeductedDistance);
}
}
this.changeDetectorRef.detectChanges();
}

getCommuteDeductionOptions(distance: number): { label: string; value: string; distance: number }[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@angular/forms';
import { ModalController } from '@ionic/angular';
import { intersection, isEqual } from 'lodash';
import { Subscription } from 'rxjs';
import { distinctUntilChanged, Subscription } from 'rxjs';
import { RouteSelectorModalComponent } from './route-selector-modal/route-selector-modal.component';

@Component({
Expand Down Expand Up @@ -181,7 +181,7 @@ export class RouteSelectorComponent implements OnInit, ControlValueAccessor, OnD
}

ngOnInit() {
this.form.controls.roundTrip.valueChanges.subscribe((roundTrip) => {
this.form.controls.roundTrip.valueChanges.pipe(distinctUntilChanged()).subscribe((roundTrip) => {
if (!this.skipRoundTripUpdate) {
if (this.formInitialized) {
if (this.form.value.distance) {
Expand Down

0 comments on commit fd76c62

Please sign in to comment.