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

fix(InvoicesPage): Fix export while having a issuing date filter enabled #1984

Merged
merged 1 commit into from
Jan 10, 2025
Merged
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
58 changes: 28 additions & 30 deletions src/components/designSystem/Filters/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,23 @@ export const FILTER_VALUE_MAP: Partial<Record<AvailableFiltersEnum, Function>> =
[AvailableFiltersEnum.creditNoteCreditStatus]: (value: string) => (value as string).split(','),
}

export const formatFiltersForCreditNotesQuery = (searchParams: URLSearchParams) => {
const formatFiltersForQuery = ({
searchParams,
keyMap,
availableFilters,
}: {
searchParams: URLSearchParams
keyMap?: Record<string, string>
availableFilters: AvailableFiltersEnum[]
}) => {
const filtersSetInUrl = Object.fromEntries(searchParams.entries())

const keyMap: Partial<Record<AvailableFiltersEnum, string>> = {
[AvailableFiltersEnum.creditNoteReason]: 'reason',
[AvailableFiltersEnum.creditNoteCreditStatus]: 'creditStatus',
[AvailableFiltersEnum.creditNoteRefundStatus]: 'refundStatus',
}

return Object.entries(filtersSetInUrl).reduce(
(acc, cur) => {
const current = cur as [AvailableFiltersEnum, string | string[] | boolean]
const key = current[0]

if (!CreditNoteAvailableFilters.includes(key)) {
if (!availableFilters.includes(key)) {
return acc
}

Expand All @@ -95,36 +97,32 @@ export const formatFiltersForCreditNotesQuery = (searchParams: URLSearchParams)

return {
...acc,
[keyMap[key] || key]: value,
[keyMap?.[key] || key]: value,
}
},
{} as Record<string, string | string[] | boolean>,
)
}

export const formatFiltersForInvoiceQuery = (searchParams: URLSearchParams) => {
const filtersSetInUrl = Object.fromEntries(searchParams.entries())

return Object.entries(filtersSetInUrl).reduce(
(acc, cur) => {
const current = cur as [AvailableFiltersEnum, string | string[] | boolean]
const key = current[0]

if (!InvoiceAvailableFilters.includes(key)) {
return acc
}

const filterFunction = FILTER_VALUE_MAP[key]
export const formatFiltersForCreditNotesQuery = (searchParams: URLSearchParams) => {
const keyMap: Partial<Record<AvailableFiltersEnum, string>> = {
[AvailableFiltersEnum.creditNoteReason]: 'reason',
[AvailableFiltersEnum.creditNoteCreditStatus]: 'creditStatus',
[AvailableFiltersEnum.creditNoteRefundStatus]: 'refundStatus',
}

const value = filterFunction ? filterFunction(current[1]) : current[1]
return formatFiltersForQuery({
searchParams,
keyMap,
availableFilters: CreditNoteAvailableFilters,
})
}

return {
...acc,
[key]: value,
}
},
{} as Record<string, string | string[] | boolean>,
)
export const formatFiltersForInvoiceQuery = (searchParams: URLSearchParams) => {
return formatFiltersForQuery({
searchParams,
availableFilters: InvoiceAvailableFilters,
})
}

export const AMOUNT_INTERVALS_TRANSLATION_MAP = {
Expand Down
Loading