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

fix: invoice button logic in OrderActionsMenu #871

Merged
merged 1 commit into from
Oct 14, 2024
Merged
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
29 changes: 18 additions & 11 deletions apps/web/src/app/admin/orders/OrderActionsMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use client';

import { InvoiceRequestDto, OrderDto, OrderStatus, PaymentProvider } from '@eventuras/sdk';
import { Button, Definition, DescriptionList, Drawer, Heading, Term } from '@eventuras/ui';
import { Logger } from '@eventuras/utils';
import { useRouter } from 'next/navigation';
import createTranslation from 'next-translate/createTranslation';
import { useState } from 'react';
import React, { useState } from 'react';

import { apiWrapper, createSDK } from '@/utils/api/EventurasApi';
import Environment from '@/utils/Environment';
Expand All @@ -21,6 +20,17 @@ export const OrderActionsMenu = ({ order }: OrderActionsMenuProps) => {
Logger.info({ namespace: 'invoicing:order' }, order);
Logger.info({ namespace: 'invoicing:registration' }, order.registration);

const invoicablePaymentMethods = [
PaymentProvider.POWER_OFFICE_EMAIL_INVOICE,
PaymentProvider.POWER_OFFICE_EHFINVOICE,
];

const isOrderVerified = order.status === OrderStatus.VERIFIED;
const hasInvoicablePaymentMethod =
order.paymentMethod != null && invoicablePaymentMethods.includes(order.paymentMethod);

const shouldShowInvoiceButton = isOrderVerified && hasInvoicablePaymentMethod;

const verifyOrder =
({ order }: { order: OrderDto }) =>
async () => {
Expand Down Expand Up @@ -95,15 +105,12 @@ export const OrderActionsMenu = ({ order }: OrderActionsMenuProps) => {
<Definition>{order.log}</Definition>
</DescriptionList>
</div>
{order.status == OrderStatus.VERIFIED &&
order.paymentMethod ==
(PaymentProvider.POWER_OFFICE_EMAIL_INVOICE ||
PaymentProvider.POWER_OFFICE_EHFINVOICE) && (
<Button onClick={() => invoiceOrder(order)}>
Send to accounting system (
{order.paymentMethod == PaymentProvider.POWER_OFFICE_EMAIL_INVOICE ? 'email' : 'ehf'})
</Button>
)}
{shouldShowInvoiceButton && (
<Button onClick={() => invoiceOrder(order)}>
Send to accounting system (
{order.paymentMethod === PaymentProvider.POWER_OFFICE_EMAIL_INVOICE ? 'email' : 'ehf'})
</Button>
)}
</Drawer>
</>
);
Expand Down
Loading