Skip to content

Commit

Permalink
fix: project category mapping is not working properly (#2556)
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashpatil78 authored Nov 9, 2023
1 parent 6197dfe commit 8e4bacf
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/app/fyle/add-edit-expense/add-edit-expense.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ export class AddEditExpensePage implements OnInit {

_isExpandedView = false;

recentCategoriesOriginal: OrgCategoryListItem[];

constructor(
private activatedRoute: ActivatedRoute,
private accountsService: AccountsService,
Expand Down Expand Up @@ -1663,6 +1665,8 @@ export class AddEditExpensePage implements OnInit {
recentCostCenters,
taxGroups,
}) => {
this.recentCategoriesOriginal = recentCategories;

if (project) {
this.selectedProject$.next(project);
}
Expand Down Expand Up @@ -2476,11 +2480,6 @@ export class AddEditExpensePage implements OnInit {
};
};

const categoryControl = this.fg.value as {
category: {
id: number;
};
};
this.filteredCategories$ = this.etxn$.pipe(
switchMap((etxn) => {
if (etxn.tx.project_id) {
Expand Down Expand Up @@ -2512,13 +2511,27 @@ export class AddEditExpensePage implements OnInit {
shareReplay(1)
);

this.fg.controls.project.valueChanges.subscribe((project: { project_org_category_ids: number[] }) => {
if (project && project.project_org_category_ids.length !== 0) {
this.recentCategories = this.recentCategoriesOriginal.filter((originalCategory) =>
project.project_org_category_ids.includes(originalCategory.value.id)
);
} else {
this.recentCategories = this.recentCategoriesOriginal;
}
});

this.filteredCategories$.subscribe((categories) => {
const formValue = this.fg.value as {
category: {
id: number;
};
};
if (
categoryControl.category &&
categoryControl.category.id &&
formValue.category &&
formValue.category.id &&
!categories.some(
(category: { value: { id: number } }) =>
categoryControl.category && categoryControl.category.id === category.value.id
(category: { value: { id: number } }) => formValue.category && formValue.category.id === category.value.id
)
) {
this.fg.controls.category.reset();
Expand Down

0 comments on commit 8e4bacf

Please sign in to comment.