import type { DeleteProjectMutation, DeleteProjectMutationVariables, AdminFindProjectById, } from 'types/graphql' import { Link, routes, navigate } from '@redwoodjs/router' import { useMutation } from '@redwoodjs/web' import type { TypedDocumentNode } from '@redwoodjs/web' import { toast } from '@redwoodjs/web/toast' import { calculateLuminance } from 'src/lib/color' import { timeTag } from 'src/lib/formatters' import { batchDelete } from 'src/lib/tus' const DELETE_PROJECT_MUTATION: TypedDocumentNode< DeleteProjectMutation, DeleteProjectMutationVariables > = gql` mutation DeleteProjectMutation($id: Int!) { deleteProject(id: $id) { id } } ` interface Props { project: NonNullable } const AdminProject = ({ project }: Props) => { const [deleteProject] = useMutation(DELETE_PROJECT_MUTATION, { onCompleted: () => { toast.success('Project deleted') navigate(routes.adminProjects()) }, onError: (error) => toast.error(error.message), }) const onDeleteClick = (id: DeleteProjectMutationVariables['id']) => { if (confirm('Are you sure you want to delete project ' + id + '?')) { batchDelete(project.images) deleteProject({ variables: { id } }) } } return (
Project {project.id}: {project.title}  
ID {project.id}
Title {project.title}
Description {project.description}
Date {timeTag(project.date)}
Images
{project.images.map((image, i) => ( {i + 1} ))}
Tags
{project.tags.map((tag, i) => (
0.5 ? 'black' : 'white', }} > {tag.tag}
))}
Links
{project.links.map((link, i) => ( {link} ))}
) } export default AdminProject