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

feat: add succeededAt date #1587

Merged
merged 2 commits into from
Jul 9, 2024
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
3 changes: 3 additions & 0 deletions src/components/creditNote/CreditNoteFormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface CreditNoteFormItemProps {
feeName: string
formikKey: string
maxValue: number
feeSucceededAt?: string
}

export const CreditNoteFormItem = ({
Expand All @@ -28,6 +29,7 @@ export const CreditNoteFormItem = ({
formikKey,
maxValue,
feeName,
feeSucceededAt,
}: CreditNoteFormItemProps) => {
const { translate } = useInternationalization()
const error = _get(formikProps.errors, `${formikKey}.value`)
Expand All @@ -41,6 +43,7 @@ export const CreditNoteFormItem = ({
<Typography color="grey700">
{feeName}
<Typography variant="caption">
{feeSucceededAt && `${feeSucceededAt} • `}
{translate('text_636bedf292786b19d3398efc', {
max: intlFormatNumber(deserializeAmount(maxValue || 0, currency), {
currencyDisplay: 'symbol',
Expand Down
1 change: 1 addition & 0 deletions src/components/creditNote/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type FromFee = {
name: string
value: string | number
isTrueUpFee?: boolean
succeededAt?: string
appliedTaxes?: {
id: string
tax: {
Expand Down
18 changes: 14 additions & 4 deletions src/components/invoices/details/InvoiceDetailsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { gql } from '@apollo/client'
import { DateTime } from 'luxon'
import { memo, RefObject } from 'react'
import styled, { css } from 'styled-components'

Expand Down Expand Up @@ -157,9 +158,12 @@ export const InvoiceDetailsTable = memo(
* One-off invoice
******************/
if (
[InvoiceTypeEnum.AddOn, InvoiceTypeEnum.Credit, InvoiceTypeEnum.OneOff].includes(
invoice.invoiceType,
)
[
InvoiceTypeEnum.AddOn,
InvoiceTypeEnum.Credit,
InvoiceTypeEnum.OneOff,
InvoiceTypeEnum.AdvanceCharges,
].includes(invoice.invoiceType)
) {
return (
<InvoiceWrapper $isDraftInvoice={isDraftInvoice} $canHaveUnitPrice={canHaveUnitPrice}>
Expand All @@ -178,10 +182,16 @@ export const InvoiceDetailsTable = memo(
displayName={
invoice.invoiceType === InvoiceTypeEnum.AddOn
? translate('text_6388baa2e514213fed583611', { name: fee.itemName })
: invoice.invoiceType === InvoiceTypeEnum.OneOff
: invoice.invoiceType === InvoiceTypeEnum.OneOff ||
invoice.invoiceType === InvoiceTypeEnum.AdvanceCharges
? fee.invoiceDisplayName || fee.itemName
: translate('text_637ccf8133d2c9a7d11ce6e1')
}
succeededDate={
keellyp marked this conversation as resolved.
Show resolved Hide resolved
invoice.invoiceType === InvoiceTypeEnum.AdvanceCharges
? DateTime.fromISO(fee.succeededAt).toFormat('LLL. dd, yyyy')
: undefined
}
editFeeDrawerRef={editFeeDrawerRef}
deleteAdjustedFeeDialogRef={deleteAdjustedFeeDialogRef}
isDraftInvoice={isDraftInvoice}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ gql`
eventsCount
adjustedFee
adjustedFeeType
succeededAt
charge {
id
chargeModel
Expand Down Expand Up @@ -94,6 +95,7 @@ type InvoiceDetailsTableBodyLineProps = {
hideVat?: boolean
editFeeDrawerRef?: RefObject<EditFeeDrawerRef>
deleteAdjustedFeeDialogRef?: RefObject<DeleteAdjustedFeeDialogRef>
succeededDate?: string
}

export const calculateIfDetailsShouldBeDisplayed = (
Expand Down Expand Up @@ -159,6 +161,7 @@ export const InvoiceDetailsTableBodyLine = memo(
fee,
hideVat,
isDraftInvoice,
succeededDate,
}: InvoiceDetailsTableBodyLineProps) => {
const { translate } = useInternationalization()
const chargeModel = fee?.charge?.chargeModel
Expand Down Expand Up @@ -206,8 +209,10 @@ export const InvoiceDetailsTableBodyLine = memo(
</Typography>
)}
</Stack>
{!!subLabel && (
{(succeededDate || !!subLabel) && (
<Typography variant="caption" color="grey600">
{succeededDate}
{succeededDate && !!subLabel && ' • '}
{subLabel}
</Typography>
)}
Expand Down
40 changes: 25 additions & 15 deletions src/generated/graphql.tsx

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/hooks/__tests__/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ export const fullSubscriptionInvoiceGroupTrueUpMockAndExpect = () => ({
trueUpFee: null,
maxAmount: '167',
appliedTaxes: [],
succeededAt: undefined,
},
'5ff24500-2c67-4872-9808-746c59e94d38': {
name: 'Invoice custom name',
Expand Down Expand Up @@ -587,6 +588,7 @@ export const fullSubscriptionInvoiceGroupTrueUpMockAndExpect = () => ({
trueUpFee: null,
maxAmount: '10666',
appliedTaxes: [],
succeededAt: undefined,
},
'594fe1d1-69f1-4b47-8cae-9c76fd409f76': {
name: 'Count BM - One dimension',
Expand Down Expand Up @@ -620,6 +622,7 @@ export const fullSubscriptionInvoiceGroupTrueUpMockAndExpect = () => ({
trueUpFee: null,
maxAmount: '40000',
appliedTaxes: [],
succeededAt: undefined,
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useCreateCreditNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ gql`
invoiceName
invoiceDisplayName
groupedBy
succeededAt
appliedTaxes {
id
tax {
Expand Down Expand Up @@ -73,6 +74,7 @@ gql`
invoiceName
invoiceDisplayName
creditableAmountCents
succeededAt
appliedTaxes {
id
tax {
Expand Down Expand Up @@ -283,6 +285,7 @@ export const useCreateCreditNote: () => UseCreateCreditNoteReturn = () => {
trueUpFee: fee?.trueUpFee,
maxAmount: fee?.creditableAmountCents,
appliedTaxes: fee?.appliedTaxes || [],
succeededAt: fee?.succeededAt,
},
...groupApp,
}
Expand Down Expand Up @@ -321,6 +324,7 @@ export const useCreateCreditNote: () => UseCreateCreditNoteReturn = () => {
trueUpFee: firstFee?.trueUpFee,
maxAmount: firstFee?.creditableAmountCents,
appliedTaxes: firstFee?.appliedTaxes || [],
succeededAt: firstFee?.succeededAt,
},
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/pages/CreateCreditNote.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { gql } from '@apollo/client'
import { useFormik } from 'formik'
import _get from 'lodash/get'
import { DateTime } from 'luxon'
import { useMemo, useRef, useState } from 'react'
import { generatePath, useNavigate, useParams } from 'react-router-dom'
import styled from 'styled-components'
Expand Down Expand Up @@ -453,6 +454,13 @@ const CreateCreditNote = () => {
}`}
formikKey={`fees.${subKey}.fees.${groupFeeKey}`}
maxValue={child?.maxAmount || 0}
feeSucceededAt={
!!child?.succeededAt
? DateTime.fromISO(child?.succeededAt).toFormat(
'LLL. dd, yyyy',
)
: undefined
}
/>
)
}
Expand Down
Loading