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

fix user id #184

Merged
merged 1 commit into from
Oct 30, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ import { api } from "~/trpc/react";
const ApprovalDialog: React.FC<{
releaseId: string;
policyId: string;
userId: string;
children: React.ReactNode;
}> = ({ releaseId, policyId, userId, children }) => {
}> = ({ releaseId, policyId, children }) => {
const approve = api.environment.policy.approval.approve.useMutation();
const rejected = api.environment.policy.approval.reject.useMutation();
const router = useRouter();
Expand All @@ -52,15 +51,15 @@ const ApprovalDialog: React.FC<{
<AlertDialogFooter>
<AlertDialogCancel
onClick={async () => {
await rejected.mutateAsync({ releaseId, policyId, userId });
await rejected.mutateAsync({ releaseId, policyId });
router.refresh();
}}
>
Reject
</AlertDialogCancel>
<AlertDialogAction
onClick={async () => {
await approve.mutateAsync({ releaseId, policyId, userId });
await approve.mutateAsync({ releaseId, policyId });
router.refresh();
}}
>
Expand Down Expand Up @@ -191,11 +190,7 @@ const ApprovalCheck: React.FC<PolicyNodeProps["data"]> = ({ id, release }) => {
}
const status = approval.data?.status;
return (
<ApprovalDialog
policyId={id}
releaseId={release.id}
userId={approval.data?.userId ?? ""}
>
<ApprovalDialog policyId={id} releaseId={release.id}>
<button
disabled={status === "approved" || status === "rejected"}
className="flex w-full items-center gap-2 rounded-md hover:bg-neutral-800/50"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const PolicyApprovalRow: React.FC<PolicyApprovalRowProps> = ({

const environmentName = environment.name;
const { releaseId, policyId, status } = approval;
const currentUserId = api.user.viewer.useQuery().data?.id;

const rejectMutation = api.environment.policy.approval.reject.useMutation({
onSuccess: ({ cancelledJobCount }) => {
Expand Down Expand Up @@ -59,13 +58,11 @@ export const PolicyApprovalRow: React.FC<PolicyApprovalRowProps> = ({
rejectMutation.mutate({
releaseId,
policyId,
userId: currentUserId!,
});
const handleApprove = () =>
approveMutation.mutate({
releaseId,
policyId,
userId: currentUserId!,
});

return (
Expand Down
6 changes: 2 additions & 4 deletions packages/api/src/router/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,12 @@ const policyRouter = createTRPCRouter({
z.object({
policyId: z.string().uuid(),
releaseId: z.string().uuid(),
userId: z.string().uuid(),
}),
)
.mutation(async ({ ctx, input }) => {
const envApproval = await ctx.db
.update(environmentPolicyApproval)
.set({ status: "approved", userId: input.userId })
.set({ status: "approved", userId: ctx.session.user.id })
.where(
and(
eq(environmentPolicyApproval.policyId, input.policyId),
Expand Down Expand Up @@ -225,14 +224,13 @@ const policyRouter = createTRPCRouter({
z.object({
releaseId: z.string().uuid(),
policyId: z.string().uuid(),
userId: z.string().uuid(),
}),
)
.mutation(({ ctx, input }) =>
ctx.db.transaction(async (tx) => {
await tx
.update(environmentPolicyApproval)
.set({ status: "rejected", userId: input.userId })
.set({ status: "rejected", userId: ctx.session.user.id })
.where(
and(
eq(environmentPolicyApproval.policyId, input.policyId),
Expand Down
Loading