improve: improve template form buttons

This commit is contained in:
Scott Wilson
2024-11-08 14:07:50 -08:00
parent 829ae7d3c0
commit d5f718c6ad
2 changed files with 46 additions and 71 deletions
@@ -1,17 +1,9 @@
import { faEllipsis } from "@fortawesome/free-solid-svg-icons"; import { faPencil, faTrash } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { twMerge } from "tailwind-merge";
import { createNotification } from "@app/components/notifications"; import { createNotification } from "@app/components/notifications";
import { OrgPermissionCan } from "@app/components/permissions"; import { OrgPermissionCan } from "@app/components/permissions";
import { import { Button, DeleteActionModal } from "@app/components/v2";
DeleteActionModal,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
IconButton
} from "@app/components/v2";
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/context"; import { OrgPermissionActions, OrgPermissionSubjects } from "@app/context";
import { usePopUp } from "@app/hooks"; import { usePopUp } from "@app/hooks";
import { TProjectTemplate, useDeleteProjectTemplate } from "@app/hooks/api/projectTemplates"; import { TProjectTemplate, useDeleteProjectTemplate } from "@app/hooks/api/projectTemplates";
@@ -58,39 +50,27 @@ export const EditProjectTemplate = ({ isInfisicalTemplate, projectTemplate, onBa
return ( return (
<> <>
<div className="mb-4 flex items-center justify-between border-b border-bunker-400"> <div className="mb-4 flex items-start justify-between border-b border-bunker-400 pb-4">
<div className="mb-4 flex flex-col"> <div className=" flex flex-col">
<h3 className="text-xl font-semibold">{name}</h3> <h3 className="text-xl font-semibold">{name}</h3>
<h2 className="text-sm text-mineshaft-400">{description || "Project Template"}</h2> <h2 className="text-sm text-mineshaft-400">{description || "Project Template"}</h2>
</div> </div>
{!isInfisicalTemplate && ( {!isInfisicalTemplate && (
<DropdownMenu> <div className="flex gap-2">
<DropdownMenuTrigger asChild>
<IconButton
colorSchema="secondary"
variant="plain"
size="lg"
ariaLabel="More options"
className="mr-2"
>
<FontAwesomeIcon icon={faEllipsis} />
</IconButton>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="p-1">
<OrgPermissionCan <OrgPermissionCan
I={OrgPermissionActions.Edit} I={OrgPermissionActions.Edit}
a={OrgPermissionSubjects.ProjectTemplates} a={OrgPermissionSubjects.ProjectTemplates}
> >
{(isAllowed) => ( {(isAllowed) => (
<DropdownMenuItem <Button
className={twMerge( isDisabled={!isAllowed}
!isAllowed && "pointer-events-none cursor-not-allowed opacity-50" leftIcon={<FontAwesomeIcon icon={faPencil} />}
)} size="xs"
colorSchema="secondary"
onClick={() => handlePopUpOpen("editDetails")} onClick={() => handlePopUpOpen("editDetails")}
disabled={!isAllowed}
> >
Edit Details Edit Details
</DropdownMenuItem> </Button>
)} )}
</OrgPermissionCan> </OrgPermissionCan>
<OrgPermissionCan <OrgPermissionCan
@@ -98,23 +78,20 @@ export const EditProjectTemplate = ({ isInfisicalTemplate, projectTemplate, onBa
a={OrgPermissionSubjects.ProjectTemplates} a={OrgPermissionSubjects.ProjectTemplates}
> >
{(isAllowed) => ( {(isAllowed) => (
<DropdownMenuItem <Button
className={twMerge( isDisabled={!isAllowed}
isAllowed
? "hover:!bg-red-500 hover:!text-white"
: "pointer-events-none cursor-not-allowed opacity-50"
)}
onClick={() => { onClick={() => {
handlePopUpOpen("removeTemplate"); handlePopUpOpen("removeTemplate");
}} }}
disabled={!isAllowed} leftIcon={<FontAwesomeIcon icon={faTrash} />}
size="xs"
colorSchema="danger"
> >
Delete Template Delete Template
</DropdownMenuItem> </Button>
)} )}
</OrgPermissionCan> </OrgPermissionCan>
</DropdownMenuContent> </div>
</DropdownMenu>
)} )}
</div> </div>
<ProjectTemplateEnvironmentsForm <ProjectTemplateEnvironmentsForm
@@ -138,21 +138,19 @@ export const ProjectTemplateEnvironmentsForm = ({
<OrgPermissionCan <OrgPermissionCan
I={OrgPermissionActions.Edit} I={OrgPermissionActions.Edit}
a={OrgPermissionSubjects.ProjectTemplates} a={OrgPermissionSubjects.ProjectTemplates}
renderTooltip
allowedLabel="Add Environment"
> >
{(isAllowed) => ( {(isAllowed) => (
<IconButton <Button
onClick={() => append({ name: "", slug: "" })} onClick={() => append({ name: "", slug: "" })}
colorSchema="primary" colorSchema="secondary"
className="ml-auto" className="ml-auto"
variant="outline_bg" variant="solid"
size="xs" size="xs"
ariaLabel="Add environment" leftIcon={<FontAwesomeIcon icon={faPlus} />}
isDisabled={!isAllowed} isDisabled={!isAllowed}
> >
<FontAwesomeIcon icon={faPlus} /> Add Environment
</IconButton> </Button>
)} )}
</OrgPermissionCan> </OrgPermissionCan>
</div> </div>