From 716f0dc4e70549cd7c0bcfcbf690ebe9da0db40a Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sun, 29 Oct 2023 19:18:36 +0000 Subject: [PATCH 1/2] feat: Updated packages/hub/src/app/new/definition/ --- .../src/app/new/definition/NewDefinition.tsx | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/packages/hub/src/app/new/definition/NewDefinition.tsx b/packages/hub/src/app/new/definition/NewDefinition.tsx index fbd3b4511c..9acd854652 100644 --- a/packages/hub/src/app/new/definition/NewDefinition.tsx +++ b/packages/hub/src/app/new/definition/NewDefinition.tsx @@ -1,10 +1,8 @@ "use client"; - import { useSession } from "next-auth/react"; import { useRouter } from "next/navigation"; import { FC } from "react"; import { graphql } from "relay-runtime"; - import { NewDefinitionMutation } from "@/__generated__/NewDefinitionMutation.graphql"; import { H1 } from "@/components/ui/Headers"; import { useAsyncMutation } from "@/hooks/useAsyncMutation"; @@ -13,32 +11,27 @@ import { FormShape } from "@/relative-values/components/RelativeValuesDefinition import { relativeValuesRoute } from "@/routes"; const Mutation = graphql` - mutation NewDefinitionMutation( - $input: MutationCreateRelativeValuesDefinitionInput! - ) { - result: createRelativeValuesDefinition(input: $input) { - __typename - ... on ValidationError { - message - } - ... on CreateRelativeValuesDefinitionResult { - definition { - id +mutation NewDefinitionMutation($input: MutationCreateRelativeValuesDefinitionInput!) { + result: createRelativeValuesDefinition(input: $input) { + __typename + ... on ValidationError { + message + } + ... on CreateRelativeValuesDefinitionResult { + definition { + id + slug + owner { slug - owner { - slug - } } } } } -`; +}`; export const NewDefinition: FC = () => { useSession({ required: true }); - const router = useRouter(); - const [runMutation] = useAsyncMutation({ mutation: Mutation, expectedTypename: "CreateRelativeValuesDefinitionResult", @@ -59,12 +52,10 @@ export const NewDefinition: FC = () => { }, onCompleted: (result) => { if (result.__typename === "CreateRelativeValuesDefinitionResult") { - router.push( - relativeValuesRoute({ - owner: result.definition.owner.slug, - slug: result.definition.slug, - }) - ); + router.push(relativeValuesRoute({ + owner: result.definition.owner.slug, + slug: result.definition.slug, + })); } }, }); From ea46e4632b6231055da78bd261fd65ef81fdf8cf Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sun, 29 Oct 2023 19:22:10 +0000 Subject: [PATCH 2/2] feat: Updated packages/hub/src/app/relative-values --- .../edit/EditRelativeValuesDefinition.tsx | 66 +++++-------------- 1 file changed, 17 insertions(+), 49 deletions(-) diff --git a/packages/hub/src/app/relative-values/[owner]/[slug]/edit/EditRelativeValuesDefinition.tsx b/packages/hub/src/app/relative-values/[owner]/[slug]/edit/EditRelativeValuesDefinition.tsx index 04854b5dcb..0b3ca67bbf 100644 --- a/packages/hub/src/app/relative-values/[owner]/[slug]/edit/EditRelativeValuesDefinition.tsx +++ b/packages/hub/src/app/relative-values/[owner]/[slug]/edit/EditRelativeValuesDefinition.tsx @@ -22,55 +22,28 @@ import { import { relativeValuesRoute } from "@/routes"; const Mutation = graphql` - mutation EditRelativeValuesDefinitionMutation( - $input: MutationUpdateRelativeValuesDefinitionInput! - ) { - result: updateRelativeValuesDefinition(input: $input) { - __typename - ... on BaseError { - message - } - ... on UpdateRelativeValuesDefinitionResult { - definition { - id - } +mutation EditRelativeValuesDefinitionMutation($input: MutationUpdateRelativeValuesDefinitionInput!) { + result: updateRelativeValuesDefinition(input: $input) { + __typename + ... on BaseError { + message + } + ... on UpdateRelativeValuesDefinitionResult { + definition { + id } } } -`; +}`; -export const EditRelativeValuesDefinition: FC<{ - query: SerializablePreloadedQuery; -}> = ({ query }) => { +export const EditRelativeValuesDefinition: FC<{ query: SerializablePreloadedQuery; }> = ({ query }) => { useSession({ required: true }); - - const [{ relativeValuesDefinition: result }] = usePageQuery( - RelativeValuesDefinitionPageQuery, - query - ); - - const definitionRef = extractFromGraphqlErrorUnion( - result, - "RelativeValuesDefinition" - ); - + const [{ relativeValuesDefinition: result }] = usePageQuery(RelativeValuesDefinitionPageQuery, query); + const definitionRef = extractFromGraphqlErrorUnion(result, "RelativeValuesDefinition"); const router = useRouter(); - - const definition = useFragment( - RelativeValuesDefinitionPageFragment, - definitionRef - ); - const revision = useFragment( - RelativeValuesDefinitionRevisionFragment, - definition.currentRevision - ); - - const [saveMutation] = useAsyncMutation( - { - mutation: Mutation, - expectedTypename: "UpdateRelativeValuesDefinitionResult", - } - ); + const definition = useFragment(RelativeValuesDefinitionPageFragment, definitionRef); + const revision = useFragment(RelativeValuesDefinitionRevisionFragment, definition.currentRevision); + const [saveMutation] = useAsyncMutation({ mutation: Mutation, expectedTypename: "UpdateRelativeValuesDefinitionResult" }); const save = async (data: FormShape) => { await saveMutation({ @@ -85,12 +58,7 @@ export const EditRelativeValuesDefinition: FC<{ }, }, onCompleted() { - router.push( - relativeValuesRoute({ - owner: definition.owner.slug, - slug: definition.slug, - }) - ); + router.push(relativeValuesRoute({ owner: definition.owner.slug, slug: definition.slug })); }, }); };