import { formatDate } from "date-fns"; import { ExternalLinkIcon, GitBranch, ImportIcon, Loader2, Trash2, } from "lucide-react"; import Link from "next/link"; import { toast } from "sonner"; import { BitbucketIcon, GiteaIcon, GithubIcon, GitlabIcon, } from "@/components/icons/data-tools-icons"; import { DialogAction } from "@/components/shared/dialog-action"; import { Badge } from "@/components/ui/badge"; import { Button, buttonVariants } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { api } from "@/utils/api"; import { useUrl } from "@/utils/hooks/use-url"; import { AddBitbucketProvider } from "./bitbucket/add-bitbucket-provider"; import { EditBitbucketProvider } from "./bitbucket/edit-bitbucket-provider"; import { AddGiteaProvider } from "./gitea/add-gitea-provider"; import { EditGiteaProvider } from "./gitea/edit-gitea-provider"; import { AddGithubProvider } from "./github/add-github-provider"; import { EditGithubProvider } from "./github/edit-github-provider"; import { AddGitlabProvider } from "./gitlab/add-gitlab-provider"; import { EditGitlabProvider } from "./gitlab/edit-gitlab-provider"; export const ShowGitProviders = () => { const { data, isLoading, refetch } = api.gitProvider.getAll.useQuery(); const { mutateAsync, isLoading: isRemoving } = api.gitProvider.remove.useMutation(); const url = useUrl(); const getGitlabUrl = ( clientId: string, gitlabId: string, gitlabUrl: string, ) => { const redirectUri = `${url}/api/providers/gitlab/callback?gitlabId=${gitlabId}`; const scope = "api read_user read_repository"; const authUrl = `${gitlabUrl}/oauth/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&scope=${encodeURIComponent(scope)}`; return authUrl; }; return (