1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-03 23:52:19 +01:00

74 lines
2.0 KiB
TypeScript
Raw Normal View History

2022-09-01 16:08:37 +02:00
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';
2022-09-07 15:35:46 +02:00
import { User } from '../../models/user';
import { FabStateLabel } from '../base/fab-state-label';
2022-09-01 16:08:37 +02:00
interface OrderItemProps {
2022-09-07 15:35:46 +02:00
order?: Order,
currentUser?: User
2022-09-01 16:08:37 +02:00
}
/**
* List item for an order
*/
2022-09-07 15:35:46 +02:00
export const OrderItem: React.FC<OrderItemProps> = ({ order, currentUser }) => {
const { t } = useTranslation('shared');
2022-09-01 16:08:37 +02:00
/**
* Go to order page
*/
2022-09-07 15:35:46 +02:00
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';
}
2022-09-01 16:08:37 +02:00
};
return (
<div className='order-item'>
2022-09-07 15:35:46 +02:00
<p className="ref">order.ref</p>
<div>
<FabStateLabel status={statusColor('pending')} background>
order.state
</FabStateLabel>
2022-09-01 16:08:37 +02:00
</div>
2022-09-07 15:35:46 +02:00
{isPrivileged() &&
<div className='client'>
<span>{t('app.shared.store.order_item.client')}</span>
<p>order.user.name</p>
</div>
}
2022-09-01 16:08:37 +02:00
<p className="date">order.created_at</p>
<div className='price'>
2022-09-07 15:35:46 +02:00
<span>{t('app.shared.store.order_item.total')}</span>
2022-09-01 16:08:37 +02:00
<p>{FormatLib.price(order?.total)}</p>
</div>
2022-09-07 15:35:46 +02:00
<FabButton onClick={() => showOrder('orderRef')} icon={<i className="fas fa-eye" />} className="is-black" />
2022-09-01 16:08:37 +02:00
</div>
);
};