Skip to content

Commit

Permalink
fix: issues with fetching and submitting reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Extheoisah committed Sep 16, 2023
1 parent 49ce6f3 commit 4389780
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/components/alerts/SubmitTranscriptAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const PromptStepOne = forwardRef<HTMLButtonElement, PromptOneProps>(
PromptStepOne.displayName = "PromptStepOne";

const PromptStepTwo = forwardRef<HTMLButtonElement, PromptTwoProps>(
({ onCancel, prRepo, onSubmit }) => {
({ onCancel, prRepo, onSubmit }, ref) => {
return (
<>
<AlertDialogBody>
Expand All @@ -138,6 +138,7 @@ const PromptStepTwo = forwardRef<HTMLButtonElement, PromptTwoProps>(
</AlertDialogBody>
<AlertDialogFooter gap={3}>
<Button
ref={ref}
display="block"
size="sm"
mx="auto"
Expand Down
25 changes: 11 additions & 14 deletions src/components/tables/CurrentJobsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@ import type { TableStructure } from "./types";
import Image from "next/image";

const CurrentJobsTable = () => {
const router = useRouter();
const { data: userSession } = useSession();
const {
data: multipleStatusData,
isLoading,
isError,
refetch,
} = useUserMultipleReviews({

const { data, isLoading } = useUserMultipleReviews({
userId: userSession?.user?.id,
multipleStatus: ["active"],
multipleStatus: ["pending", "active"],
});

const router = useRouter();
const multipleStatusData = data?.data;
const refetch = data?.refetch;
const isError = data?.isError || false;

const tableData = useMemo(() => {
let allData = multipleStatusData?.data ?? [];
let allData = (multipleStatusData && multipleStatusData.data) ?? [];
if (!allData.length) return [];

// return data restructured as ReviewTranscript[]
Expand All @@ -47,10 +45,9 @@ const CurrentJobsTable = () => {

const ActionComponent = useCallback(
({ data }: { data: ReviewTranscript }) => {
const pendingIndex = multipleStatusData?.data?.findIndex(
(review) => review.id === data.review?.id
const pendingReview = multipleStatusData?.data?.find(
(review) => review.pr_url !== null
);
const isPending = pendingIndex !== -1;

const handleResume = () => {
if (!data.review?.id) {
Expand All @@ -61,7 +58,7 @@ const CurrentJobsTable = () => {
};
return (
<>
{isPending ? (
{Boolean(pendingReview) ? (
<Link href={`${data.review?.pr_url}`} target="_blank">
<Button colorScheme={"gray"} size="sm">
Under Review
Expand Down
4 changes: 2 additions & 2 deletions src/components/tables/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Flex, Text } from "@chakra-ui/react";
import { useRouter } from "next/router";
import React, { Dispatch, SetStateAction, useLayoutEffect } from "react";
import React, { Dispatch, SetStateAction, useEffect } from "react";

type IPagination = {
pages: number;
Expand All @@ -15,7 +15,7 @@ const Pagination = ({ pages, currentPage, setCurrentPage }: IPagination) => {
});
setCurrentPage(page);
};
useLayoutEffect(() => {
useEffect(() => {
if (router.query?.page) {
setCurrentPage(Number(router.query?.page as string));
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/tables/TransactionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const tableStructure = [
modifier: (data) => data.id,
},
{
name: "amount",
name: "amount (SAT)",
type: "text-short",
modifier: (data) => data.amount,
},
Expand Down
15 changes: 15 additions & 0 deletions src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import NextAuth, {
GhExtendedProfile,
NextAuthOptions,
Session,
getServerSession,
} from "next-auth";
import GithubProvider from "next-auth/providers/github";
import { DecodedJWT, UserSessionType } from "../../../../types";
import {
GetServerSidePropsContext,
NextApiRequest,
NextApiResponse,
} from "next";

export const authOptions: NextAuthOptions = {
// Configure one or more authentication providers
Expand Down Expand Up @@ -86,3 +92,12 @@ export const authOptions: NextAuthOptions = {
secret: process.env.NEXTAUTH_SECRET,
};
export default NextAuth(authOptions);

export function auth(
...args:
| [GetServerSidePropsContext["req"], GetServerSidePropsContext["res"]]
| [NextApiRequest, NextApiResponse]
| []
) {
return getServerSession(...args, authOptions);
}
4 changes: 2 additions & 2 deletions src/pages/api/github/pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import config from "@/config/config.json";
import { deriveFileSlug, Metadata, newIndexFile } from "@/utils";
import { Octokit } from "@octokit/core";
import type { NextApiRequest, NextApiResponse } from "next";
import { getSession } from "next-auth/react";
import { auth } from "../auth/[...nextauth]";

async function createForkAndPR(
octokit: InstanceType<typeof Octokit>,
Expand Down Expand Up @@ -137,7 +137,7 @@ export default async function handler(
res: NextApiResponse
) {
// Check if the user is authenticated
const session = await getSession({ req });
const session = await auth(req, res);
if (!session || !session.accessToken || !session.user?.githubUsername) {
return res.status(401).json({ message: "Unauthorized" });
}
Expand Down
11 changes: 8 additions & 3 deletions src/services/api/reviews/useUserReviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ export const useUserMultipleReviews = ({
};
}),
});
const resultQuery = queryInfo.find(
(query) => query.data && query.data.totalItems !== 0
);
const result = resultQuery && resultQuery.data ? resultQuery : null;
return {
...queryInfo[0],
isLoading:
queryInfo[0].isLoading && queryInfo[0].fetchStatus === "fetching",
data: result,
isLoading: queryInfo.some(
(query) => query.isLoading && query.fetchStatus === "fetching"
),
};
};

0 comments on commit 4389780

Please sign in to comment.