feat(dashboard): show "Action Required" badge for incomplete Git provider setup

This commit is contained in:
Jhon
2025-07-26 14:18:26 -03:00
parent d3a54172b5
commit 212c1b2d5f
@@ -1,27 +1,27 @@
import { import {
BitbucketIcon, BitbucketIcon,
GiteaIcon, GiteaIcon,
GithubIcon, GithubIcon,
GitlabIcon, GitlabIcon,
} from "@/components/icons/data-tools-icons"; } from "@/components/icons/data-tools-icons";
import { DialogAction } from "@/components/shared/dialog-action"; import { DialogAction } from "@/components/shared/dialog-action";
import { Button, buttonVariants } from "@/components/ui/button"; import { Button, buttonVariants } from "@/components/ui/button";
import { import {
Card, Card,
CardContent, CardContent,
CardDescription, CardDescription,
CardHeader, CardHeader,
CardTitle, CardTitle,
} from "@/components/ui/card"; } from "@/components/ui/card";
import { api } from "@/utils/api"; import { api } from "@/utils/api";
import { useUrl } from "@/utils/hooks/use-url"; import { useUrl } from "@/utils/hooks/use-url";
import { formatDate } from "date-fns"; import { formatDate } from "date-fns";
import { import {
ExternalLinkIcon, ExternalLinkIcon,
GitBranch, GitBranch,
ImportIcon, ImportIcon,
Loader2, Loader2,
Trash2, Trash2,
} from "lucide-react"; } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import { toast } from "sonner"; import { toast } from "sonner";
@@ -33,249 +33,256 @@ import { AddGithubProvider } from "./github/add-github-provider";
import { EditGithubProvider } from "./github/edit-github-provider"; import { EditGithubProvider } from "./github/edit-github-provider";
import { AddGitlabProvider } from "./gitlab/add-gitlab-provider"; import { AddGitlabProvider } from "./gitlab/add-gitlab-provider";
import { EditGitlabProvider } from "./gitlab/edit-gitlab-provider"; import { EditGitlabProvider } from "./gitlab/edit-gitlab-provider";
import { Badge } from "@/components/ui/badge";
export const ShowGitProviders = () => { export const ShowGitProviders = () => {
const { data, isLoading, refetch } = api.gitProvider.getAll.useQuery(); const { data, isLoading, refetch } = api.gitProvider.getAll.useQuery();
const { mutateAsync, isLoading: isRemoving } = const { mutateAsync, isLoading: isRemoving } =
api.gitProvider.remove.useMutation(); api.gitProvider.remove.useMutation();
const url = useUrl(); const url = useUrl();
const getGitlabUrl = ( const getGitlabUrl = (
clientId: string, clientId: string,
gitlabId: string, gitlabId: string,
gitlabUrl: string, gitlabUrl: string,
) => { ) => {
const redirectUri = `${url}/api/providers/gitlab/callback?gitlabId=${gitlabId}`; const redirectUri = `${url}/api/providers/gitlab/callback?gitlabId=${gitlabId}`;
const scope = "api read_user read_repository"; 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)}`; const authUrl = `${gitlabUrl}/oauth/authorize?client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code&scope=${encodeURIComponent(scope)}`;
return authUrl; return authUrl;
}; };
return ( return (
<div className="w-full"> <div className="w-full">
<Card className="h-full bg-sidebar p-2.5 rounded-xl max-w-5xl mx-auto"> <Card className="h-full bg-sidebar p-2.5 rounded-xl max-w-5xl mx-auto">
<div className="rounded-xl bg-background shadow-md "> <div className="rounded-xl bg-background shadow-md ">
<CardHeader className=""> <CardHeader className="">
<CardTitle className="text-xl flex flex-row gap-2"> <CardTitle className="text-xl flex flex-row gap-2">
<GitBranch className="size-6 text-muted-foreground self-center" /> <GitBranch className="size-6 text-muted-foreground self-center" />
Git Providers Git Providers
</CardTitle> </CardTitle>
<CardDescription> <CardDescription>
Connect your Git provider for authentication. Connect your Git provider for authentication.
</CardDescription> </CardDescription>
</CardHeader> </CardHeader>
<CardContent className="space-y-2 py-8 border-t"> <CardContent className="space-y-2 py-8 border-t">
{isLoading ? ( {isLoading ? (
<div className="flex flex-row gap-2 items-center justify-center text-sm text-muted-foreground min-h-[25vh]"> <div className="flex flex-row gap-2 items-center justify-center text-sm text-muted-foreground min-h-[25vh]">
<span>Loading...</span> <span>Loading...</span>
<Loader2 className="animate-spin size-4" /> <Loader2 className="animate-spin size-4" />
</div> </div>
) : ( ) : (
<> <>
{data?.length === 0 ? ( {data?.length === 0 ? (
<div className="flex flex-col items-center gap-3 min-h-[25vh] justify-center"> <div className="flex flex-col items-center gap-3 min-h-[25vh] justify-center">
<GitBranch className="size-8 self-center text-muted-foreground" /> <GitBranch className="size-8 self-center text-muted-foreground" />
<span className="text-base text-muted-foreground text-center"> <span className="text-base text-muted-foreground text-center">
Create your first Git Provider Create your first Git Provider
</span> </span>
<div> <div>
<div className="flex items-center bg-sidebar p-1 w-full rounded-lg"> <div className="flex items-center bg-sidebar p-1 w-full rounded-lg">
<div className="flex flex-wrap items-center gap-4 p-3.5 rounded-lg bg-background border w-full [&>button]:grow"> <div className="flex flex-wrap items-center gap-4 p-3.5 rounded-lg bg-background border w-full [&>button]:grow">
<AddGithubProvider /> <AddGithubProvider />
<AddGitlabProvider /> <AddGitlabProvider />
<AddBitbucketProvider /> <AddBitbucketProvider />
<AddGiteaProvider /> <AddGiteaProvider />
</div> </div>
</div> </div>
</div> </div>
</div> </div>
) : ( ) : (
<div className="flex flex-col gap-4 min-h-[25vh]"> <div className="flex flex-col gap-4 min-h-[25vh]">
<div className="flex flex-col gap-2 rounded-lg "> <div className="flex flex-col gap-2 rounded-lg ">
<span className="text-base font-medium"> <span className="text-base font-medium">
Available Providers Available Providers
</span> </span>
<div className="flex items-center bg-sidebar p-1 w-full rounded-lg"> <div className="flex items-center bg-sidebar p-1 w-full rounded-lg">
<div className="flex flex-wrap items-center gap-4 p-3.5 rounded-lg bg-background border w-full [&>button]:grow"> <div className="flex flex-wrap items-center gap-4 p-3.5 rounded-lg bg-background border w-full [&>button]:grow">
<AddGithubProvider /> <AddGithubProvider />
<AddGitlabProvider /> <AddGitlabProvider />
<AddBitbucketProvider /> <AddBitbucketProvider />
<AddGiteaProvider /> <AddGiteaProvider />
</div> </div>
</div> </div>
</div> </div>
<div className="flex flex-col gap-4 rounded-lg "> <div className="flex flex-col gap-4 rounded-lg ">
{data?.map((gitProvider, _index) => { {data?.map((gitProvider, _index) => {
const isGithub = gitProvider.providerType === "github"; const isGithub = gitProvider.providerType === "github";
const isGitlab = gitProvider.providerType === "gitlab"; const isGitlab = gitProvider.providerType === "gitlab";
const isBitbucket = const isBitbucket =
gitProvider.providerType === "bitbucket"; gitProvider.providerType === "bitbucket";
const isGitea = gitProvider.providerType === "gitea"; const isGitea = gitProvider.providerType === "gitea";
const haveGithubRequirements = const haveGithubRequirements =
isGithub && isGithub &&
gitProvider.github?.githubPrivateKey && gitProvider.github?.githubPrivateKey &&
gitProvider.github?.githubAppId && gitProvider.github?.githubAppId &&
gitProvider.github?.githubInstallationId; gitProvider.github?.githubInstallationId;
const haveGitlabRequirements = const haveGitlabRequirements =
isGitlab && isGitlab &&
gitProvider.gitlab?.accessToken && gitProvider.gitlab?.accessToken &&
gitProvider.gitlab?.refreshToken; gitProvider.gitlab?.refreshToken;
return ( return (
<div <div
key={gitProvider.gitProviderId} key={gitProvider.gitProviderId}
className="flex items-center justify-between bg-sidebar p-1 w-full rounded-lg" className="flex items-center justify-between bg-sidebar p-1 w-full rounded-lg"
> >
<div className="flex items-center justify-between p-3.5 rounded-lg bg-background border w-full"> <div className="flex items-center justify-between p-3.5 rounded-lg bg-background border w-full">
<div className="flex flex-col items-center justify-between"> <div className="flex flex-col items-center justify-between">
<div className="flex gap-2 flex-row items-center"> <div className="flex gap-2 flex-row items-center">
{isGithub && ( {isGithub && (
<GithubIcon className="size-5" /> <GithubIcon className="size-5" />
)} )}
{isGitlab && ( {isGitlab && (
<GitlabIcon className="size-5" /> <GitlabIcon className="size-5" />
)} )}
{isBitbucket && ( {isBitbucket && (
<BitbucketIcon className="size-5" /> <BitbucketIcon className="size-5" />
)} )}
{isGitea && <GiteaIcon className="size-5" />} {isGitea && <GiteaIcon className="size-5" />}
<div className="flex flex-col gap-1"> <div className="flex flex-col gap-1">
<span className="text-sm font-medium"> <span className="text-sm font-medium">
{gitProvider.name} {gitProvider.name}
</span> </span>
<span className="text-xs text-muted-foreground"> <span className="text-xs text-muted-foreground">
{formatDate( {formatDate(
gitProvider.createdAt, gitProvider.createdAt,
"yyyy-MM-dd hh:mm:ss a", "yyyy-MM-dd hh:mm:ss a",
)} )}
</span> </span>
</div> </div>
</div> </div>
</div> </div>
<div className="flex flex-row gap-1"> <div className="flex flex-row gap-1">
{!haveGithubRequirements && isGithub && ( {!haveGithubRequirements && isGithub && (
<div className="flex flex-col gap-1"> <div className="flex flex-row gap-1 items-center">
<Link <Badge variant="outline" className="text-xs">
href={`${gitProvider?.github?.githubAppName}/installations/new?state=gh_setup:${gitProvider?.github.githubId}`} Action Required
className={buttonVariants({ </Badge>
size: "icon", <Link
variant: "ghost", href={`${gitProvider?.github?.githubAppName}/installations/new?state=gh_setup:${gitProvider?.github.githubId}`}
})} className={buttonVariants({
> size: "icon",
<ImportIcon className="size-4 text-primary" /> variant: "ghost",
</Link> })}
</div> >
)} <ImportIcon className="size-4 text-primary" />
{haveGithubRequirements && isGithub && ( </Link>
<div className="flex flex-col gap-1"> </div>
<Link )}
href={`${gitProvider?.github?.githubAppName}`} {haveGithubRequirements && isGithub && (
target="_blank" <div className="flex flex-col gap-1">
className={buttonVariants({ <Link
size: "icon", href={`${gitProvider?.github?.githubAppName}`}
variant: "ghost", target="_blank"
})} className={buttonVariants({
> size: "icon",
<ExternalLinkIcon className="size-4 text-primary" /> variant: "ghost",
</Link> })}
</div> >
)} <ExternalLinkIcon className="size-4 text-primary" />
{!haveGitlabRequirements && isGitlab && ( </Link>
<div className="flex flex-col gap-1"> </div>
<Link )}
href={getGitlabUrl( {!haveGitlabRequirements && isGitlab && (
gitProvider.gitlab?.applicationId || "", <div className="flex flex-row gap-1 items-center">
gitProvider.gitlab?.gitlabId || "", <Badge variant="outline" className="text-xs">
gitProvider.gitlab?.gitlabUrl, Action Required
)} </Badge>
target="_blank" <Link
className={buttonVariants({ href={getGitlabUrl(
size: "icon", gitProvider.gitlab?.applicationId || "",
variant: "ghost", gitProvider.gitlab?.gitlabId || "",
})} gitProvider.gitlab?.gitlabUrl,
> )}
<ImportIcon className="size-4 text-primary" /> target="_blank"
</Link> className={buttonVariants({
</div> size: "icon",
)} variant: "ghost",
})}
>
<ImportIcon className="size-4 text-primary" />
</Link>
</div>
)}
{isGithub && haveGithubRequirements && ( {isGithub && haveGithubRequirements && (
<EditGithubProvider <EditGithubProvider
githubId={gitProvider.github?.githubId} githubId={gitProvider.github?.githubId}
/> />
)} )}
{isGitlab && ( {isGitlab && (
<EditGitlabProvider <EditGitlabProvider
gitlabId={gitProvider.gitlab?.gitlabId} gitlabId={gitProvider.gitlab?.gitlabId}
/> />
)} )}
{isBitbucket && ( {isBitbucket && (
<EditBitbucketProvider <EditBitbucketProvider
bitbucketId={ bitbucketId={
gitProvider.bitbucket?.bitbucketId gitProvider.bitbucket?.bitbucketId
} }
/> />
)} )}
{isGitea && ( {isGitea && (
<EditGiteaProvider <EditGiteaProvider
giteaId={gitProvider.gitea?.giteaId} giteaId={gitProvider.gitea?.giteaId}
/> />
)} )}
<DialogAction <DialogAction
title="Delete Git Provider" title="Delete Git Provider"
description="Are you sure you want to delete this Git Provider?" description="Are you sure you want to delete this Git Provider?"
type="destructive" type="destructive"
onClick={async () => { onClick={async () => {
await mutateAsync({ await mutateAsync({
gitProviderId: gitProvider.gitProviderId, gitProviderId: gitProvider.gitProviderId,
}) })
.then(() => { .then(() => {
toast.success( toast.success(
"Git Provider deleted successfully", "Git Provider deleted successfully",
); );
refetch(); refetch();
}) })
.catch(() => { .catch(() => {
toast.error( toast.error(
"Error deleting Git Provider", "Error deleting Git Provider",
); );
}); });
}} }}
> >
<Button <Button
variant="ghost" variant="ghost"
size="icon" size="icon"
className="group hover:bg-red-500/10" className="group hover:bg-red-500/10"
isLoading={isRemoving} isLoading={isRemoving}
> >
<Trash2 className="size-4 text-primary group-hover:text-red-500" /> <Trash2 className="size-4 text-primary group-hover:text-red-500" />
</Button> </Button>
</DialogAction> </DialogAction>
</div> </div>
</div> </div>
</div> </div>
); );
})} })}
</div> </div>
<div className="flex flex-row gap-2 flex-wrap w-full justify-end mr-4"> <div className="flex flex-row gap-2 flex-wrap w-full justify-end mr-4">
{/* <AddCertificate /> */} {/* <AddCertificate /> */}
</div> </div>
</div> </div>
)} )}
</> </>
)} )}
</CardContent> </CardContent>
</div> </div>
</Card> </Card>
</div> </div>
); );
}; };