Skip to content

Commit

Permalink
feat: Invoice amount filter (#1980)
Browse files Browse the repository at this point in the history
* feat(filtersTypes): add amount to invoice filters

* feat(InvocesList): include amount filter

* feat(InvoicesPage): add amountFrom / amountTo to invoices query

* feat(InvoicesPage): format amount filter based on currency

* chore(graphql): generate types

* fix(FiltersUtils): enable user to input decimals

* fix(FiltersItemAmonut): do not show clear button
  • Loading branch information
stephenlago99 authored Jan 15, 2025
1 parent b1bcf7e commit da65408
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const FiltersItemAmount = ({ value = '', setFilterValue }: FiltersItemAmo
}))}
placeholder={translate('text_66ab42d4ece7e6b7078993b1')}
formikProps={formikProps}
disableClearable={true}
/>

{showFrom && (
Expand Down
1 change: 1 addition & 0 deletions src/components/designSystem/Filters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const InvoiceAvailableFilters = [
AvailableFiltersEnum.paymentOverdue,
AvailableFiltersEnum.paymentStatus,
AvailableFiltersEnum.status,
AvailableFiltersEnum.amount,
]

const translationMap: Record<AvailableFiltersEnum, string> = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/designSystem/Filters/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
export const parseAmountValue = (value: string) => {
const [interval, from, to] = value.split(',')

const fromAmount = from ? parseInt(from) : null
const toAmount = to ? parseInt(to) : null
const fromAmount = from ? Number(from) : null
const toAmount = to ? Number(to) : null

switch (interval) {
case AmountFilterInterval.isEqualTo:
Expand Down
1 change: 1 addition & 0 deletions src/components/invoices/InvoicesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const InvoicesList = ({
<QuickFilters type={AvailableQuickFilters.InvoiceStatus} />
<Filters
filters={[
AvailableFiltersEnum.amount,
AvailableFiltersEnum.status,
AvailableFiltersEnum.invoiceType,
AvailableFiltersEnum.paymentStatus,
Expand Down
12 changes: 11 additions & 1 deletion src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2155,6 +2155,8 @@ export enum DataExportFormatTypeEnum {

/** Export Invoices search query and filters input argument */
export type DataExportInvoiceFiltersInput = {
amountFrom?: InputMaybe<Scalars['Int']['input']>;
amountTo?: InputMaybe<Scalars['Int']['input']>;
currency?: InputMaybe<CurrencyEnum>;
customerExternalId?: InputMaybe<Scalars['String']['input']>;
invoiceType?: InputMaybe<Array<InvoiceTypeEnum>>;
Expand Down Expand Up @@ -4899,6 +4901,8 @@ export type QueryInvoicedUsagesArgs = {


export type QueryInvoicesArgs = {
amountFrom?: InputMaybe<Scalars['Int']['input']>;
amountTo?: InputMaybe<Scalars['Int']['input']>;
currency?: InputMaybe<CurrencyEnum>;
customerExternalId?: InputMaybe<Scalars['String']['input']>;
customerId?: InputMaybe<Scalars['ID']['input']>;
Expand Down Expand Up @@ -8695,6 +8699,8 @@ export type GetInvoicesListQueryVariables = Exact<{
paymentStatus?: InputMaybe<Array<InvoicePaymentStatusTypeEnum> | InvoicePaymentStatusTypeEnum>;
searchTerm?: InputMaybe<Scalars['String']['input']>;
status?: InputMaybe<Array<InvoiceStatusTypeEnum> | InvoiceStatusTypeEnum>;
amountFrom?: InputMaybe<Scalars['Int']['input']>;
amountTo?: InputMaybe<Scalars['Int']['input']>;
}>;


Expand Down Expand Up @@ -22961,7 +22967,7 @@ export type GetInvoiceCreditNotesLazyQueryHookResult = ReturnType<typeof useGetI
export type GetInvoiceCreditNotesSuspenseQueryHookResult = ReturnType<typeof useGetInvoiceCreditNotesSuspenseQuery>;
export type GetInvoiceCreditNotesQueryResult = Apollo.QueryResult<GetInvoiceCreditNotesQuery, GetInvoiceCreditNotesQueryVariables>;
export const GetInvoicesListDocument = gql`
query getInvoicesList($currency: CurrencyEnum, $customerExternalId: String, $invoiceType: [InvoiceTypeEnum!], $issuingDateFrom: ISO8601Date, $issuingDateTo: ISO8601Date, $limit: Int, $page: Int, $paymentDisputeLost: Boolean, $paymentOverdue: Boolean, $paymentStatus: [InvoicePaymentStatusTypeEnum!], $searchTerm: String, $status: [InvoiceStatusTypeEnum!]) {
query getInvoicesList($currency: CurrencyEnum, $customerExternalId: String, $invoiceType: [InvoiceTypeEnum!], $issuingDateFrom: ISO8601Date, $issuingDateTo: ISO8601Date, $limit: Int, $page: Int, $paymentDisputeLost: Boolean, $paymentOverdue: Boolean, $paymentStatus: [InvoicePaymentStatusTypeEnum!], $searchTerm: String, $status: [InvoiceStatusTypeEnum!], $amountFrom: Int, $amountTo: Int) {
invoices(
currency: $currency
customerExternalId: $customerExternalId
Expand All @@ -22975,6 +22981,8 @@ export const GetInvoicesListDocument = gql`
paymentStatus: $paymentStatus
searchTerm: $searchTerm
status: $status
amountFrom: $amountFrom
amountTo: $amountTo
) {
metadata {
currentPage
Expand Down Expand Up @@ -23013,6 +23021,8 @@ export const GetInvoicesListDocument = gql`
* paymentStatus: // value for 'paymentStatus'
* searchTerm: // value for 'searchTerm'
* status: // value for 'status'
* amountFrom: // value for 'amountFrom'
* amountTo: // value for 'amountTo'
* },
* });
*/
Expand Down
8 changes: 6 additions & 2 deletions src/pages/InvoicesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ gql`
$paymentStatus: [InvoicePaymentStatusTypeEnum!]
$searchTerm: String
$status: [InvoiceStatusTypeEnum!]
$amountFrom: Int
$amountTo: Int
) {
invoices(
currency: $currency
Expand All @@ -73,6 +75,8 @@ gql`
paymentStatus: $paymentStatus
searchTerm: $searchTerm
status: $status
amountFrom: $amountFrom
amountTo: $amountTo
) {
metadata {
currentPage
Expand Down Expand Up @@ -212,7 +216,7 @@ const InvoicesPage = () => {
nextFetchPolicy: 'network-only',
variables: {
limit: 20,
...filtersForInvoiceQuery,
...formatAmountCurrency(filtersForInvoiceQuery, amountCurrency),
},
})

Expand Down Expand Up @@ -254,7 +258,7 @@ const InvoicesPage = () => {

const onInvoicesExport = async (values: ExportValues<InvoiceExportTypeEnum>) => {
const filters = {
...formatFiltersForInvoiceQuery(searchParams),
...formatAmountCurrency(formatFiltersForInvoiceQuery(searchParams), amountCurrency),
searchTerm: variableInvoices?.searchTerm,
}

Expand Down

0 comments on commit da65408

Please sign in to comment.