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

error message and no save button for generated invoices edit view #500

Merged
merged 1 commit into from
Jul 3, 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
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