Skip to content

Commit

Permalink
Merge branch 'develop' into feature/1880-leaving-page
Browse files Browse the repository at this point in the history
  • Loading branch information
Civolilah committed Jan 22, 2025
2 parents 4beef71 + 86a73ed commit a9729c1
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/common/constants/invoice-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ export default {
[InvoiceStatus.Sent]: 'sent',
[InvoiceStatus.Partial]: 'partial',
[InvoiceStatus.Paid]: 'paid',
[InvoiceStatus.Cancelled]: 'cancelled',
[InvoiceStatus.Reversed]: 'reversed',
};
2 changes: 1 addition & 1 deletion src/common/queries/invoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function useInvoiceQuery(params: InvoiceQueryParams) {
request(
'GET',
endpoint(
`/api/v1/invoices/:id?include=client.group_settings${isLockedParam}`,
`/api/v1/invoices/:id?include=payments,client.group_settings${isLockedParam}`,
{
id: params.id,
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export function Combobox<T = any>({

useClickAway(comboboxRef, () => {
setIsOpen(false);
onInputValueChange?.(inputValue);

if (
selectedOption &&
Expand Down Expand Up @@ -340,7 +341,6 @@ export function Combobox<T = any>({
onFocus();
}
}}
onBlur={() => onInputValueChange?.(inputValue)}
placeholder={inputOptions.placeholder}
disabled={readonly}
defaultValue={
Expand Down
14 changes: 8 additions & 6 deletions src/components/forms/InputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ export function InputField(props: Props) {
)}
placeholder={props.placeholder || ''}
onBlur={(event) => {
event.target.value =
event.target.value === '' && props.type === 'number'
? '0'
: event.target.value;
if (!props.changeOverride) {
event.target.value =
event.target.value === '' && props.type === 'number'
? '0'
: event.target.value;

props.onValueChange && props.onValueChange(event.target.value);
props.onChange && props.onChange(event);
props.onValueChange && props.onValueChange(event.target.value);
props.onChange && props.onChange(event);
}
}}
onChange={(event) => {
event.target.value =
Expand Down
13 changes: 9 additions & 4 deletions src/components/forms/MarkdownEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface Props {
onChange: (value: string) => unknown;
label?: string;
disabled?: boolean;
handleOnBlur?: () => void;
handleChangeOnlyOnUserInput?: boolean;
}

export function MarkdownEditor(props: Props) {
Expand Down Expand Up @@ -96,9 +96,14 @@ export function MarkdownEditor(props: Props) {
browser_spellcheck: true,
convert_urls: false,
}}
onEditorChange={handleChange}
onBlur={() => {
props.handleOnBlur?.();
onEditorChange={(currentValue) => {
if (props.handleChangeOnlyOnUserInput) {
if (currentValue !== props.value) {
handleChange(currentValue);
}
} else {
handleChange(currentValue);
}
}}
disabled={props.disabled}
/>
Expand Down
6 changes: 6 additions & 0 deletions src/pages/invoices/common/hooks/useTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @license https://www.elastic.co/licensing/elastic-license
*/

import { InvoiceStatus } from '$app/common/enums/invoice-status';
import { route } from '$app/common/helpers/route';
import { useHasPermission } from '$app/common/hooks/permissions/useHasPermission';
import { useCurrentCompany } from '$app/common/hooks/useCurrentCompany';
Expand Down Expand Up @@ -97,6 +98,11 @@ export function useTabs(params: Params) {
name: t('email_history'),
href: route('/invoices/:id/email_history', { id }),
},
{
name: t('payments'),
href: route('/invoices/:id/payments', { id }),
enabled: invoice?.status_id === InvoiceStatus.Paid,
},
];

return tabs;
Expand Down
1 change: 1 addition & 0 deletions src/pages/invoices/edit/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default function Edit() {
{invoice && (
<div className="flex space-x-20">
<span className="text-sm">{t('status')}</span>

<InvoiceStatusBadge entity={invoice} />
</div>
)}
Expand Down
85 changes: 85 additions & 0 deletions src/pages/invoices/edit/components/Payments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/

import { Paymentable } from '$app/common/interfaces/payment';

import { useOutletContext } from 'react-router-dom';
import { Context } from '../Edit';
import { ClickableElement } from '$app/components/cards/ClickableElement';
import { useDisableNavigation } from '$app/common/hooks/useDisableNavigation';
import { Payment } from '$app/common/interfaces/payment';
import { useTranslation } from 'react-i18next';
import { date } from '$app/common/helpers';
import { PaymentStatus } from '$app/pages/payments/common/components/PaymentStatus';
import { useCurrentCompanyDateFormats } from '$app/common/hooks/useCurrentCompanyDateFormats';
import { useFormatMoney } from '$app/common/hooks/money/useFormatMoney';
import { Card } from '$app/components/cards';

function Payments() {
const [t] = useTranslation();

const context: Context = useOutletContext();
const { invoice } = context;

const formatMoney = useFormatMoney();
const disableNavigation = useDisableNavigation();

const { dateFormat } = useCurrentCompanyDateFormats();

return (
<Card
title={t('payments')}
withScrollableBody
style={{ maxHeight: '42.5rem' }}
>
<div className="divide-y">
{invoice?.payments &&
invoice.payments.map((payment: Payment) =>
payment.paymentables
.filter(
(item) =>
item.invoice_id == invoice?.id && item.archived_at == 0
)
.map((paymentable: Paymentable) => (
<ClickableElement
key={payment.id}
to={`/payments/${payment.id}/edit`}
disableNavigation={disableNavigation('payment', payment)}
>
<div className="flex flex-col space-y-2">
<p className="font-semibold">
{t('payment')} {payment.number}
</p>

<p className="inline-flex items-center space-x-1">
<p>
{formatMoney(
paymentable.amount,
payment.client?.country_id,
payment.client?.settings.currency_id
)}
</p>
<p>&middot;</p>
<p>{date(paymentable.created_at, dateFormat)}</p>
</p>

<div>
<PaymentStatus entity={payment} />
</div>
</div>
</ClickableElement>
))
)}
</div>
</Card>
);
}

export default Payments;
19 changes: 10 additions & 9 deletions src/pages/invoices/email/components/Mailer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,9 @@ export const Mailer = forwardRef<MailerComponent, Props>((props, ref) => {
<InputField
label={t('cc_email')}
value={payloadData.ccEmail}
onValueChange={(value) => {
setPayloadData((current) => ({ ...current, ccEmail: value }));

setTriggerTemplateGeneration(true);
}}
onValueChange={(value) =>
setPayloadData((current) => ({ ...current, ccEmail: value }))
}
errorMessage={errors?.errors.cc_email}
/>
)}
Expand All @@ -246,16 +244,19 @@ export const Mailer = forwardRef<MailerComponent, Props>((props, ref) => {
setTriggerTemplateGeneration(true);
}}
disabled={freePlan() && isHosted()}
changeOverride
errorMessage={errors?.errors.subject}
/>

{(proPlan() || enterprisePlan()) && (
<MarkdownEditor
value={payloadData.body}
onChange={(value) =>
setPayloadData((current) => ({ ...current, body: value }))
}
handleOnBlur={() => setTriggerTemplateGeneration(true)}
onChange={(value) => {
setPayloadData((current) => ({ ...current, body: value }));

setTriggerTemplateGeneration(true);
}}
handleChangeOnlyOnUserInput
/>
)}
</Card>
Expand Down
4 changes: 4 additions & 0 deletions src/pages/invoices/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const EInvoice = lazy(
const Documents = lazy(
() => import('$app/pages/invoices/edit/components/Documents')
);
const Payments = lazy(
() => import('$app/pages/invoices/edit/components/Payments')
);
const Settings = lazy(
() => import('$app/pages/invoices/edit/components/Settings')
);
Expand Down Expand Up @@ -117,6 +120,7 @@ export const invoiceRoutes = (
<Route path="activity" element={<Activities />} />
<Route path="history" element={<History />} />
<Route path="email_history" element={<EmailHistory />} />
<Route path="payments" element={<Payments />} />
</Route>

<Route
Expand Down

0 comments on commit a9729c1

Please sign in to comment.