import React, { useCallback, useMemo } from 'react'; import { Button, DataTable, DataTableSkeleton, Layer, Table, TableBody, TableCell, TableContainer, TableHead, TableHeader, TableRow, Tile, } from '@carbon/react'; import { Add } from '@carbon/react/icons'; import { useTranslation } from 'react-i18next'; import { EmptyCardIllustration, ErrorState, launchWorkspace2, useLayoutType } from '@openmrs/esm-framework'; import { useQueueRooms, useQueuesMutable } from '../queue-admin.resource'; import QueueActionMenu from './queue-action-menu.component'; import QueueRoomActionMenu from './queue-room-action-menu.component'; import styles from './admin-page.scss'; const AdminPage = () => { const { t } = useTranslation(); const layout = useLayoutType(); const isTablet = layout === 'tablet'; const responsiveSize = isTablet ? 'lg' : 'sm'; const { queues, isLoading: isLoadingQueues, error: queuesError } = useQueuesMutable(); const { queueRooms, isLoading: isLoadingQueueRooms, error: queueRoomsError } = useQueueRooms(); const queueTableHeaders = [ { key: 'name', header: t('name', 'Name'), }, { key: 'description', header: t('description', 'Description'), }, { key: 'service', header: t('service', 'Service'), }, { key: 'location', header: t('location', 'Location'), }, ]; const queueRoomTableHeaders = [ { key: 'name', header: t('name', 'Name'), }, { key: 'description', header: t('description', 'Description'), }, { key: 'queue', header: t('queue', 'Queue'), }, ]; const handleAddQueue = useCallback(() => { launchWorkspace2('service-queues-service-form'); }, []); const handleAddQueueRoom = useCallback(() => { launchWorkspace2('service-queues-room-workspace'); }, []); const queueTableRows = useMemo(() => { return ( queues?.map((queue) => ({ id: queue.uuid, name: queue.name || queue.display, description: queue.description || '--', service: queue.service?.display || '--', location: queue.location?.display || '--', })) || [] ); }, [queues]); const queueRoomTableRows = useMemo(() => { return ( queueRooms?.map((room) => ({ id: room.uuid, name: room.name || room.display, description: room.description || '--', queue: room.queue?.display || '--', })) || [] ); }, [queueRooms]); return (
{/* Queues Section */}

{t('queues', 'Queues')}

{!queuesError && ( )}
{isLoadingQueues ? ( ) : queuesError ? ( ) : ( {({ rows, headers, getTableProps }) => ( {headers.map((header) => ( {header.header} ))} {rows.map((row, i) => ( {row.cells.map((cell) => ( {cell.value} ))} ))}
)}
{queueTableRows.length === 0 && (

{t('noQueuesToDisplay', 'No queues to display')}

)}
)}
{/* Queue Rooms Section */}

{t('queueRooms', 'Queue rooms')}

{!queueRoomsError && ( )}
{isLoadingQueueRooms ? ( ) : queueRoomsError ? ( ) : ( {({ rows, headers, getTableProps }) => ( {headers.map((header) => ( {header.header} ))} {rows.map((row, i) => ( {row.cells.map((cell) => ( {cell.value} ))} ))}
)}
{queueRoomTableRows.length === 0 && (

{t('noQueueRoomsToDisplay', 'No queue rooms to display')}

)}
)}
); }; export default AdminPage;