import React from 'react'; import { useTranslation } from 'react-i18next'; import { IApplication } from '../../models/application'; import { User } from '../../models/user'; import { react2angular } from 'react2angular'; import { Loader } from '../base/loader'; import noImage from '../../../../images/no_image.png'; import { FabStateLabel } from '../base/fab-state-label'; import Select from 'react-select'; declare const Application: IApplication; interface ShowOrderProps { orderRef: string, currentUser?: User, onError: (message: string) => void, onSuccess: (message: string) => void } /** * Option format, expected by react-select * @see https://github.com/JedWatson/react-select */ type selectOption = { value: number, label: string }; /** * This component shows an order details */ // TODO: delete next eslint disable // eslint-disable-next-line @typescript-eslint/no-unused-vars export const ShowOrder: React.FC = ({ 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'); }; /** * Creates sorting options to the react-select format */ const buildOptions = (): Array => { return [ { 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') } ]; }; /** * 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' }) }; /** * 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]

{isPrivileged() &&