Skip to content

Commit

Permalink
fix: handle invoice type credit
Browse files Browse the repository at this point in the history
  • Loading branch information
keellyp committed Jan 28, 2025
1 parent 365bcc6 commit 678ae5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -22209,6 +22209,7 @@ export const GetPayableInvoiceDocument = gql`
totalDueAmountCents
issuingDate
currency
invoiceType
}
}
`;
Expand Down
12 changes: 12 additions & 0 deletions src/pages/CreatePayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { intlFormatDateTime } from '~/core/timezone'
import {
CreatePaymentInput,
CurrencyEnum,
InvoiceTypeEnum,
LagoApiError,
useCreatePaymentMutation,
useGetPayableInvoiceQuery,
Expand Down Expand Up @@ -48,6 +49,7 @@ gql`
totalDueAmountCents
issuingDate
currency
invoiceType
}
}
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -297,6 +308,7 @@ const CreatePayment = () => {
currency={currency}
beforeChangeFormatter={['positiveNumber']}
placeholder="0.00"
disabled={invoice?.invoiceType === InvoiceTypeEnum.Credit}
InputProps={{
startAdornment: currency && (
<InputAdornment position="start">
Expand Down

0 comments on commit 678ae5f

Please sign in to comment.