Skip to content

Commit

Permalink
Enable setting invoice skipping at 0 for both organizations and custo…
Browse files Browse the repository at this point in the history
…mers
  • Loading branch information
stephenlago99 committed Sep 5, 2024
1 parent 599cffe commit 0be62eb
Show file tree
Hide file tree
Showing 6 changed files with 632 additions and 3 deletions.
113 changes: 113 additions & 0 deletions src/components/customers/CustomerSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { gql } from '@apollo/client'
import { useRef } from 'react'
import styled from 'styled-components'

import {
DeleteCustomerFinalizeZeroAmountInvoiceDialog,
DeleteCustomerFinalizeZeroAmountInvoiceDialogRef,
} from '~/components/customers/DeleteCustomerFinalizeZeroAmountInvoiceDialog'
import {
EditCustomerVatRateDialog,
EditCustomerVatRateDialogRef,
Expand All @@ -17,6 +21,10 @@ import {
} from '~/components/designSystem'
import { GenericPlaceholder } from '~/components/GenericPlaceholder'
import { PremiumWarningDialog, PremiumWarningDialogRef } from '~/components/PremiumWarningDialog'
import {
EditFinalizeZeroAmountInvoiceDialog,
EditFinalizeZeroAmountInvoiceDialogRef,
} from '~/components/settings/EditFinalizeZeroAmountInvoiceDialog'
import {
EditNetPaymentTermDialog,
EditNetPaymentTermDialogRef,
Expand All @@ -32,6 +40,7 @@ import {
EditCustomerDocumentLocaleFragmentDoc,
EditCustomerInvoiceGracePeriodFragmentDoc,
EditCustomerVatRateFragmentDoc,
FinalizeZeroAmountInvoiceEnum,
useGetCustomerSettingsQuery,
} from '~/generated/graphql'
import { useInternationalization } from '~/hooks/core/useInternationalization'
Expand Down Expand Up @@ -83,6 +92,8 @@ gql`
id
invoiceGracePeriod
netPaymentTerm
finalizeZeroAmountInvoice
billingConfiguration {
id
documentLocale
Expand All @@ -102,6 +113,7 @@ gql`
organization {
id
netPaymentTerm
finalizeZeroAmountInvoice
billingConfiguration {
id
invoiceGracePeriod
Expand Down Expand Up @@ -143,6 +155,10 @@ export const CustomerSettings = ({ customerId }: CustomerSettingsProps) => {
const editNetPaymentTermDialogRef = useRef<EditNetPaymentTermDialogRef>(null)
const deleteOrganizationNetPaymentTermDialogRef =
useRef<DeleteOrganizationNetPaymentTermDialogRef>(null)
const editFinalizeZeroAmountInvoiceDialogRef =
useRef<EditFinalizeZeroAmountInvoiceDialogRef>(null)
const deleteCustomerFinalizeZeroAmountInvoiceDialogRef =
useRef<DeleteCustomerFinalizeZeroAmountInvoiceDialogRef>(null)

{
!!error && !loading && (
Expand Down Expand Up @@ -332,6 +348,94 @@ export const CustomerSettings = ({ customerId }: CustomerSettingsProps) => {
)}
</InfoBlock>

<InlineSectionTitle>
<Typography variant="subhead" color="grey700">
{translate('text_1725549671287r9tnu5cuoeu')}
</Typography>

{customer?.finalizeZeroAmountInvoice === FinalizeZeroAmountInvoiceEnum.Inherit ? (
<Button
disabled={loading}
variant="quaternary"
onClick={() => editFinalizeZeroAmountInvoiceDialogRef?.current?.openDialog()}
>
{translate('text_1725550089200lfv6ug3vicm')}
</Button>
) : (
<Popper
PopperProps={{ placement: 'bottom-end' }}
opener={<Button disabled={loading} icon="dots-horizontal" variant="quaternary" />}
>
{({ closePopper }) => (
<MenuPopper>
<Button
disabled={loading}
startIcon="pen"
variant="quaternary"
align="left"
onClick={() => {
editFinalizeZeroAmountInvoiceDialogRef?.current?.openDialog()
closePopper()
}}
>
{translate('text_63aa15caab5b16980b21b0b8')}
</Button>
<Button
disabled={loading}
startIcon="trash"
variant="quaternary"
align="left"
onClick={() => {
deleteCustomerFinalizeZeroAmountInvoiceDialogRef?.current?.openDialog()
closePopper()
}}
>
{translate('text_63aa15caab5b16980b21b0ba')}
</Button>
</MenuPopper>
)}
</Popper>
)}
</InlineSectionTitle>

<InfoBlock $hasSeparator $loading={loading}>
{loading ? (
<>
<Skeleton variant="text" width={320} height={12} marginBottom={theme.spacing(4)} />
<Skeleton variant="text" width={160} height={12} />
</>
) : (
<>
<Typography variant="body" color="grey700">
{customer?.finalizeZeroAmountInvoice === FinalizeZeroAmountInvoiceEnum.Inherit ? (
<>
{organization?.finalizeZeroAmountInvoice
? translate('text_17255500892002nq3iltm03z')
: translate('text_1725549671288zkq9sr0y46l')}
{` ${translate('text_17255500892009uqfqttms4w')}`}
</>
) : (
<>
{customer?.finalizeZeroAmountInvoice === FinalizeZeroAmountInvoiceEnum.Finalize
? translate('text_17255500892002nq3iltm03z')
: translate('text_1725549671288zkq9sr0y46l')}
</>
)}
</Typography>

<Typography
variant="caption"
color="grey600"
html={
customer?.finalizeZeroAmountInvoice === FinalizeZeroAmountInvoiceEnum.Inherit
? translate('text_1725550089200omw15t6nh0h', { link: INVOICE_SETTINGS_ROUTE })
: translate('text_1725550089200svn5rdwfftc')
}
/>
</>
)}
</InfoBlock>

<InlineSectionTitle>
<Typography variant="subhead" color="grey700">
{translate('text_638dff9779fb99299bee912e')}
Expand Down Expand Up @@ -546,6 +650,15 @@ export const CustomerSettings = ({ customerId }: CustomerSettingsProps) => {
ref={deleteOrganizationNetPaymentTermDialogRef}
customer={customer}
/>
<EditFinalizeZeroAmountInvoiceDialog
ref={editFinalizeZeroAmountInvoiceDialogRef}
entity={customer}
finalizeZeroAmountInvoice={customer?.finalizeZeroAmountInvoice}
/>
<DeleteCustomerFinalizeZeroAmountInvoiceDialog
ref={deleteCustomerFinalizeZeroAmountInvoiceDialogRef}
customer={customer}
/>
</>
)}
<PremiumWarningDialog ref={premiumWarningDialogRef} />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { gql } from '@apollo/client'
import { forwardRef } from 'react'

import { DialogRef, Typography } from '~/components/designSystem'
import { WarningDialog, WarningDialogRef } from '~/components/WarningDialog'
import { addToast } from '~/core/apolloClient'
import {
DeleteCustomerFinalizeZeroAmountInvoiceFragment,
FinalizeZeroAmountInvoiceEnum,
useDeleteCustomerFinalizeZeroAmountInvoiceMutation,
} from '~/generated/graphql'
import { useInternationalization } from '~/hooks/core/useInternationalization'

gql`
fragment DeleteCustomerFinalizeZeroAmountInvoice on Customer {
id
externalId
name
finalizeZeroAmountInvoice
}
mutation deleteCustomerFinalizeZeroAmountInvoice($input: UpdateCustomerInput!) {
updateCustomer(input: $input) {
id
...DeleteCustomerFinalizeZeroAmountInvoice
}
}
`

export interface DeleteCustomerFinalizeZeroAmountInvoiceDialogRef extends WarningDialogRef {}

interface DeleteCustomerFinalizeZeroAmountInvoiceDialogProps {
customer: DeleteCustomerFinalizeZeroAmountInvoiceFragment
}

export const DeleteCustomerFinalizeZeroAmountInvoiceDialog = forwardRef<
DialogRef,
DeleteCustomerFinalizeZeroAmountInvoiceDialogProps
>(({ customer }: DeleteCustomerFinalizeZeroAmountInvoiceDialogProps, ref) => {
const { translate } = useInternationalization()

const [deleteCustomerFinalizeZeroAmountInvoice] =
useDeleteCustomerFinalizeZeroAmountInvoiceMutation({
onCompleted(data) {
if (data && data.updateCustomer) {
addToast({
message: translate('text_17255496712882bspi9zp0ii'),
severity: 'success',
})
}
},
})

return (
<WarningDialog
ref={ref}
title={translate('text_1725549671288txz7z4m4qrf')}
description={
<Typography
html={translate('text_17255496712882gafqyniqpc', {
customerName: customer?.name,
})}
/>
}
onContinue={async () =>
await deleteCustomerFinalizeZeroAmountInvoice({
variables: {
input: {
id: customer?.id,
externalId: customer?.externalId,
name: customer?.name || '',
finalizeZeroAmountInvoice: FinalizeZeroAmountInvoiceEnum.Inherit,
},
},
})
}
continueText={translate('text_63aa085d28b8510cd46441a5')}
/>
)
})

DeleteCustomerFinalizeZeroAmountInvoiceDialog.displayName =
'DeleteCustomerFinalizeZeroAmountInvoice'
Loading

0 comments on commit 0be62eb

Please sign in to comment.