import type { EditProjectById, UpdateProjectInput, UpdateProjectMutationVariables, } from 'types/graphql' import { navigate, routes } from '@redwoodjs/router' import type { CellSuccessProps, CellFailureProps, TypedDocumentNode, } from '@redwoodjs/web' import { useMutation } from '@redwoodjs/web' import { toast } from '@redwoodjs/web/toast' import CellFailure from 'src/components/Cell/CellFailure/CellFailure' import CellLoading from 'src/components/Cell/CellLoading/CellLoading' import ProjectForm from 'src/components/Project/ProjectForm' export const QUERY: TypedDocumentNode = gql` query EditProjectById($id: Int!) { project: project(id: $id) { id title description date links images tags { id tag color } } } ` const UPDATE_PROJECT_MUTATION: TypedDocumentNode< EditProjectById, UpdateProjectMutationVariables > = gql` mutation UpdateProjectMutation($id: Int!, $input: UpdateProjectInput!) { updateProject(id: $id, input: $input) { id title description date links } } ` export const Loading = () => export const Failure = ({ error }: CellFailureProps) => ( ) export const Success = ({ project }: CellSuccessProps) => { const [updateProject, { loading, error }] = useMutation( UPDATE_PROJECT_MUTATION, { onCompleted: () => { toast.success('Project updated') navigate(routes.adminProjects()) }, onError: (error) => toast.error(error.message), } ) const onSave = ( input: UpdateProjectInput, id: EditProjectById['project']['id'] ) => updateProject({ variables: { id, input } }) return (
Edit Project {project.id}
) }