Skip to content

Commit

Permalink
feat: Added Add to report restriction in add edit report section (#2785)
Browse files Browse the repository at this point in the history
* feat: Added Add to report restriction in add edit report section

* test added for variables

* feat: extra optional chaining removed

* feat: optional chaning only added for length and ststus
  • Loading branch information
Suraj Kumar authored Feb 27, 2024
1 parent 680caef commit 377416d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/app/fyle/add-edit-expense/add-edit-expense-5.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,10 @@ export function TestCases5(getTestBed) {
expect(expense).toEqual(expenseData);
});

component.pendingTransactionRestrictionEnabled = true;

expect(component.pendingTransactionAllowedToReportAndSplit).toBeTrue();

expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith('txyeiYbLDSOy');

component.attachments$.subscribe((res) => {
Expand Down Expand Up @@ -1754,6 +1758,7 @@ export function TestCases5(getTestBed) {
});

expect(component.platformExpense$).toBeUndefined();
expect(component.pendingTransactionAllowedToReportAndSplit).toBeTrue();
expect(expensesService.getExpenseById).not.toHaveBeenCalled();

component.attachments$.subscribe((res) => {
Expand Down
20 changes: 11 additions & 9 deletions src/app/fyle/add-edit-expense/add-edit-expense.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -1127,15 +1127,17 @@
<ng-container *ngIf="!(isCriticalPolicyViolated$|async)">
<ng-container *ngIf="canRemoveFromReport || !etxn?.tx?.report_id">
<ng-container *ngIf="reports$|async as reports">
<div class="add-edit-expense--internal-block">
<app-fy-add-to-report
[label]="etxn.tx.report_id ? 'Report' : 'Add to Report'"
[autoSubmissionReportName]="autoSubmissionReportName$|async"
[options]="reports"
[isNewReportsFlowEnabled]="isNewReportsFlowEnabled"
formControlName="report"
></app-fy-add-to-report>
</div>
<ng-container *ngIf="pendingTransactionAllowedToReportAndSplit">
<div class="add-edit-expense--internal-block">
<app-fy-add-to-report
[label]="etxn.tx.report_id ? 'Report' : 'Add to Report'"
[autoSubmissionReportName]="autoSubmissionReportName$|async"
[options]="reports"
[isNewReportsFlowEnabled]="isNewReportsFlowEnabled"
formControlName="report"
></app-fy-add-to-report>
</div>
</ng-container>
</ng-container>
</ng-container>
</ng-container>
Expand Down
15 changes: 15 additions & 0 deletions src/app/fyle/add-edit-expense/add-edit-expense.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ export class AddEditExpensePage implements OnInit {

isRTFEnabled$: Observable<boolean>;

pendingTransactionAllowedToReportAndSplit = true;

//TODO : Assign its value from org settings
pendingTransactionRestrictionEnabled = false;

constructor(
private activatedRoute: ActivatedRoute,
private accountsService: AccountsService,
Expand Down Expand Up @@ -3078,6 +3083,16 @@ export class AddEditExpensePage implements OnInit {
if (this.activatedRoute.snapshot.params.id) {
const id = this.activatedRoute.snapshot.params.id as string;
this.platformExpense$ = this.expensesService.getExpenseById(id);
if (this.pendingTransactionRestrictionEnabled) {
this.platformExpense$.pipe(take(1)).subscribe((transaction) => {
if (
transaction.matched_corporate_card_transactions?.length &&
transaction.matched_corporate_card_transactions[0]?.status === TransactionStatus.PENDING
) {
this.pendingTransactionAllowedToReportAndSplit = false;
}
});
}
}

this.attachments$ = this.loadAttachments$.pipe(
Expand Down

0 comments on commit 377416d

Please sign in to comment.