Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: popover confirmation once commute is updated from form #2820

Merged
merged 4 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 54 additions & 51 deletions src/app/fyle/add-edit-mileage/add-edit-mileage.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,59 +152,62 @@
</ng-container>

<ng-container *ngIf="showCommuteDeductionField">
<div
class="add-edit-mileage--internal-block"
[ngClass]="{'add-edit-mileage--internal-block__invalid': fg.controls.commuteDeduction.touched && !fg.controls.commuteDeduction.valid}"
>
<app-fy-select
[enableSearch]="false"
[label]="'Commute Deduction'"
[mandatory]="true"
[nullOption]="false"
[options]="commuteDeductionOptions"
[selectModalHeader]="'Commute Deduction'"
formControlName="commuteDeduction"
[selectionElement]="commuteDeduction"
[touchedInParent]="fg.controls.commuteDeduction.touched"
[validInParent]="fg.controls.commuteDeduction.valid"
>
</app-fy-select>
<ng-template
#commuteDeduction
let-label="label"
let-value="value"
let-distance="distance"
let-selected="selected"
<ng-container *ngIf="txnFields$|async as txnFields">
<div
class="add-edit-mileage--internal-block"
[ngClass]="{'add-edit-mileage--internal-block__invalid': fg.controls.commuteDeduction.touched && !fg.controls.commuteDeduction.valid}"
>
<div>
<div class="add-edit-mileage--commute-deduction">{{label}}</div>
<div *ngIf="distance > 0" class="add-edit-mileage--payment-mode-section">
{{distance.toFixed(2) + ' ' + distanceUnit}}
</div>
<div *ngIf="distance === 0" class="add-edit-mileage--payment-mode-section">
{{distance + ' ' + distanceUnit}}
</div>
<div
*ngIf="distance === null"
class="add-edit-mileage--add-location"
(click)="openCommuteDetailsModal()"
>
<ion-icon
class="add-edit-mileage--add-location--icon"
src="../../../assets/svg/plus-square.svg"
></ion-icon>
Add Location
<app-fy-select
[enableSearch]="false"
[label]="'Commute Deduction'"
[mandatory]="txnFields.commute_deduction?.is_mandatory"
[nullOption]="false"
[options]="commuteDeductionOptions"
[selectModalHeader]="'Commute Deduction'"
formControlName="commuteDeduction"
[selectionElement]="commuteDeduction"
[touchedInParent]="fg.controls.commuteDeduction.touched"
[validInParent]="fg.controls.commuteDeduction.valid"
[placeholder]="txnFields.commute_deduction?.placeholder || 'Select Commute Deduction'"
>
</app-fy-select>
<ng-template
#commuteDeduction
let-label="label"
let-value="value"
let-distance="distance"
let-selected="selected"
>
<div>
<div class="add-edit-mileage--commute-deduction">{{label}}</div>
<div *ngIf="distance > 0" class="add-edit-mileage--payment-mode-section">
{{distance.toFixed(2) + ' ' + distanceUnit}}
</div>
<div *ngIf="distance === 0" class="add-edit-mileage--payment-mode-section">
{{distance + ' ' + distanceUnit}}
</div>
<div
*ngIf="distance === null"
class="add-edit-mileage--add-location"
(click)="openCommuteDetailsModal()"
>
<ion-icon
class="add-edit-mileage--add-location--icon"
src="../../../assets/svg/plus-square.svg"
></ion-icon>
Add Location
</div>
</div>
</div>
<mat-icon *ngIf="selected" class="add-edit-mileage--check"> check </mat-icon>
</ng-template>
</div>
<div
*ngIf="fg.controls.commuteDeduction.touched && !fg.controls.commuteDeduction.valid"
class="add-edit-mileage--error"
>
Select Commute Deduction.
</div>
<mat-icon *ngIf="selected" class="add-edit-mileage--check"> check </mat-icon>
</ng-template>
</div>
<div
*ngIf="fg.controls.commuteDeduction.touched && !fg.controls.commuteDeduction.valid"
class="add-edit-mileage--error"
>
Please select commute deduction.
</div>
</ng-container>
</ng-container>

