Skip to content

Commit

Permalink
fixing custom date filter (#2675)
Browse files Browse the repository at this point in the history
Co-authored-by: Jay Budhadev <[email protected]>
  • Loading branch information
2 people authored and Jay Budhadev committed Jan 17, 2024
1 parent ae555df commit 41b41db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
10 changes: 4 additions & 6 deletions src/app/fyle/my-expenses-v2/my-expenses.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Injectable } from '@angular/core';
import { cloneDeep } from 'lodash';
import * as dayjs from 'dayjs';
import { FilterPill } from 'src/app/shared/components/fy-filter-pills/filter-pill.interface';
import { DateFilters } from 'src/app/shared/components/fy-filters/date-filters.enum';
Expand Down Expand Up @@ -167,31 +166,30 @@ export class MyExpensesService {
}

generateCustomDatePill(filter: Partial<ExpenseFilters>, filterPills: FilterPill[]): FilterPill[] {
const filterPillsCopy = cloneDeep(filterPills);
const startDate = filter.customDateStart && dayjs(filter.customDateStart).format('YYYY-MM-D');
const endDate = filter.customDateEnd && dayjs(filter.customDateEnd).format('YYYY-MM-D');

if (startDate && endDate) {
filterPillsCopy.push({
filterPills.push({
label: 'Date',
type: 'date',
value: `${startDate} to ${endDate}`,
});
} else if (startDate) {
filterPillsCopy.push({
filterPills.push({
label: 'Date',
type: 'date',
value: `>= ${startDate}`,
});
} else if (endDate) {
filterPillsCopy.push({
filterPills.push({
label: 'Date',
type: 'date',
value: `<= ${endDate}`,
});
}

return filterPillsCopy;
return filterPills;
}

generateReceiptsAttachedFilterPills(filterPills: FilterPill[], filter: Partial<ExpenseFilters>): void {
Expand Down
23 changes: 10 additions & 13 deletions src/app/fyle/my-expenses/my-expenses.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Injectable } from '@angular/core';
import { cloneDeep } from 'lodash';
import * as dayjs from 'dayjs';
import { FilterPill } from 'src/app/shared/components/fy-filter-pills/filter-pill.interface';
import { DateFilters } from 'src/app/shared/components/fy-filters/date-filters.enum';
Expand Down Expand Up @@ -123,72 +122,70 @@ export class MyExpensesService {
}

generateDateFilterPills(filter: Partial<ExpenseFilters>, filterPills: FilterPill[]): FilterPill[] {
let filterPillsCopy = cloneDeep(filterPills);
if (filter.date === DateFilters.thisWeek) {
filterPillsCopy.push({
filterPills.push({
label: 'Date',
type: 'date',
value: 'this Week',
});
}

if (filter.date === DateFilters.thisMonth) {
filterPillsCopy.push({
filterPills.push({
label: 'Date',
type: 'date',
value: 'this Month',
});
}

if (filter.date === DateFilters.all) {
filterPillsCopy.push({
filterPills.push({
label: 'Date',
type: 'date',
value: 'All',
});
}

if (filter.date === DateFilters.lastMonth) {
filterPillsCopy.push({
filterPills.push({
label: 'Date',
type: 'date',
value: 'Last Month',
});
}

if (filter.date === DateFilters.custom) {
filterPillsCopy = this.generateCustomDatePill(filter, filterPillsCopy);
filterPills = this.generateCustomDatePill(filter, filterPills);
}

return filterPillsCopy;
return filterPills;
}

generateCustomDatePill(filter: Partial<ExpenseFilters>, filterPills: FilterPill[]): FilterPill[] {
const filterPillsCopy = cloneDeep(filterPills);
const startDate = filter.customDateStart && dayjs(filter.customDateStart).format('YYYY-MM-D');
const endDate = filter.customDateEnd && dayjs(filter.customDateEnd).format('YYYY-MM-D');

if (startDate && endDate) {
filterPillsCopy.push({
filterPills.push({
label: 'Date',
type: 'date',
value: `${startDate} to ${endDate}`,
});
} else if (startDate) {
filterPillsCopy.push({
filterPills.push({
label: 'Date',
type: 'date',
value: `>= ${startDate}`,
});
} else if (endDate) {
filterPillsCopy.push({
filterPills.push({
label: 'Date',
type: 'date',
value: `<= ${endDate}`,
});
}

return filterPillsCopy;
return filterPills;
}

generateReceiptsAttachedFilterPills(filterPills: FilterPill[], filter: Partial<ExpenseFilters>): void {
Expand Down

0 comments on commit 41b41db

Please sign in to comment.