import React, { useEffect, useState } from 'react'; import { Container, Flex, Heading, Spinner, Table, TableContainer, Tbody, Td, Th, Thead, Tr } from '@chakra-ui/react'; import { ApiError } from '../client'; import ActionsMenu from '../components/Common/ActionsMenu'; import Navbar from '../components/Common/Navbar'; import useCustomToast from '../hooks/useCustomToast'; import { useItemsStore } from '../store/items-store'; const Items: React.FC = () => { const showToast = useCustomToast(); const [isLoading, setIsLoading] = useState(false); const { items, getItems } = useItemsStore(); useEffect(() => { const fetchItems = async () => { setIsLoading(true); try { await getItems(); } catch (err) { const errDetail = (err as ApiError).body.detail; showToast('Something went wrong.', `${errDetail}`, 'error'); } finally { setIsLoading(false); } } if (items.length === 0) { fetchItems(); } }, []) return ( <> {isLoading ? ( // TODO: Add skeleton ) : ( items && Items Management {items.map((item) => ( ))}
ID Title Description Actions
{item.id} {item.title} {item.description || 'N/A'}
)} ) } export default Items;