Skip to content
Prev Previous commit
Next Next commit
chore: hide create workspace button on template header
  • Loading branch information
jaaydenh committed Apr 2, 2025
commit ff77fe9886883b7e10d64ae1838b3092c25835ff
11 changes: 9 additions & 2 deletions site/src/pages/TemplatePage/TemplateLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { API } from "api/api";
import { organizationsPermissions } from "api/queries/organizations";
import type { AuthorizationRequest } from "api/typesGenerated";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { Loader } from "components/Loader/Loader";
Expand Down Expand Up @@ -77,6 +78,9 @@ export const TemplateLayout: FC<PropsWithChildren> = ({
queryKey: ["template", templateName],
queryFn: () => fetchTemplate(organizationName, templateName),
});
const orgPermissionsQuery = useQuery(
organizationsPermissions([organizationName]),
);
const location = useLocation();
const paths = location.pathname.split("/");
const activeTab = paths.at(-1) === templateName ? "summary" : paths.at(-1)!;
Expand All @@ -85,24 +89,27 @@ export const TemplateLayout: FC<PropsWithChildren> = ({
const shouldShowInsights =
data?.permissions?.canUpdateTemplate || data?.permissions?.canReadInsights;

if (error) {
if (error || orgPermissionsQuery.error) {
return (
<div css={{ margin: 16 }}>
<ErrorAlert error={error} />
</div>
);
}

if (isLoading || !data) {
if (isLoading || !data || !orgPermissionsQuery.data) {
return <Loader />;
}

const orgPermissions = orgPermissionsQuery.data?.[organizationName];

return (
<>
<TemplatePageHeader
template={data.template}
activeVersion={data.activeVersion}
permissions={data.permissions}
orgPermissions={orgPermissions}
onDeleteTemplate={() => {
navigate("/templates");
}}
Expand Down
5 changes: 4 additions & 1 deletion site/src/pages/TemplatePage/TemplatePageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { Pill } from "components/Pill/Pill";
import { Stack } from "components/Stack/Stack";
import { linkToTemplate, useLinks } from "modules/navigation";
import type { OrganizationPermissions } from "modules/permissions/organizations";
import type { FC } from "react";
import { useQuery } from "react-query";
import { Link as RouterLink, useNavigate } from "react-router-dom";
Expand Down Expand Up @@ -158,13 +159,15 @@ export type TemplatePageHeaderProps = {
template: Template;
activeVersion: TemplateVersion;
permissions: AuthorizationResponse;
orgPermissions: OrganizationPermissions;
onDeleteTemplate: () => void;
};

export const TemplatePageHeader: FC<TemplatePageHeaderProps> = ({
template,
activeVersion,
permissions,
orgPermissions,
onDeleteTemplate,
}) => {
const getLink = useLinks();
Expand All @@ -177,7 +180,7 @@ export const TemplatePageHeader: FC<TemplatePageHeaderProps> = ({
<PageHeader
actions={
<>
{!template.deprecated && (
{!template.deprecated && orgPermissions.createWorkspaces && (
<Button
variant="contained"
startIcon={<AddIcon />}
Expand Down