<ng-container *ngIf="mileageRatesOptions$|async as mileageRatesOptions">
Expand Down
45 changes: 41 additions & 4 deletions src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,15 @@ export class AddEditMileagePage implements OnInit {
}).pipe(
switchMap(({ expenseFieldsMap, mileageCategoriesContainer }) => {
// skipped distance unit, location 1 and location 2 - confirm this these are not used at all
const fields = ['purpose', 'txn_dt', 'cost_center_id', 'project_id', 'distance', 'billable'];
const fields = [
'purpose',
'txn_dt',
'cost_center_id',
'project_id',
'distance',
'billable',
'commute_deduction',
];

return this.expenseFieldsService.filterByOrgCategoryId(
expenseFieldsMap,
Expand Down Expand Up @@ -996,11 +1004,12 @@ export class AddEditMileagePage implements OnInit {
txn_dt: this.fg.controls.dateOfSpend,
project_id: this.fg.controls.project,
billable: this.fg.controls.billable,
commute_deduction: this.fg.controls.commuteDeduction,
};

for (const [key, control] of Object.entries(keyToControlMap)) {
control.clearValidators();
if (key === 'project_id') {
if (key === 'project_id' || key === 'commute_deduction') {
control.updateValueAndValidity({
emitEvent: false,
});
Expand All @@ -1027,11 +1036,13 @@ export class AddEditMileagePage implements OnInit {
? null
: Validators.required
);
} else if (txnFieldKey === 'commute_deduction') {
control.setValidators(orgSettings.commute_deduction_settings.enabled ? Validators.required : null);
} else {
control.setValidators(isConnected ? Validators.required : null);
}
}
if (txnFieldKey === 'project_id') {
if (txnFieldKey === 'project_id' || txnFieldKey === 'commute_deduction') {
control.updateValueAndValidity({
emitEvent: false,
});
Expand Down Expand Up @@ -2319,7 +2330,8 @@ export class AddEditMileagePage implements OnInit {
cost_center_name: formValue.costCenter && formValue.costCenter.name,
cost_center_code: formValue.costCenter && formValue.costCenter.code,
commute_deduction: this.showCommuteDeductionField ? formValue.commuteDeduction : null,
commute_details_id: this.showCommuteDeductionField ? this.commuteDetails?.id : null,
commute_details_id:
this.showCommuteDeductionField && formValue.commuteDeduction ? this.commuteDetails?.id : null,
},
dataUrls: [],
ou: etxn.ou,
Expand Down Expand Up @@ -2936,6 +2948,30 @@ export class AddEditMileagePage implements OnInit {
this.onPageExit$.complete();
}

getCommuteUpdatedTextBody(): string {
return `<div>
<p>Your Commute Details have been successfully added to your Profile
Settings.</p>
<p>You can now easily deduct commute from your Mileage expenses.<p>
</div>`;
}

async showCommuteUpdatedPopover(): Promise<void> {
const sizeLimitExceededPopover = await this.popoverController.create({
component: PopupAlertComponent,
componentProps: {
title: 'Commute Updated',
message: this.getCommuteUpdatedTextBody(),
primaryCta: {
text: 'Proceed',
},
},
cssClass: 'pop-up-in-center',
});

await sizeLimitExceededPopover.present();
}

async openCommuteDetailsModal(): Promise<Subscription> {
const commuteDetailsModal = await this.modalController.create({
component: FySelectCommuteDetailsComponent,
Expand All @@ -2958,6 +2994,7 @@ export class AddEditMileagePage implements OnInit {
this.commuteDeductionOptions = this.mileageService.getCommuteDeductionOptions(this.commuteDetails?.distance);
// If the user has saved the commute details, update the commute deduction field to no deduction
this.fg.patchValue({ commuteDeduction: 'NO_DEDUCTION' });
this.showCommuteUpdatedPopover();
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@
>
</app-fy-alert-info>

<div class="route-selector-modal--internal-block" *ngIf="mileageLocations.controls.length < 3">
<mat-checkbox [disabled]="isAmountDisabled" formControlName="roundTrip">
<div
class="route-selector-modal--internal-block"
*ngIf="mileageLocations.controls.length < 3"
[ngClass]="{ 'route-selector-modal--input-disabled': !distance }"
>
<mat-checkbox [disabled]="!distance" formControlName="roundTrip">
<span class="route-selector-modal--checkbox"> Round Trip </span>
</mat-checkbox>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@
</ng-template>
</div>

<div class="route-selector--internal-block" *ngIf="mileageLocations.controls.length < 3">
<mat-checkbox [disabled]="isAmountDisabled || !form.controls.distance" formControlName="roundTrip">
<div
class="route-selector--internal-block"
*ngIf="mileageLocations.controls.length < 3"
[ngClass]="{ 'route-selector--input-disabled': isRoundTripEnabled }"
>
<mat-checkbox [disabled]="isRoundTripEnabled" formControlName="roundTrip">
<span class="route-selector--checkbox"> Round Trip </span>
</mat-checkbox>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export class RouteSelectorComponent implements OnInit, ControlValueAccessor, OnD
return this.form.controls.mileageLocations as FormArray;
}

get isRoundTripEnabled(): boolean {
return this.isAmountDisabled || !this.form.controls.distance?.value;
}

onTouched = () => {};

ngDoCheck() {
Expand All @@ -95,10 +99,10 @@ export class RouteSelectorComponent implements OnInit, ControlValueAccessor, OnD
this.onChangeSub.unsubscribe();
}

customDistanceValidator(control: AbstractControl) {
customDistanceValidator(control: AbstractControl): { invalidDistance: boolean } {
const passedInDistance = control.value && +control.value;
if (passedInDistance !== null) {
return passedInDistance > 0
return passedInDistance >= 0
? null
: {
invalidDistance: true,
Expand Down
Loading