import React, { useEffect, useState } from 'react'; import { Box, Heading, Table, Thead, Tbody, Tr, Th, Button, useDisclosure, Flex, useToast, Td, Text, Spinner, } from '@chakra-ui/react'; import { useTranslation } from 'react-i18next'; import MasterItem from '../MasterItem'; import MasterDrawer from '../MasterDrawer'; import { armService } from '../../api/arm'; import { MasterProps } from '../MasterItem/MasterItem'; const TABLE_HEADERS = [ 'name' as const, 'currentJob' as const, 'phone' as const, 'actions' as const, ]; const Masters = () => { const { isOpen, onOpen, onClose } = useDisclosure(); const toast = useToast(); const { t } = useTranslation('~', { keyPrefix: 'dry-wash.arm.master', }); const [masters, setMasters] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const { fetchMasters } = armService(); useEffect(() => { const loadMasters = async () => { setLoading(true); try { const data = await fetchMasters(); setMasters(data.body); } catch (err) { setError(err.message); toast({ title: t('error.title'), status: 'error', duration: 5000, isClosable: true, position: 'bottom-right', }); } finally { setLoading(false); } }; loadMasters(); }, [toast, t]); return ( {t('title')} {TABLE_HEADERS.map((name) => ( ))} {loading && ( )} {!loading && masters.length === 0 && !error && ( )} {!loading && !error && masters.map((master, index) => ( ))}
{t(`table.header.${name}`)}
{t('table.empty')}
); }; export default Masters;