import { useMutation, useFlash } from '@redwoodjs/web' import { Link, routes } from '@redwoodjs/router' const DELETE_PART_MUTATION = gql` mutation DeletePartMutation($id: Int!) { deletePart(id: $id) { id } } ` const MAX_STRING_LENGTH = 150 const truncate = (text) => { let output = text if (text && text.length > MAX_STRING_LENGTH) { output = output.substring(0, MAX_STRING_LENGTH) + '...' } return output } const jsonTruncate = (obj) => { return truncate(JSON.stringify(obj, null, 2)) } const timeTag = (datetime) => { return ( ) } const checkboxInputTag = (checked) => { return } const PartsList = ({ parts }) => { const { addMessage } = useFlash() const [deletePart] = useMutation(DELETE_PART_MUTATION, { onCompleted: () => { addMessage('Part deleted.', { classes: 'rw-flash-success' }) }, }) const onDeleteClick = (id) => { if (confirm('Are you sure you want to delete part ' + id + '?')) { deletePart({ variables: { id }, refetchQueries: ['PARTS'] }) } } return (
{parts.map((part) => ( ))}
Id Title Description Code Main image Created at  
{truncate(part.id)} {truncate(part.title)} {truncate(part.description)} {truncate(part.code)} {truncate(part.mainImage)} {timeTag(part.createdAt)}
) } export default PartsList