Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sweep Rules] Remove Unnecessary Separators and Extra Characters in Code #2382

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 16 additions & 25 deletions packages/hub/src/app/new/definition/NewDefinition.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<NewDefinitionMutation>({
mutation: Mutation,
expectedTypename: "CreateRelativeValuesDefinitionResult",
Expand All @@ -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,
}));
}
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<QueryType>;
}> = ({ query }) => {
export const EditRelativeValuesDefinition: FC<{ query: SerializablePreloadedQuery<QueryType>; }> = ({ 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<RelativeValuesDefinitionPage$key>(
RelativeValuesDefinitionPageFragment,
definitionRef
);
const revision = useFragment<RelativeValuesDefinitionRevision$key>(
RelativeValuesDefinitionRevisionFragment,
definition.currentRevision
);

const [saveMutation] = useAsyncMutation<EditRelativeValuesDefinitionMutation>(
{
mutation: Mutation,
expectedTypename: "UpdateRelativeValuesDefinitionResult",
}
);
const definition = useFragment<RelativeValuesDefinitionPage$key>(RelativeValuesDefinitionPageFragment, definitionRef);
const revision = useFragment<RelativeValuesDefinitionRevision$key>(RelativeValuesDefinitionRevisionFragment, definition.currentRevision);
const [saveMutation] = useAsyncMutation<EditRelativeValuesDefinitionMutation>({ mutation: Mutation, expectedTypename: "UpdateRelativeValuesDefinitionResult" });

const save = async (data: FormShape) => {
await saveMutation({
Expand All @@ -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 }));
},
});
};
Expand Down