import { useMutation } from '@redwoodjs/web' import { toast } from '@redwoodjs/web/toast' import { Link, routes } from '@redwoodjs/router' import { QUERY } from 'src/components/AdminProjectsCell/AdminProjectsCell' const DELETE_PROJECT_MUTATION_ADMIN = gql` mutation DeleteProjectMutationAdmin($id: String!) { deleteProject(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 AdminProjects = ({ projects }) => { const [deleteProject] = useMutation(DELETE_PROJECT_MUTATION_ADMIN, { onCompleted: () => { toast.success('Project 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 project ' + id + '?')) { deleteProject({ variables: { id } }) } } return (
| Id | Title | Description | Code | Main image | Created at | Updated at | User id | Deleted | |
|---|---|---|---|---|---|---|---|---|---|
| {truncate(project.id)} | {truncate(project.title)} | {truncate(project.description)} | {truncate(project.code)} | {truncate(project.mainImage)} | {timeTag(project.createdAt)} | {timeTag(project.updatedAt)} | {truncate(project.userId)} | {checkboxInputTag(project.deleted)} |