import { Link, routes } from '@redwoodjs/router' import { useMutation } from '@redwoodjs/web' import { toast } from '@redwoodjs/web/toast' import { QUERY } from 'src/components/Artikel/ArtikelsCell' import { truncate } from 'src/lib/formatters' const DELETE_ARTIKEL_MUTATION = gql` mutation DeleteArtikelMutation($id: Int!) { deleteArtikel(id: $id) { id } } ` const ArtikelsList = ({ artikels }) => { const [deleteArtikel] = useMutation(DELETE_ARTIKEL_MUTATION, { onCompleted: () => { toast.success('Artikel deleted') }, onError: (error) => { toast.error(error.message) }, // This refetches the query on the list page. Read more about other ways to // update the cache over here: // https://www.apollographql.com/docs/react/data/mutations/#making-all-other-cache-updates refetchQueries: [{ query: QUERY }], awaitRefetchQueries: true, }) const onDeleteClick = (id) => { if (confirm('Are you sure you want to delete artikel ' + id + '?')) { deleteArtikel({ variables: { id } }) } } return (
{artikels.map((artikel) => ( ))}
Id Name Preis Kategorie  
{truncate(artikel.id)} {truncate(artikel.name)} {truncate(artikel.preis)} {truncate(artikel.kategorie.name)}
) } export default ArtikelsList