Skip to content

Commit 6f4606a

Browse files
committed
add use update review
1 parent cccd278 commit 6f4606a

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import graphqlClient from "@/shared/api/graphql/graphqlClientApollo";
2+
import { BranchContextParams } from "@/shared/api/types";
3+
import { gql } from "@apollo/client";
4+
5+
const MUTATION = `
6+
mutation ProposedChangeReview($id: ID, $decison: String) {
7+
CoreProposedChangeReview(data: {
8+
id: $id,
9+
decision: $decision
10+
}) {
11+
ok
12+
}
13+
}
14+
`;
15+
16+
export interface UpdateReviewFromApiApiParams extends BranchContextParams {
17+
proposedChangeId: string;
18+
decision: string;
19+
}
20+
21+
export function udpateReviewFromApi({
22+
proposedChangeId,
23+
decision,
24+
branchName,
25+
}: UpdateReviewFromApiApiParams) {
26+
return graphqlClient.mutate({
27+
mutation: gql(MUTATION),
28+
variables: {
29+
proposedChangeId,
30+
decision,
31+
},
32+
context: {
33+
branch: branchName,
34+
},
35+
});
36+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { useCurrentBranch } from "@/entities/branches/ui/branches-provider";
2+
import { useMutation } from "@tanstack/react-query";
3+
import { UpdateReviewFromApiApiParams } from "../api/updateReviewFromApi";
4+
import { updateReview } from "./update-review";
5+
6+
interface UpdateReviewProps {
7+
onSuccess?: () => void;
8+
onError?: () => void;
9+
onSettled?: () => void;
10+
}
11+
12+
export function useUpdateReview({ onSuccess, onError, onSettled }: UpdateReviewProps) {
13+
const { currentBranch } = useCurrentBranch();
14+
15+
return useMutation({
16+
mutationFn: async (params: Omit<UpdateReviewFromApiApiParams, "branchName">) => {
17+
return updateReview({
18+
...params,
19+
branchName: currentBranch.name,
20+
});
21+
},
22+
onSuccess,
23+
onError,
24+
onSettled,
25+
});
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { UpdateReviewFromApiApiParams, udpateReviewFromApi } from "../api/updateReviewFromApi";
2+
3+
export type UpdateReview = (data: UpdateReviewFromApiApiParams) => Promise<void>;
4+
5+
export const updateReview: UpdateReview = async (params) => {
6+
const { data, errors } = await udpateReviewFromApi(params);
7+
8+
if (errors?.[0]?.message) {
9+
throw new Error(errors[0].message);
10+
}
11+
12+
return data.CoreProposedChangeReview.object;
13+
};

0 commit comments

Comments
 (0)