diff --git a/apps/webservice/src/app/[workspaceSlug]/(job)/job-agents/add/GithubConfig.tsx b/apps/webservice/src/app/[workspaceSlug]/(job)/job-agents/add/GithubConfig.tsx deleted file mode 100644 index 84530e3b..00000000 --- a/apps/webservice/src/app/[workspaceSlug]/(job)/job-agents/add/GithubConfig.tsx +++ /dev/null @@ -1,166 +0,0 @@ -import type { GithubUser } from "@ctrlplane/db/schema"; -import { useState } from "react"; -import { TbPlus } from "react-icons/tb"; - -import { Avatar, AvatarFallback, AvatarImage } from "@ctrlplane/ui/avatar"; -import { Button } from "@ctrlplane/ui/button"; -import { - Card, - CardContent, - CardDescription, - CardHeader, - CardTitle, -} from "@ctrlplane/ui/card"; -import { - Command, - CommandGroup, - CommandInput, - CommandItem, - CommandList, -} from "@ctrlplane/ui/command"; -import { Popover, PopoverContent, PopoverTrigger } from "@ctrlplane/ui/popover"; - -import { env } from "~/env"; -import { api } from "~/trpc/react"; - -export const GithubJobAgentConfig: React.FC<{ - githubUser: GithubUser; - workspaceSlug: string; - workspaceId: string; -}> = ({ githubUser, workspaceSlug, workspaceId }) => { - const githubOrgs = api.github.organizations.byGithubUserId.useQuery( - githubUser.githubUserId, - ); - - const githubOrgCreate = api.github.organizations.create.useMutation(); - - const githubOrgsInstalled = - api.github.organizations.list.useQuery(workspaceId); - - const { mutateAsync, isPending } = api.job.agent.create.useMutation(); - - const [open, setOpen] = useState(false); - const [value, setValue] = useState(null); - const [image, setImage] = useState(null); - - return ( - - - - Connect an organization - - - Select an organization to associate with this job agent. - - - -
-
- - - - - - - - - - {githubOrgs.data - ?.filter( - (org) => - !githubOrgsInstalled.data?.some( - (o) => - o.github_organization.organizationName === - org.login, - ), - ) - .map(({ id, login, avatar_url }) => ( - { - setValue(currentValue); - setImage(avatar_url); - setOpen(false); - }} - > -
- - - - {login.slice(0, 2)} - - - {login} -
-
- ))} - - - - - Add new organization - - -
-
-
-
-
- - -
-
-
-
- ); -}; diff --git a/apps/webservice/src/app/[workspaceSlug]/settings/(settings)/workspace/integrations/(integration)/github/GithubOrgConfig.tsx b/apps/webservice/src/app/[workspaceSlug]/settings/(settings)/workspace/integrations/(integration)/github/GithubOrgConfig.tsx index 908f9efa..710ace02 100644 --- a/apps/webservice/src/app/[workspaceSlug]/settings/(settings)/workspace/integrations/(integration)/github/GithubOrgConfig.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/settings/(settings)/workspace/integrations/(integration)/github/GithubOrgConfig.tsx @@ -31,15 +31,27 @@ import { Popover, PopoverContent, PopoverTrigger } from "@ctrlplane/ui/popover"; import { Separator } from "@ctrlplane/ui/separator"; import { Skeleton } from "@ctrlplane/ui/skeleton"; -import { env } from "~/env"; import { api } from "~/trpc/react"; -export const GithubOrgConfig: React.FC<{ +interface GithubOrgConfigProps { githubUser?: GithubUser | null; workspaceSlug?: string; workspaceId?: string; loading: boolean; -}> = ({ githubUser, workspaceSlug, workspaceId, loading }) => { + githubConfig: { + url: string; + botName: string; + clientId: string; + }; +} + +export const GithubOrgConfig: React.FC = ({ + githubUser, + workspaceSlug, + workspaceId, + loading, + githubConfig, +}) => { const githubOrgs = api.github.organizations.byGithubUserId.useQuery( githubUser?.githubUserId ?? 0, { enabled: !loading && githubUser != null }, @@ -58,6 +70,8 @@ export const GithubOrgConfig: React.FC<{ const [value, setValue] = useState(null); const [image, setImage] = useState(null); + const baseUrl = api.runtime.baseUrl.useQuery(); + return ( @@ -138,7 +152,7 @@ export const GithubOrgConfig: React.FC<{ @@ -254,7 +268,7 @@ export const GithubOrgConfig: React.FC<{ { diff --git a/apps/webservice/src/app/[workspaceSlug]/settings/(settings)/workspace/integrations/(integration)/github/page.tsx b/apps/webservice/src/app/[workspaceSlug]/settings/(settings)/workspace/integrations/(integration)/github/page.tsx index 8f03a15c..b40cf572 100644 --- a/apps/webservice/src/app/[workspaceSlug]/settings/(settings)/workspace/integrations/(integration)/github/page.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/settings/(settings)/workspace/integrations/(integration)/github/page.tsx @@ -7,13 +7,18 @@ import { SiGithub } from "react-icons/si"; import { Button } from "@ctrlplane/ui/button"; import { Card } from "@ctrlplane/ui/card"; -import { env } from "~/env"; import { api } from "~/trpc/react"; import { GithubConfigFileSync } from "./GithubConfigFile"; import { GithubOrgConfig } from "./GithubOrgConfig"; -const githubAuthUrl = (userId?: string, workspaceSlug?: string) => - `${env.NEXT_PUBLIC_GITHUB_URL}/login/oauth/authorize?response_type=code&client_id=${env.NEXT_PUBLIC_GITHUB_BOT_CLIENT_ID}&redirect_uri=${env.NEXT_PUBLIC_BASE_URL}/api/github/${userId}/${workspaceSlug}&state=sLtHqpxQ6FiUtBWJ&scope=repo%2Cread%3Auser`; +const githubAuthUrl = ( + baseUrl: string, + githubUrl: string, + clientId: string, + userId?: string, + workspaceSlug?: string, +) => + `${githubUrl}/login/oauth/authorize?response_type=code&client_id=${clientId}&redirect_uri=${baseUrl}/api/github/${userId}/${workspaceSlug}&state=sLtHqpxQ6FiUtBWJ&scope=repo%2Cread%3Auser`; export default function GitHubIntegrationPage({ params, @@ -24,6 +29,15 @@ export default function GitHubIntegrationPage({ const workspace = api.workspace.bySlug.useQuery(workspaceSlug); const session = useSession(); const router = useRouter(); + const baseUrl = api.runtime.baseUrl.useQuery(); + + const githubUrl = api.runtime.github.url.useQuery(); + const githubBotName = api.runtime.github.botName.useQuery(); + const githubBotClientId = api.runtime.github.clientId.useQuery(); + const isGithubConfigured = + githubUrl.data != null && + githubBotName.data != null && + githubBotClientId.data != null; const githubUser = api.github.user.byUserId.useQuery(session.data!.user.id, { enabled: session.status === "authenticated", @@ -64,7 +78,15 @@ export default function GitHubIntegrationPage({