import ButtonKDS from '../Buttons/ButtonKDS'; import { getElements } from '../utils/helperFunctions'; import { ButtonsContainerProps } from '../utils/types'; import { ButtonsWrapper } from './style'; import { useTranslation } from 'react-i18next'; const showProcessedButtons = (toDone: string[]): boolean => toDone && toDone.length > 0; const showDeliveredButton = (allDone: string[], toDone: string[]): boolean => allDone && allDone.length > 0 && toDone && toDone.length === 0; const ButtonsContainer = (props: ButtonsContainerProps): JSX.Element => { const { isZoomIn, setIsZoomIn, lines, callOrderApi, orderId, authProvider, kdsDeviceConfigs, viewMode, } = props; const { toDone, allDone, toPrepare, toConfirm } = getElements( lines, kdsDeviceConfigs && kdsDeviceConfigs.KDS_STAGE_DONE ? kdsDeviceConfigs.KDS_STAGE_DONE : '' ); const { t } = useTranslation(); const setOrderStatus = async (type: any, elements: any[]) => { try { const { token } = await authProvider(); callOrderApi( orderId, type, token, elements, kdsDeviceConfigs && 'KDS_STAGE_DONE' in kdsDeviceConfigs ? kdsDeviceConfigs.KDS_STAGE_DONE : null ); } catch (error) { console.warn(error); } }; return ( {toConfirm.length > 0 && toPrepare.length === 0 && ( setOrderStatus('confirm', toConfirm)} /> )} {toPrepare.length > 0 && ( setOrderStatus('prepare', toPrepare)} /> )} {showProcessedButtons(toDone) && ( <> setOrderStatus('prepared', toDone)} /> {viewMode !== '2' && isZoomIn && ( )} {viewMode !== '2' && !isZoomIn && ( )} )} {showDeliveredButton(allDone, toDone) && ( setOrderStatus('deliver', [])} /> )} ); }; export default ButtonsContainer;