From 678ae5f96f5a3b31f08e9e750a32a9e67d7ac349 Mon Sep 17 00:00:00 2001 From: Kelly Phan Date: Tue, 28 Jan 2025 10:58:44 +0100 Subject: [PATCH] fix: handle invoice type credit --- src/generated/graphql.tsx | 3 ++- src/pages/CreatePayment.tsx | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/generated/graphql.tsx b/src/generated/graphql.tsx index 020c3f4a4..40de22681 100644 --- a/src/generated/graphql.tsx +++ b/src/generated/graphql.tsx @@ -8634,7 +8634,7 @@ export type GetPayableInvoiceQueryVariables = Exact<{ }>; -export type GetPayableInvoiceQuery = { __typename?: 'Query', invoice?: { __typename?: 'Invoice', id: string, number: string, paymentStatus: InvoicePaymentStatusTypeEnum, status: InvoiceStatusTypeEnum, totalDueAmountCents: any, issuingDate: any, currency?: CurrencyEnum | null } | null }; +export type GetPayableInvoiceQuery = { __typename?: 'Query', invoice?: { __typename?: 'Invoice', id: string, number: string, paymentStatus: InvoicePaymentStatusTypeEnum, status: InvoiceStatusTypeEnum, totalDueAmountCents: any, issuingDate: any, currency?: CurrencyEnum | null, invoiceType: InvoiceTypeEnum } | null }; export type CreatePaymentMutationVariables = Exact<{ input: CreatePaymentInput; @@ -22209,6 +22209,7 @@ export const GetPayableInvoiceDocument = gql` totalDueAmountCents issuingDate currency + invoiceType } } `; diff --git a/src/pages/CreatePayment.tsx b/src/pages/CreatePayment.tsx index fe81fcd4a..c6f64a7f9 100644 --- a/src/pages/CreatePayment.tsx +++ b/src/pages/CreatePayment.tsx @@ -18,6 +18,7 @@ import { intlFormatDateTime } from '~/core/timezone' import { CreatePaymentInput, CurrencyEnum, + InvoiceTypeEnum, LagoApiError, useCreatePaymentMutation, useGetPayableInvoiceQuery, @@ -48,6 +49,7 @@ gql` totalDueAmountCents issuingDate currency + invoiceType } } @@ -104,6 +106,15 @@ const CreatePayment = () => { skip: !formikProps.values.invoiceId, }) + useEffect(() => { + if (invoice && invoice.invoiceType === InvoiceTypeEnum.Credit) { + formikProps.setFieldValue( + 'amountCents', + deserializeAmount(invoice.totalDueAmountCents, invoice.currency ?? CurrencyEnum.Usd), + ) + } + }, [invoice]) + const currency = invoice?.currency ?? CurrencyEnum.Usd const [createPayment, { error: createError }] = useCreatePaymentMutation({ @@ -297,6 +308,7 @@ const CreatePayment = () => { currency={currency} beforeChangeFormatter={['positiveNumber']} placeholder="0.00" + disabled={invoice?.invoiceType === InvoiceTypeEnum.Credit} InputProps={{ startAdornment: currency && (