import React from 'react'; import { useTranslation } from 'react-i18next'; import { Order } from '../../models/order'; import FormatLib from '../../lib/format'; import { FabButton } from '../base/fab-button'; import { User } from '../../models/user'; import { FabStateLabel } from '../base/fab-state-label'; interface OrderItemProps { order?: Order, currentUser?: User } /** * List item for an order */ export const OrderItem: React.FC = ({ order, currentUser }) => { const { t } = useTranslation('shared'); /** * Go to order page */ const showOrder = (ref: string) => { isPrivileged() ? window.location.href = `/#!/admin/store/o/${ref}` : window.location.href = `/#!/store/o/${ref}`; }; /** * Check if the current operator has administrative rights or is a normal member */ const isPrivileged = (): boolean => { return (currentUser?.role === 'admin' || currentUser?.role === 'manager'); }; /** * Returns a className according to the status */ const statusColor = (status: string) => { switch (status) { case 'error': return 'error'; case 'canceled': return 'canceled'; case 'pending' || 'under_preparation': return 'pending'; default: return 'normal'; } }; return (

order.ref

order.state
{isPrivileged() &&
{t('app.shared.store.order_item.client')}

order.user.name

}

order.created_at

{t('app.shared.store.order_item.total')}

{FormatLib.price(order?.total)}

showOrder('orderRef')} icon={} className="is-black" />
); };