Skip to content

Commit

Permalink
error message and no save button for generated invoices edit view (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
NC-jsAhonen authored Jul 3, 2024
1 parent 4686acd commit d504085
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
43 changes: 36 additions & 7 deletions src/leases/components/leaseSections/invoice/InvoicePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getInvoicesByLease, getIsEditClicked, getMethods as getInvoiceMethods }
import { getCurrentLease } from "leases/selectors";
import type { Methods as MethodsType } from "types";
import type { Invoice, InvoiceList } from "invoices/types";

type Props = {
formValues: Record<string, any>;
invoice: Invoice | null | undefined;
Expand All @@ -27,6 +28,7 @@ type Props = {
receiveIsEditClicked: (...args: Array<any>) => any;
valid: boolean;
};

type State = {
creditedInvoice: Record<string, any> | null | undefined;
interestInvoiceFor: Record<string, any> | null | undefined;
Expand Down Expand Up @@ -85,13 +87,40 @@ class InvoicePanel extends PureComponent<Props, State> {
creditedInvoice,
interestInvoiceFor
} = this.state;
return <TablePanelContainer innerRef={this.setComponentRef} footer={invoice && !invoice.sap_id && <Authorization allow={isMethodAllowed(invoiceMethods, Methods.PATCH)}>
<Button className={ButtonColors.SECONDARY} onClick={onClose} text='Peruuta' />
<Button className={ButtonColors.SUCCESS} disabled={isEditClicked || !valid} onClick={this.handleSave} text='Tallenna' />
</Authorization>} onClose={onClose} title='Laskun tiedot'>
{isMethodAllowed(invoiceMethods, Methods.PATCH) && (!invoice || !invoice.sap_id) ? <EditInvoiceForm creditedInvoice={creditedInvoice} interestInvoiceFor={interestInvoiceFor} invoice={invoice} initialValues={{ ...invoice
}} onInvoiceLinkClick={onInvoiceLinkClick} relativeTo={this.component} /> : <InvoiceTemplate creditedInvoice={creditedInvoice} interestInvoiceFor={interestInvoiceFor} invoice={invoice} onInvoiceLinkClick={onInvoiceLinkClick} relativeTo={this.component} />}
</TablePanelContainer>;
const automaticallyGenerated = invoice && invoice.generated;

return (
<TablePanelContainer
innerRef={this.setComponentRef}
footer={invoice && !invoice.sap_id &&
<Authorization allow={isMethodAllowed(invoiceMethods, Methods.PATCH)}>
<Button className={ButtonColors.SECONDARY} onClick={onClose} text='Peruuta' />
{automaticallyGenerated
? <p className="invoice-panel__error-text">Automaattisesti luotuja laskuja ei voi muokata.</p>
: <Button className={ButtonColors.SUCCESS} disabled={isEditClicked || !valid} onClick={this.handleSave} text='Tallenna' />
}
</Authorization>}
onClose={onClose}
title='Laskun tiedot'>
{isMethodAllowed(invoiceMethods, Methods.PATCH) && (!invoice || !invoice.sap_id)
? <EditInvoiceForm
creditedInvoice={creditedInvoice}
interestInvoiceFor={interestInvoiceFor}
invoice={invoice}
initialValues={{ ...invoice}}
onInvoiceLinkClick={onInvoiceLinkClick}
relativeTo={this.component}
/>
: <InvoiceTemplate
creditedInvoice={creditedInvoice}
interestInvoiceFor={interestInvoiceFor}
invoice={invoice}
onInvoiceLinkClick={onInvoiceLinkClick}
relativeTo={this.component}
/>
}
</TablePanelContainer>
);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
}
}

&__error-text {
color: $red;
}

&__footer {
position: absolute;
bottom: 0;
Expand Down

0 comments on commit d504085

Please sign in to comment.