clean code
parent
7034ad32e1
commit
f7cd5ffa49
|
@ -1,3 +1,4 @@
|
|||
import { useSession } from "next-auth/react";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
import { ZapierSetup } from "@calcom/app-store/zapierother/components";
|
||||
|
@ -5,9 +6,29 @@ import _packageZapier from "@calcom/app-store/zapierother/package.json";
|
|||
|
||||
import { trpc } from "@lib/trpc";
|
||||
|
||||
import Loader from "@components/Loader";
|
||||
|
||||
export default function SetupInformation() {
|
||||
const router = useRouter();
|
||||
const appName = router.query.appName;
|
||||
const { status } = useSession();
|
||||
|
||||
if (status === "loading") {
|
||||
return (
|
||||
<div className="absolute z-50 flex h-screen w-full items-center bg-gray-200">
|
||||
<Loader />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (status === "unauthenticated") {
|
||||
router.replace({
|
||||
pathname: "/auth/login",
|
||||
query: {
|
||||
callbackUrl: `/apps/setup/${appName}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (appName === _packageZapier.name.toLowerCase()) {
|
||||
return <ZapierSetup trpc={trpc}></ZapierSetup>;
|
||||
|
|
|
@ -4,7 +4,7 @@ import { stringify } from "querystring";
|
|||
import prisma from "@calcom/prisma";
|
||||
|
||||
const client_id = process.env.SLACK_CLIENT_ID;
|
||||
const scopes = ["commands", "users:read", "users:read.email","chat:write.public"];
|
||||
const scopes = ["commands", "users:read", "users:read.email", "chat:write.public"];
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (!req.session?.user?.id) {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { SubscriptionType } from "@prisma/client";
|
||||
import { ApiKeyType } from "@prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
import findValidApiKey from "@calcom/ee/lib/api/findValidApiKey";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKeyType } from "@prisma/client";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const apiKey = req.query.apiKey as string;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { ApiKeyType } from "@prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import findValidApiKey from "@calcom/ee/lib/api/findValidApiKey";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKeyType } from "@prisma/client";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const apiKey = req.query.apiKey as string;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { ApiKeyType } from "@prisma/client";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import findValidApiKey from "@calcom/ee/lib/api/findValidApiKey";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKeyType } from "@prisma/client";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const apiKey = req.query.apiKey as string;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { ClipboardCopyIcon } from "@heroicons/react/solid";
|
||||
import { ApiKeyType } from "@prisma/client";
|
||||
import { useSession } from "next-auth/react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
|
@ -21,7 +20,6 @@ export default function ZapierSetup(props: IZapierSetupProps) {
|
|||
const router = useRouter();
|
||||
const [newApiKey, setNewApiKey] = useState("");
|
||||
const utils = trpc.useContext();
|
||||
const { data: session, status } = useSession();
|
||||
const integrations = trpc.useQuery(["viewer.integrations"]);
|
||||
const oldApiKey = trpc.useQuery(["viewer.apiKeys.findKeyOfType", { apiKeyType: ApiKeyType.ZAPIER }]);
|
||||
const deleteApiKey = trpc.useMutation("viewer.apiKeys.delete");
|
||||
|
@ -42,7 +40,7 @@ export default function ZapierSetup(props: IZapierSetupProps) {
|
|||
setNewApiKey(apiKey);
|
||||
}
|
||||
|
||||
if (integrations.isLoading || status === "loading") {
|
||||
if (integrations.isLoading) {
|
||||
return (
|
||||
<div className="absolute z-50 flex h-screen w-full items-center bg-gray-200">
|
||||
<Loader />
|
||||
|
@ -50,13 +48,7 @@ export default function ZapierSetup(props: IZapierSetupProps) {
|
|||
);
|
||||
}
|
||||
|
||||
if (status === "unauthenticated") {
|
||||
router.replace({
|
||||
pathname: "/auth/login",
|
||||
});
|
||||
}
|
||||
|
||||
return status === "authenticated" ? (
|
||||
return (
|
||||
<div className="flex h-screen bg-gray-200">
|
||||
{showContent ? (
|
||||
<div className="m-auto rounded bg-white p-10">
|
||||
|
@ -122,9 +114,5 @@ export default function ZapierSetup(props: IZapierSetupProps) {
|
|||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="absolute z-50 flex h-screen w-full items-center bg-gray-200">
|
||||
<Loader />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,32 +1,33 @@
|
|||
import { ApiKeyType } from "@prisma/client";
|
||||
|
||||
import { hashAPIKey } from "@calcom/ee/lib/api/apiKeys";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { ApiKeyType } from "@prisma/client";
|
||||
|
||||
const findValidApiKey = async (apiKey: string, apiKeyType: ApiKeyType) => {
|
||||
const hashedKey = hashAPIKey(apiKey.substring(process.env.API_KEY_PREFIX?.length || 0));
|
||||
|
||||
const validKey = await prisma.apiKey.findFirst({
|
||||
where: {
|
||||
AND: [
|
||||
{
|
||||
hashedKey,
|
||||
where: {
|
||||
AND: [
|
||||
{
|
||||
hashedKey,
|
||||
},
|
||||
{
|
||||
apiKeyType,
|
||||
},
|
||||
],
|
||||
OR: [
|
||||
{
|
||||
expiresAt: {
|
||||
gte: new Date(Date.now()),
|
||||
},
|
||||
{
|
||||
apiKeyType,
|
||||
},
|
||||
],
|
||||
OR: [
|
||||
{
|
||||
expiresAt: {
|
||||
gte: new Date(Date.now()),
|
||||
},
|
||||
},
|
||||
{
|
||||
expiresAt: null,
|
||||
},
|
||||
]
|
||||
},
|
||||
});
|
||||
},
|
||||
{
|
||||
expiresAt: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
return validKey;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue