import { useMutation } from '@redwoodjs/web' import { toast } from '@redwoodjs/web/toast' import { Link, routes } from '@redwoodjs/router' import { QUERY } from 'src/components/AdminPartsCell' const DELETE_PART_MUTATION = gql` mutation DeletePartMutation($id: String!) { 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 timeTag = (datetime) => { return ( ) } const checkboxInputTag = (checked) => { return } const AdminParts = ({ parts }) => { const [deletePart] = useMutation(DELETE_PART_MUTATION, { onCompleted: () => { toast.success('Part deleted.') }, // 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 part ' + id + '?')) { deletePart({ variables: { id } }) } } return (
| Id | Title | Description | Code | Main image | Created at | Updated at | User id | Deleted | |
|---|---|---|---|---|---|---|---|---|---|
| {truncate(part.id)} | {truncate(part.title)} | {truncate(part.description)} | {truncate(part.code)} | {truncate(part.mainImage)} | {timeTag(part.createdAt)} | {timeTag(part.updatedAt)} | {truncate(part.userId)} | {checkboxInputTag(part.deleted)} |