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: Dismiss Dialog for duplicate expenses #3175

Merged
merged 8 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="dismiss-dialog">
<ion-content>
<ion-grid class="dismiss-dialog--grid">
<ion-row>
<ion-col>
<div class="dismiss-dialog--header">Dismiss duplicate expenses</div>
</ion-col>
</ion-row>
<ion-row>
<ion-col>
<div class="dismiss-dialog--body">Are you sure you want to take this action?</div>
</ion-col>
</ion-row>
<ion-row class="dismiss-dialog--cta-container">
<ion-col size="6">
<div
[ngClass]="{ 'dismiss-dialog--cancel__disabled': dismissCallInProgress }"
class="dismiss-dialog--cancel"
(click)="cancel()"
>
No, go back
</div>
</ion-col>
<ion-col size="6">
<div class="dismiss-dialog--dismiss" (click)="dismiss()" appFormButtonValidation>Yes, Dismiss</div>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@import '../../../../../theme/colors.scss';

.dismiss-dialog {
&--header {
font-size: 16px;
line-height: 20.48px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does 20px work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

color: $black;
font-weight: 500;
}

&--body {
font-size: 14px;
line-height: 18px;
color: $blue-black;
font-weight: 400;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be there by default, check if it's not required

Copy link
Contributor Author

@devendrafyle devendrafyle Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, actually that is for different dialog, for this dismiss dialog we need to add this class styling since the color is different by default and we also want margin-top

margin-top: 16px;
}

&--cta-container {
margin-top: 16px;
}

&--dismiss {
display: flex;
padding: 12px 16px;
justify-content: center;
color: #fff;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the color variable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

align-items: center;
border-radius: 4px;
background: $brand-gradient;
}

&--cancel {
display: flex;
padding: 12px 16px;
justify-content: center;
align-items: center;
color: $blue-black;
&__disabled {
opacity: 0.2;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';

import { DismissDialogComponent } from './dismiss-dialog.component';

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

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [DismissDialogComponent],
imports: [IonicModule.forRoot()],
}).compileComponents();

fixture = TestBed.createComponent(DismissDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Component, Input, OnInit } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { PopoverController } from '@ionic/angular';
import { catchError, finalize, map } from 'rxjs/operators';
import { of } from 'rxjs';

@Component({
selector: 'app-dismiss-dialog',
templateUrl: './dismiss-dialog.component.html',
styleUrls: ['./dismiss-dialog.component.scss'],
})
export class DismissDialogComponent implements OnInit {
// eslint-disable-next-line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have we added this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed this by adding the observable type

@Input() dismissMethod: () => Observable<any>;

dismissCallInProgress: boolean;

constructor(private popoverController: PopoverController) {}

ngOnInit(): void {
this.dismissCallInProgress = false;
}

cancel(): void {
if (!this.dismissCallInProgress) {
this.popoverController.dismiss();
}
}

dismiss(): void {
this.dismissCallInProgress = true;
this.dismissMethod()
.pipe(
map(() => ({ status: 'success' })),
catchError(() =>
of({
status: 'error',
})
),
finalize(() => (this.dismissCallInProgress = false))
)
.subscribe((res) => {
this.popoverController.dismiss(res);
});
}
}
3 changes: 2 additions & 1 deletion src/app/fyle/my-expenses/my-expenses.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { AddTxnToReportDialogComponent } from './add-txn-to-report-dialog/add-tx
import { MatBottomSheetModule } from '@angular/material/bottom-sheet';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { DismissDialogComponent } from '../dashboard/tasks/dismiss-dialog/dismiss-dialog.component';

@NgModule({
imports: [
Expand All @@ -40,6 +41,6 @@ import { MatCheckboxModule } from '@angular/material/checkbox';
SharedModule,
MatCheckboxModule,
],
declarations: [MyExpensesPage, AddTxnToReportDialogComponent],
declarations: [MyExpensesPage, AddTxnToReportDialogComponent, DismissDialogComponent],
})
export class MyExpensesPageModule {}
52 changes: 42 additions & 10 deletions src/app/fyle/potential-duplicates/potential-duplicates.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { SnackbarPropertiesService } from 'src/app/core/services/snackbar-proper
import { TrackingService } from 'src/app/core/services/tracking.service';
import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service';
import { ToastMessageComponent } from 'src/app/shared/components/toast-message/toast-message.component';
import { DismissDialogComponent } from '../dashboard/tasks/dismiss-dialog/dismiss-dialog.component';
import { PopoverController } from '@ionic/angular';
import { OverlayResponse } from 'src/app/core/models/overlay-response.modal';

// eslint-disable-next-line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint throwing error here, else need to create new modal for it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed this by creating new type in model file

type Expenses = Expense[];

@Component({
Expand All @@ -34,7 +38,8 @@ export class PotentialDuplicatesPage {
private router: Router,
private snackbarProperties: SnackbarPropertiesService,
private matSnackBar: MatSnackBar,
private trackingService: TrackingService
private trackingService: TrackingService,
private popoverController: PopoverController
) {}

ionViewWillEnter(): void {
Expand Down Expand Up @@ -106,11 +111,24 @@ export class PotentialDuplicatesPage {
return this.expensesService.dismissDuplicates(duplicateExpenseIds, targetExpenseIds);
}

dismiss(expense: Expense): void {
const transactionIds = [expense.id];
const duplicateTxnIds = this.duplicateSetData[this.selectedSet];
async dismiss(expense: Expense): Promise<void> {
const targetExpenseIds = [expense.id];
const duplicateExpenseIds = this.duplicateSetData[this.selectedSet];

const popover = await this.popoverController.create({
component: DismissDialogComponent,
cssClass: 'dismiss-dialog',
backdropDismiss: false,
componentProps: {
dismissMethod: () => this.dismissDuplicates(duplicateExpenseIds, targetExpenseIds),
},
});

await popover.present();

const popoverResponse = (await popover.onDidDismiss()) as OverlayResponse<{ status: string }>;

this.dismissDuplicates(duplicateTxnIds, transactionIds).subscribe(() => {
if (popoverResponse.data?.status === 'success') {
this.trackingService.dismissedIndividualExpenses();
this.showDismissedSuccessToast();
this.duplicateSetData[this.selectedSet] = this.duplicateSetData[this.selectedSet].filter(
Expand All @@ -119,12 +137,26 @@ export class PotentialDuplicatesPage {
this.duplicateExpenses[this.selectedSet] = this.duplicateExpenses[this.selectedSet].filter(
(exp) => exp.id !== expense.id
);
});
}
}

dismissAll(): void {
const txnIds = this.duplicateSetData[this.selectedSet];
this.dismissDuplicates(txnIds, txnIds).subscribe(() => {
async dismissAll(): Promise<void> {
const expenseIds = this.duplicateSetData[this.selectedSet];

const popover = await this.popoverController.create({
component: DismissDialogComponent,
cssClass: 'dismiss-dialog',
backdropDismiss: false,
componentProps: {
dismissMethod: () => this.dismissDuplicates(expenseIds, expenseIds),
},
});

await popover.present();

const popoverResponse = (await popover.onDidDismiss()) as OverlayResponse<{ status: string }>;

if (popoverResponse.data?.status === 'success') {
if (this.selectedSet !== 0) {
this.selectedSet--;
}
Expand All @@ -134,7 +166,7 @@ export class PotentialDuplicatesPage {
this.duplicateSets$.subscribe((duplicateExpenses) => {
this.duplicateExpenses = duplicateExpenses;
});
});
}
}

mergeExpense(): void {
Expand Down
11 changes: 11 additions & 0 deletions src/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,17 @@ ion-modal.flag-unflag-modal {
padding-top: 0 !important;
}

ion-popover.dismiss-dialog {
--width: 298px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check this in different resolutions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have checked this, seems to working fine


&::part(content) {
border-radius: 8px;
padding: 24px;
}

background: rgba(0, 0, 0, 0.6);
}

ion-popover.delete-dialog {
--width: 296px;
--max-height: 346px;
Expand Down
1 change: 1 addition & 0 deletions src/theme/colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ $shadow-lg: rgba(44, 48, 78, 0.1);

$brand-primary: #ff3366 !default;
$brand-primary-light: #fe5196 !default;
$brand-gradient: linear-gradient(162deg, #f36 3.01%, #fe5196 111.5%);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not required, we already have $pink-gradient

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh right, will fix this


$pink: #fe4c8e !default;

Expand Down
Loading