2022-09-01 16:08:37 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { IApplication } from '../../models/application';
|
2022-09-08 12:04:37 +02:00
|
|
|
import { User } from '../../models/user';
|
2022-09-01 16:08:37 +02:00
|
|
|
import { react2angular } from 'react2angular';
|
|
|
|
import { Loader } from '../base/loader';
|
|
|
|
import noImage from '../../../../images/no_image.png';
|
2022-09-07 15:35:46 +02:00
|
|
|
import { FabStateLabel } from '../base/fab-state-label';
|
2022-09-07 17:14:06 +02:00
|
|
|
import Select from 'react-select';
|
2022-09-01 16:08:37 +02:00
|
|
|
|
|
|
|
declare const Application: IApplication;
|
|
|
|
|
|
|
|
interface ShowOrderProps {
|
|
|
|
orderRef: string,
|
2022-09-08 12:04:37 +02:00
|
|
|
currentUser?: User,
|
2022-09-01 16:08:37 +02:00
|
|
|
onError: (message: string) => void,
|
|
|
|
onSuccess: (message: string) => void
|
|
|
|
}
|
2022-09-07 17:14:06 +02:00
|
|
|
/**
|
|
|
|
* Option format, expected by react-select
|
|
|
|
* @see https://github.com/JedWatson/react-select
|
|
|
|
*/
|
|
|
|
type selectOption = { value: number, label: string };
|
2022-09-01 16:08:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This component shows an order details
|
|
|
|
*/
|
2022-09-07 09:22:16 +02:00
|
|
|
// TODO: delete next eslint disable
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2022-09-08 12:04:37 +02:00
|
|
|
export const ShowOrder: React.FC<ShowOrderProps> = ({ orderRef, currentUser, onError, onSuccess }) => {
|
|
|
|
const { t } = useTranslation('shared');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the current operator has administrative rights or is a normal member
|
|
|
|
*/
|
|
|
|
const isPrivileged = (): boolean => {
|
|
|
|
return (currentUser?.role === 'admin' || currentUser?.role === 'manager');
|
|
|
|
};
|
2022-09-01 16:08:37 +02:00
|
|
|
|
2022-09-07 17:14:06 +02:00
|
|
|
/**
|
|
|
|
* Creates sorting options to the react-select format
|
|
|
|
*/
|
|
|
|
const buildOptions = (): Array<selectOption> => {
|
|
|
|
return [
|
2022-09-08 12:04:37 +02:00
|
|
|
{ value: 0, label: t('app.shared.store.show_order.status.error') },
|
|
|
|
{ value: 1, label: t('app.shared.store.show_order.status.canceled') },
|
|
|
|
{ value: 2, label: t('app.shared.store.show_order.status.pending') },
|
|
|
|
{ value: 3, label: t('app.shared.store.show_order.status.under_preparation') },
|
|
|
|
{ value: 4, label: t('app.shared.store.show_order.status.paid') },
|
|
|
|
{ value: 5, label: t('app.shared.store.show_order.status.ready') },
|
|
|
|
{ value: 6, label: t('app.shared.store.show_order.status.collected') },
|
|
|
|
{ value: 7, label: t('app.shared.store.show_order.status.refunded') }
|
2022-09-07 17:14:06 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback after selecting an action
|
|
|
|
*/
|
|
|
|
const handleAction = (action: selectOption) => {
|
|
|
|
console.log('Action:', action);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Styles the React-select component
|
|
|
|
const customStyles = {
|
|
|
|
control: base => ({
|
|
|
|
...base,
|
|
|
|
width: '20ch',
|
|
|
|
backgroundColor: 'transparent'
|
|
|
|
}),
|
|
|
|
indicatorSeparator: () => ({
|
|
|
|
display: 'none'
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2022-09-01 16:08:37 +02:00
|
|
|
/**
|
|
|
|
* 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 (
|
|
|
|
<div className='show-order'>
|
|
|
|
<header>
|
|
|
|
<h2>[order.ref]</h2>
|
|
|
|
<div className="grpBtn">
|
2022-09-08 12:04:37 +02:00
|
|
|
{isPrivileged() &&
|
|
|
|
<Select
|
|
|
|
options={buildOptions()}
|
|
|
|
onChange={option => handleAction(option)}
|
|
|
|
styles={customStyles}
|
|
|
|
/>
|
|
|
|
}
|
2022-09-01 16:08:37 +02:00
|
|
|
<a href={''}
|
|
|
|
target='_blank'
|
|
|
|
className='fab-button is-black'
|
|
|
|
rel='noreferrer'>
|
2022-09-08 12:04:37 +02:00
|
|
|
{t('app.shared.store.show_order.see_invoice')}
|
2022-09-01 16:08:37 +02:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
|
|
|
|
<div className="client-info">
|
2022-09-08 12:04:37 +02:00
|
|
|
<label>{t('app.shared.store.show_order.tracking')}</label>
|
2022-09-01 16:08:37 +02:00
|
|
|
<div className="content">
|
2022-09-08 12:04:37 +02:00
|
|
|
{isPrivileged() &&
|
|
|
|
<div className='group'>
|
|
|
|
<span>{t('app.shared.store.show_order.client')}</span>
|
|
|
|
<p>order.user.name</p>
|
|
|
|
</div>
|
|
|
|
}
|
2022-09-01 16:08:37 +02:00
|
|
|
<div className='group'>
|
2022-09-08 12:04:37 +02:00
|
|
|
<span>{t('app.shared.store.show_order.created_at')}</span>
|
2022-09-01 16:08:37 +02:00
|
|
|
<p>order.created_at</p>
|
|
|
|
</div>
|
|
|
|
<div className='group'>
|
2022-09-08 12:04:37 +02:00
|
|
|
<span>{t('app.shared.store.show_order.last_update')}</span>
|
2022-09-01 16:08:37 +02:00
|
|
|
<p>order.???</p>
|
|
|
|
</div>
|
2022-09-07 15:35:46 +02:00
|
|
|
<FabStateLabel status={statusColor('error')} background>
|
|
|
|
order.state
|
|
|
|
</FabStateLabel>
|
2022-09-01 16:08:37 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="cart">
|
2022-09-08 12:04:37 +02:00
|
|
|
<label>{t('app.shared.store.show_order.cart')}</label>
|
2022-09-01 16:08:37 +02:00
|
|
|
<div>
|
|
|
|
{/* loop sur les articles du panier */}
|
|
|
|
<article className='store-cart-list-item'>
|
|
|
|
<div className='picture'>
|
|
|
|
<img alt=''src={noImage} />
|
|
|
|
</div>
|
|
|
|
<div className="ref">
|
2022-09-08 12:04:37 +02:00
|
|
|
<span>{t('app.shared.store.show_order.reference_short')} orderable_id?</span>
|
2022-09-01 16:08:37 +02:00
|
|
|
<p>o.orderable_name</p>
|
|
|
|
</div>
|
|
|
|
<div className="actions">
|
|
|
|
<div className='price'>
|
|
|
|
<p>o.amount</p>
|
2022-09-08 12:04:37 +02:00
|
|
|
<span>/ {t('app.shared.store.show_order.unit')}</span>
|
2022-09-01 16:08:37 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<span className="count">o.quantity</span>
|
|
|
|
|
|
|
|
<div className='total'>
|
2022-09-08 12:04:37 +02:00
|
|
|
<span>{t('app.shared.store.show_order.item_total')}</span>
|
2022-09-01 16:08:37 +02:00
|
|
|
<p>o.quantity * o.amount</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</article>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2022-09-07 15:35:46 +02:00
|
|
|
<div className="subgrid">
|
2022-09-01 16:08:37 +02:00
|
|
|
<div className="payment-info">
|
2022-09-08 12:04:37 +02:00
|
|
|
<label>{t('app.shared.store.show_order.payment_informations')}</label>
|
2022-09-01 16:08:37 +02:00
|
|
|
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsum rerum commodi quaerat possimus! Odit, harum.</p>
|
|
|
|
</div>
|
|
|
|
<div className="amount">
|
2022-09-08 12:04:37 +02:00
|
|
|
<label>{t('app.shared.store.show_order.amount')}</label>
|
|
|
|
<p>{t('app.shared.store.show_order.products_total')}<span>order.amount</span></p>
|
|
|
|
<p className='gift'>{t('app.shared.store.show_order.gift_total')}<span>-order.amount</span></p>
|
|
|
|
<p>{t('app.shared.store.show_order.coupon')}<span>order.amount</span></p>
|
|
|
|
<p className='total'>{t('app.shared.store.show_order.cart_total')} <span>order.total</span></p>
|
2022-09-01 16:08:37 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const ShowOrderWrapper: React.FC<ShowOrderProps> = (props) => {
|
|
|
|
return (
|
|
|
|
<Loader>
|
|
|
|
<ShowOrder {...props} />
|
|
|
|
</Loader>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-09-08 12:04:37 +02:00
|
|
|
Application.Components.component('showOrder', react2angular(ShowOrderWrapper, ['orderRef', 'currentUser', 'onError', 'onSuccess']));
|