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(condo): DOMA-10760 fix ticket invoices update #5547

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Invoice } from '@app/condo/schema'
import { Table as AntdTable } from 'antd'
import get from 'lodash/get'
import isEmpty from 'lodash/isEmpty'
import React, { useCallback, useMemo } from 'react'

import { useIntl } from '@open-condo/next/intl'
Expand Down Expand Up @@ -113,7 +114,7 @@ export const InvoiceRowsTable: React.FC<InvoiceRowsTableProps> = ({ invoice }) =
const ContractPriceMessage = intl.formatMessage({ id: 'pages.condo.marketplace.invoice.form.contractPrice' }).toLowerCase()

const currencyCode = get(invoice, 'currencyCode') || DEFAULT_INVOICE_CURRENCY_CODE
const rows = useMemo(() => get(invoice, 'rows'), [invoice])
const rows = useMemo(() => get(invoice, 'rows') || [], [invoice])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or another solution if you're using get

Suggested change
const rows = useMemo(() => get(invoice, 'rows') || [], [invoice])
const rows = useMemo(() => get(invoice, 'rows', []), [invoice])

const organizationId = get(invoice, 'organization.id') || get(invoice, 'organization')
const skuItems = rows.map(({ sku }) => sku).filter(Boolean)

Expand All @@ -122,7 +123,7 @@ export const InvoiceRowsTable: React.FC<InvoiceRowsTableProps> = ({ invoice }) =
sku_in: skuItems,
organization: { id: organizationId },
},
})
}, { skip: isEmpty(skuItems) || !organizationId })

const orderColumns = useInvoiceRowsTableColumns(currencyCode, marketItems)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ export const UpdateInvoiceForm: React.FC<UpdateInvoiceFormProps> = ({
const handleUpdateInvoice = useCallback(async (values) => {
setSubmitLoading(true)
let valuesFromForm = { ...values }
if (isModalForm) {
valuesFromForm = omit(values, ['clientName', 'clientPhone', 'contact', 'property', 'unitName', 'unitType'])
}
if (!values.payerData) {
valuesFromForm = {
...valuesFromForm,
Expand All @@ -73,6 +70,9 @@ export const UpdateInvoiceForm: React.FC<UpdateInvoiceFormProps> = ({
client: null,
}
}
if (isModalForm) {
valuesFromForm = omit(values, ['clientName', 'clientPhone', 'contact', 'property', 'unitName', 'unitType'])
}

const formattedValues = Invoice.formValuesProcessor(valuesFromForm, intl)
const updatedInvoice = await updateInvoiceAction(formattedValues, invoice)
Expand Down
22 changes: 22 additions & 0 deletions apps/condo/domains/marketplace/queries/Invoice.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,27 @@ query getInvoicesByIds ($ids: [ID!]!) {
) {
id
status
number
paymentType
status
currencyCode
rows {
name
toPay
isMin
count
sku
}
organization {
id
}
createdBy {
id
name
type
}
ticket {
id
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const UpdateTicketForm: React.FC<IUpdateTicketForm> = ({ id }) => {
}

if (!isEmpty(existedInvoices)) {
const notUpdatableFields = ['property', 'unitName', 'unitType', 'contact', 'clientName', 'clientPhone', 'client']
const notUpdatableFields = ['ticket', 'property', 'unitName', 'unitType', 'contact', 'clientName', 'clientPhone', 'client']

for (const existedInvoice of existedInvoices) {
const initialInvoice = invoices.find(invoice => invoice.id === existedInvoice.id)
Expand Down
22 changes: 22 additions & 0 deletions apps/condo/gql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,28 @@ export const GetInvoicesByIdsDocument = gql`
invoices: allInvoices(where: {id_in: $ids}, sortBy: [createdAt_DESC]) {
id
status
number
paymentType
status
currencyCode
rows {
name
toPay
isMin
count
sku
}
organization {
id
}
createdBy {
id
name
type
}
ticket {
id
}
}
}
`
Expand Down
2 changes: 1 addition & 1 deletion apps/condo/gql/operation.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export type GetInvoicesByIdsQueryVariables = Types.Exact<{
}>


export type GetInvoicesByIdsQuery = { __typename?: 'Query', invoices?: Array<{ __typename?: 'Invoice', id: string, status?: Types.InvoiceStatusType | null } | null> | null }
export type GetInvoicesByIdsQuery = { __typename?: 'Query', invoices?: Array<{ __typename?: 'Invoice', id: string, status?: Types.InvoiceStatusType | null, number?: number | null, paymentType?: Types.InvoicePaymentTypeType | null, currencyCode?: string | null, rows: Array<{ __typename?: 'InvoiceRowSchemaField', name: string, toPay: string, isMin: boolean, count: number, sku?: string | null }>, organization?: { __typename?: 'Organization', id: string } | null, createdBy?: { __typename?: 'User', id: string, name?: string | null, type?: Types.UserTypeType | null } | null, ticket?: { __typename?: 'Ticket', id: string } | null } | null> | null }

export type GetMeterReadingExportTasksQueryVariables = Types.Exact<{
where: Types.MeterReadingExportTaskWhereInput
Expand Down
Loading