Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Allow project slug edition and refactor frontend components to reduce duplicated code

carlosmonastyrski699e03c1a916
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 1b458175d1..821f91ddcb 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -459,7 +459,8 @@ export const PROJECTS = {
workspaceId: "The ID of the project to update.",
name: "The new name of the project.",
projectDescription: "An optional description label for the project.",
- autoCapitalization: "Disable or enable auto-capitalization for the project."
+ autoCapitalization: "Disable or enable auto-capitalization for the project.",
+ slug: "An optional slug for the project. (must be unique within the server)"
},
GET_KEY: {
workspaceId: "The ID of the project to get the key from."
diff --git a/backend/src/server/routes/v1/project-router.ts b/backend/src/server/routes/v1/project-router.ts
index 68d13842cf..5209dadcf0 100644
--- a/backend/src/server/routes/v1/project-router.ts
+++ b/backend/src/server/routes/v1/project-router.ts
@@ -307,7 +307,13 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
.max(256, { message: "Description must be 256 or fewer characters" })
.optional()
.describe(PROJECTS.UPDATE.projectDescription),
- autoCapitalization: z.boolean().optional().describe(PROJECTS.UPDATE.autoCapitalization)
+ autoCapitalization: z.boolean().optional().describe(PROJECTS.UPDATE.autoCapitalization),
+ slug: z
+ .string()
+ .trim()
+ .max(64, { message: "Slug must be 64 characters or fewer" })
+ .optional()
+ .describe(PROJECTS.UPDATE.slug)
}),
response: {
200: z.object({
@@ -325,7 +331,8 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
update: {
name: req.body.name,
description: req.body.description,
- autoCapitalization: req.body.autoCapitalization
+ autoCapitalization: req.body.autoCapitalization,
+ slug: req.body.slug
},
actorAuthMethod: req.permission.authMethod,
actorId: req.permission.id,
diff --git a/backend/src/services/project/project-service.ts b/backend/src/services/project/project-service.ts
index e1653d3713..4b110ebd27 100644
--- a/backend/src/services/project/project-service.ts
+++ b/backend/src/services/project/project-service.ts
@@ -563,11 +563,24 @@ export const projectServiceFactory = ({
});
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.Settings);
+ if (update.slug) {
+ const existingProject = await projectDAL.findOne({
+ slug: update.slug,
+ orgId: actorOrgId
+ });
+ if (existingProject && existingProject.id !== project.id) {
+ throw new BadRequestError({
+ message: `Failed to update project slug. The project "${existingProject.name}" with the slug "${existingProject.slug}" already exists in your organization. Please choose a unique slug for your project.`
+ });
+ }
+ }
+
const updatedProject = await projectDAL.updateById(project.id, {
name: update.name,
description: update.description,
autoCapitalization: update.autoCapitalization,
- enforceCapitalization: update.autoCapitalization
+ enforceCapitalization: update.autoCapitalization,
+ slug: update.slug
});
return updatedProject;
diff --git a/backend/src/services/project/project-types.ts b/backend/src/services/project/project-types.ts
index 83a59b6af4..5ccf33d23d 100644
--- a/backend/src/services/project/project-types.ts
+++ b/backend/src/services/project/project-types.ts
@@ -82,6 +82,7 @@ export type TUpdateProjectDTO = {
name?: string;
description?: string;
autoCapitalization?: boolean;
+ slug?: string;
};
} & Omit<TProjectPermission, "projectId">;
diff --git a/frontend/src/pages/kms/SettingsPage/components/ProjectOverviewChangeSection/ProjectOverviewChangeSection.tsx b/frontend/src/components/project/ProjectOverviewChangeSection.tsx
similarity index 58%
rename from frontend/src/pages/kms/SettingsPage/components/ProjectOverviewChangeSection/ProjectOverviewChangeSection.tsx
rename to frontend/src/components/project/ProjectOverviewChangeSection.tsx
index d82415c0d9..767f173349 100644
--- a/frontend/src/pages/kms/SettingsPage/components/ProjectOverviewChangeSection/ProjectOverviewChangeSection.tsx
+++ b/frontend/src/components/project/ProjectOverviewChangeSection.tsx
@@ -1,4 +1,4 @@
-import { useEffect } from "react";
+import { useEffect, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
@@ -9,9 +9,7 @@ import { Button, FormControl, Input, TextArea } from "@app/components/v2";
import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@app/context";
import { useUpdateProject } from "@app/hooks/api";
-import { CopyButton } from "./CopyButton";
-
-const formSchema = z.object({
+const baseFormSchema = z.object({
name: z.string().min(1, "Required").max(64, "Too long, maximum length is 64 characters"),
description: z
.string()
@@ -20,33 +18,59 @@ const formSchema = z.object({
.optional()
});
-type FormData = z.infer<typeof formSchema>;
+const formSchemaWithSlug = baseFormSchema.extend({
+ slug: z
+ .string()
+ .min(1, "Required")
+ .max(64, "Too long, maximum length is 64 characters")
+ .regex(/^[a-zA-Z0-9-]+$/, "Only letters, numbers and hyphens are allowed")
+});
-export const ProjectOverviewChangeSection = () => {
+type BaseFormData = z.infer<typeof baseFormSchema>;
+type FormDataWithSlug = z.infer<typeof formSchemaWithSlug>;
+
+type Props = {
+ showSlugField?: boolean;
+};
+
+export const ProjectOverviewChangeSection = ({ showSlugField = false }: Props) => {
const { currentWorkspace } = useWorkspace();
+ const [currentSlug, setCurrentSlug] = useState(currentWorkspace?.slug);
const { mutateAsync, isPending } = useUpdateProject();
- const { handleSubmit, control, reset } = useForm<FormData>({ resolver: zodResolver(formSchema) });
+ const { handleSubmit, control, reset } = useForm<BaseFormData | FormDataWithSlug>({
+ resolver: zodResolver(showSlugField ? formSchemaWithSlug : baseFormSchema)
+ });
useEffect(() => {
if (currentWorkspace) {
reset({
name: currentWorkspace.name,
- description: currentWorkspace.description ?? ""
+ description: currentWorkspace.description ?? "",
+ ...(showSlugField && { slug: currentWorkspace.slug })
});
+ setCurrentSlug(currentWorkspace.slug);
}
- }, [currentWorkspace]);
+ }, [currentWorkspace, showSlugField]);
- const onFormSubmit = async ({ name, description }: FormData) => {
+ const onFormSubmit = async (data: BaseFormData | FormDataWithSlug) => {
try {
if (!currentWorkspace?.id) return;
await mutateAsync({
projectID: currentWorkspace.id,
- newProjectName: name,
- newProjectDescription: description
+ newProjectName: data.name,
+ newProjectDescription: data.description,
+ ...(showSlugField &&
+ "slug" in data && {
+ newSlug: data.slug !== currentWorkspace.slug ? data.slug : undefined
+ })
});
+ if (showSlugField && "slug" in data) {
+ setCurrentSlug(data.slug);
+ }
+
createNotification({
text: "Successfully updated project overview",
type: "success"
@@ -65,20 +89,34 @@ export const ProjectOverviewChangeSection = () => {
<div className="justify-betweens flex">
<h2 className="mb-8 flex-1 text-xl font-semibold text-mineshaft-100">Project Overview</h2>
<div className="space-x-2">
- <CopyButton
- value={currentWorkspace?.slug || ""}
- hoverText="Click to project slug"
- notificationText="Copied project slug to clipboard"
+ <Button
+ variant="outline_bg"
+ size="sm"
+ onClick={() => {
+ navigator.clipboard.writeText(currentSlug || "");
+ createNotification({
+ text: "Copied project slug to clipboard",
+ type: "success"
+ });
+ }}
+ title="Click to copy project slug"
>
Copy Project Slug
- </CopyButton>
- <CopyButton
- value={currentWorkspace?.id || ""}
- hoverText="Click to project ID"
- notificationText="Copied project ID to clipboard"
+ </Button>
+ <Button
+ variant="outline_bg"
+ size="sm"
+ onClick={() => {
+ navigator.clipboard.writeText(currentWorkspace?.id || "");
+ createNotification({
+ text: "Copied project ID to clipboard",
+ type: "success"
+ });
+ }}
+ title="Click to copy project ID"
>
Copy Project ID
- </CopyButton>
+ </Button>
</div>
</div>
<div>
@@ -113,6 +151,38 @@ export const ProjectOverviewChangeSection = () => {
</ProjectPermissionCan>
</div>
</div>
+ {showSlugField && (
+ <div className="flex w-full flex-row items-end gap-4">
+ <div className="w-full max-w-md">
+ <ProjectPermissionCan
+ I={ProjectPermissionActions.Edit}
+ a={ProjectPermissionSub.Project}
+ >
+ {(isAllowed) => (
+ <Controller
+ defaultValue=""
+ render={({ field, fieldState: { error } }) => (
+ <FormControl
+ isError={Boolean(error)}
+ errorText={error?.message}
+ label="Project slug"
+ >
+ <Input
+ placeholder="Project slug"
+ {...field}
+ className="bg-mineshaft-800"
+ isDisabled={!isAllowed}
+ />
+ </FormControl>
+ )}
+ control={control}
+ name="slug"
+ />
+ )}
+ </ProjectPermissionCan>
+ </div>
+ </div>
+ )}
<div className="flex w-full flex-row items-end gap-4">
<div className="w-full max-w-md">
<ProjectPermissionCan
diff --git a/frontend/src/hooks/api/workspace/queries.tsx b/frontend/src/hooks/api/workspace/queries.tsx
index 60867fcf4c..0b154b78b4 100644
--- a/frontend/src/hooks/api/workspace/queries.tsx
+++ b/frontend/src/hooks/api/workspace/queries.tsx
@@ -251,12 +251,13 @@ export const useUpdateProject = () => {
const queryClient = useQueryClient();
return useMutation<Workspace, object, UpdateProjectDTO>({
- mutationFn: async ({ projectID, newProjectName, newProjectDescription }) => {
+ mutationFn: async ({ projectID, newProjectName, newProjectDescription, newSlug }) => {
const { data } = await apiRequest.patch<{ workspace: Workspace }>(
`/api/v1/workspace/${projectID}`,
{
name: newProjectName,
- description: newProjectDescription
+ description: newProjectDescription,
+ slug: newSlug
}
);
return data.workspace;
diff --git a/frontend/src/hooks/api/workspace/types.ts b/frontend/src/hooks/api/workspace/types.ts
index 0510bdbe7b..0980bc715e 100644
--- a/frontend/src/hooks/api/workspace/types.ts
+++ b/frontend/src/hooks/api/workspace/types.ts
@@ -74,6 +74,7 @@ export type UpdateProjectDTO = {
projectID: string;
newProjectName: string;
newProjectDescription?: string;
+ newSlug?: string;
};
export type UpdatePitVersionLimitDTO = { projectSlug: string; pitVersionLimit: number };
diff --git a/frontend/src/pages/cert-manager/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx b/frontend/src/pages/cert-manager/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
index ef684a21b9..41e8107e09 100644
--- a/frontend/src/pages/cert-manager/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
+++ b/frontend/src/pages/cert-manager/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
@@ -1,11 +1,12 @@
+import { ProjectOverviewChangeSection } from "@app/components/project/ProjectOverviewChangeSection";
+
import { AuditLogsRetentionSection } from "../AuditLogsRetentionSection";
import { DeleteProjectSection } from "../DeleteProjectSection";
-import { ProjectOverviewChangeSection } from "../ProjectOverviewChangeSection";
export const ProjectGeneralTab = () => {
return (
<div>
- <ProjectOverviewChangeSection />
+ <ProjectOverviewChangeSection showSlugField />
<AuditLogsRetentionSection />
<DeleteProjectSection />
</div>
diff --git a/frontend/src/pages/cert-manager/SettingsPage/components/ProjectOverviewChangeSection/CopyButton.tsx b/frontend/src/pages/cert-manager/SettingsPage/components/ProjectOverviewChangeSection/CopyButton.tsx
deleted file mode 100644
index 34fe365ec8..0000000000
--- a/frontend/src/pages/cert-manager/SettingsPage/components/ProjectOverviewChangeSection/CopyButton.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-import { useCallback } from "react";
-import { faCheck, faCopy } from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-
-import { createNotification } from "@app/components/notifications";
-import { Button } from "@app/components/v2";
-import { useToggle } from "@app/hooks";
-
-type Props = {
- value: string;
- hoverText: string;
- notificationText: string;
- children: React.ReactNode;
-};
-
-export const CopyButton = ({ value, children, hoverText, notificationText }: Props) => {
- const [isProjectIdCopied, setIsProjectIdCopied] = useToggle(false);
-
- const copyToClipboard = useCallback(() => {
- if (isProjectIdCopied) {
- return;
- }
-
- setIsProjectIdCopied.on();
- navigator.clipboard.writeText(value);
-
- createNotification({
- text: notificationText,
- type: "success"
- });
-
- const timer = setTimeout(() => setIsProjectIdCopied.off(), 2000);
-
- // eslint-disable-next-line consistent-return
- return () => clearTimeout(timer);
- }, [isProjectIdCopied]);
-
- return (
- <Button
- colorSchema="secondary"
- className="group relative"
- leftIcon={<FontAwesomeIcon icon={isProjectIdCopied ? faCheck : faCopy} />}
- onClick={copyToClipboard}
- >
- {children}
- <span className="absolute -left-8 -top-20 hidden translate-y-full justify-center rounded-md bg-bunker-800 px-3 py-2 text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
- {hoverText}
- </span>
- </Button>
- );
-};
diff --git a/frontend/src/pages/cert-manager/SettingsPage/components/ProjectOverviewChangeSection/ProjectOverviewChangeSection.tsx b/frontend/src/pages/cert-manager/SettingsPage/components/ProjectOverviewChangeSection/ProjectOverviewChangeSection.tsx
deleted file mode 100644
index d82415c0d9..0000000000
--- a/frontend/src/pages/cert-manager/SettingsPage/components/ProjectOverviewChangeSection/ProjectOverviewChangeSection.tsx
+++ /dev/null
@@ -1,168 +0,0 @@
-import { useEffect } from "react";
-import { Controller, useForm } from "react-hook-form";
-import { zodResolver } from "@hookform/resolvers/zod";
-import { z } from "zod";
-
-import { createNotification } from "@app/components/notifications";
-import { ProjectPermissionCan } from "@app/components/permissions";
-import { Button, FormControl, Input, TextArea } from "@app/components/v2";
-import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@app/context";
-import { useUpdateProject } from "@app/hooks/api";
-
-import { CopyButton } from "./CopyButton";
-
-const formSchema = z.object({
- name: z.string().min(1, "Required").max(64, "Too long, maximum length is 64 characters"),
- description: z
- .string()
- .trim()
- .max(256, "Description too long, max length is 256 characters")
- .optional()
-});
-
-type FormData = z.infer<typeof formSchema>;
-
-export const ProjectOverviewChangeSection = () => {
- const { currentWorkspace } = useWorkspace();
- const { mutateAsync, isPending } = useUpdateProject();
-
- const { handleSubmit, control, reset } = useForm<FormData>({ resolver: zodResolver(formSchema) });
-
- useEffect(() => {
- if (currentWorkspace) {
- reset({
- name: currentWorkspace.name,
- description: currentWorkspace.description ?? ""
- });
- }
- }, [currentWorkspace]);
-
- const onFormSubmit = async ({ name, description }: FormData) => {
- try {
- if (!currentWorkspace?.id) return;
-
- await mutateAsync({
- projectID: currentWorkspace.id,
- newProjectName: name,
- newProjectDescription: description
- });
-
- createNotification({
- text: "Successfully updated project overview",
- type: "success"
- });
- } catch (err) {
- console.error(err);
- createNotification({
- text: "Failed to update project overview",
- type: "error"
- });
- }
- };
-
- return (
- <div className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
- <div className="justify-betweens flex">
- <h2 className="mb-8 flex-1 text-xl font-semibold text-mineshaft-100">Project Overview</h2>
- <div className="space-x-2">
- <CopyButton
- value={currentWorkspace?.slug || ""}
- hoverText="Click to project slug"
- notificationText="Copied project slug to clipboard"
- >
- Copy Project Slug
- </CopyButton>
- <CopyButton
- value={currentWorkspace?.id || ""}
- hoverText="Click to project ID"
- notificationText="Copied project ID to clipboard"
- >
- Copy Project ID
- </CopyButton>
- </div>
- </div>
- <div>
- <form onSubmit={handleSubmit(onFormSubmit)} className="flex w-full flex-col gap-0">
- <div className="flex w-full flex-row items-end gap-4">
- <div className="w-full max-w-md">
- <ProjectPermissionCan
- I={ProjectPermissionActions.Edit}
- a={ProjectPermissionSub.Project}
- >
- {(isAllowed) => (
- <Controller
- defaultValue=""
- render={({ field, fieldState: { error } }) => (
- <FormControl
- isError={Boolean(error)}
- errorText={error?.message}
- label="Project name"
- >
- <Input
- placeholder="Project name"
- {...field}
- className="bg-mineshaft-800"
- isDisabled={!isAllowed}
- />
- </FormControl>
- )}
- control={control}
- name="name"
- />
- )}
- </ProjectPermissionCan>
- </div>
- </div>
- <div className="flex w-full flex-row items-end gap-4">
- <div className="w-full max-w-md">
- <ProjectPermissionCan
- I={ProjectPermissionActions.Edit}
- a={ProjectPermissionSub.Project}
- >
- {(isAllowed) => (
- <Controller
- defaultValue=""
- render={({ field, fieldState: { error } }) => (
- <FormControl
- isError={Boolean(error)}
- errorText={error?.message}
- label="Project description"
- >
- <TextArea
- placeholder="Project description"
- {...field}
- rows={3}
- className="thin-scrollbar max-w-md !resize-none bg-mineshaft-800"
- isDisabled={!isAllowed}
- />
- </FormControl>
- )}
- control={control}
- name="description"
- />
- )}
- </ProjectPermissionCan>
- </div>
- </div>
- <div>
- <ProjectPermissionCan
- I={ProjectPermissionActions.Edit}
- a={ProjectPermissionSub.Project}
- >
- {(isAllowed) => (
- <Button
- colorSchema="secondary"
- type="submit"
- isLoading={isPending}
- isDisabled={isPending || !isAllowed}
- >
- Save
- </Button>
- )}
- </ProjectPermissionCan>
- </div>
- </form>
- </div>
- </div>
- );
-};
diff --git a/frontend/src/pages/cert-manager/SettingsPage/components/ProjectOverviewChangeSection/index.tsx b/frontend/src/pages/cert-manager/SettingsPage/components/ProjectOverviewChangeSection/index.tsx
deleted file mode 100644
index 66120d7fac..0000000000
--- a/frontend/src/pages/cert-manager/SettingsPage/components/ProjectOverviewChangeSection/index.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { ProjectOverviewChangeSection } from "./ProjectOverviewChangeSection";
diff --git a/frontend/src/pages/cert-manager/SettingsPage/components/index.tsx b/frontend/src/pages/cert-manager/SettingsPage/components/index.tsx
index 2f355dc941..04a624ec2f 100644
--- a/frontend/src/pages/cert-manager/SettingsPage/components/index.tsx
+++ b/frontend/src/pages/cert-manager/SettingsPage/components/index.tsx
@@ -1,2 +1 @@
export { DeleteProjectSection } from "./DeleteProjectSection";
-export { ProjectOverviewChangeSection } from "./ProjectOverviewChangeSection";
diff --git a/frontend/src/pages/kms/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx b/frontend/src/pages/kms/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
index ef684a21b9..41e8107e09 100644
--- a/frontend/src/pages/kms/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
+++ b/frontend/src/pages/kms/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
@@ -1,11 +1,12 @@
+import { ProjectOverviewChangeSection } from "@app/components/project/ProjectOverviewChangeSection";
+
import { AuditLogsRetentionSection } from "../AuditLogsRetentionSection";
import { DeleteProjectSection } from "../DeleteProjectSection";
-import { ProjectOverviewChangeSection } from "../ProjectOverviewChangeSection";
export const ProjectGeneralTab = () => {
return (
<div>
- <ProjectOverviewChangeSection />
+ <ProjectOverviewChangeSection showSlugField />
<AuditLogsRetentionSection />
<DeleteProjectSection />
</div>
diff --git a/frontend/src/pages/kms/SettingsPage/components/ProjectOverviewChangeSection/CopyButton.tsx b/frontend/src/pages/kms/SettingsPage/components/ProjectOverviewChangeSection/CopyButton.tsx
deleted file mode 100644
index 34fe365ec8..0000000000
--- a/frontend/src/pages/kms/SettingsPage/components/ProjectOverviewChangeSection/CopyButton.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-import { useCallback } from "react";
-import { faCheck, faCopy } from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-
-import { createNotification } from "@app/components/notifications";
-import { Button } from "@app/components/v2";
-import { useToggle } from "@app/hooks";
-
-type Props = {
- value: string;
- hoverText: string;
- notificationText: string;
- children: React.ReactNode;
-};
-
-export const CopyButton = ({ value, children, hoverText, notificationText }: Props) => {
- const [isProjectIdCopied, setIsProjectIdCopied] = useToggle(false);
-
- const copyToClipboard = useCallback(() => {
- if (isProjectIdCopied) {
- return;
- }
-
- setIsProjectIdCopied.on();
- navigator.clipboard.writeText(value);
-
- createNotification({
- text: notificationText,
- type: "success"
- });
-
- const timer = setTimeout(() => setIsProjectIdCopied.off(), 2000);
-
- // eslint-disable-next-line consistent-return
- return () => clearTimeout(timer);
- }, [isProjectIdCopied]);
-
- return (
- <Button
- colorSchema="secondary"
- className="group relative"
- leftIcon={<FontAwesomeIcon icon={isProjectIdCopied ? faCheck : faCopy} />}
- onClick={copyToClipboard}
- >
- {children}
- <span className="absolute -left-8 -top-20 hidden translate-y-full justify-center rounded-md bg-bunker-800 px-3 py-2 text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
- {hoverText}
- </span>
- </Button>
- );
-};
diff --git a/frontend/src/pages/kms/SettingsPage/components/ProjectOverviewChangeSection/index.tsx b/frontend/src/pages/kms/SettingsPage/components/ProjectOverviewChangeSection/index.tsx
deleted file mode 100644
index 66120d7fac..0000000000
--- a/frontend/src/pages/kms/SettingsPage/components/ProjectOverviewChangeSection/index.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { ProjectOverviewChangeSection } from "./ProjectOverviewChangeSection";
diff --git a/frontend/src/pages/kms/SettingsPage/components/index.tsx b/frontend/src/pages/kms/SettingsPage/components/index.tsx
index 2f355dc941..04a624ec2f 100644
--- a/frontend/src/pages/kms/SettingsPage/components/index.tsx
+++ b/frontend/src/pages/kms/SettingsPage/components/index.tsx
@@ -1,2 +1 @@
export { DeleteProjectSection } from "./DeleteProjectSection";
-export { ProjectOverviewChangeSection } from "./ProjectOverviewChangeSection";
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
index 698665e470..660eb1dbcf 100644
--- a/frontend/src/pages/secret-manager/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
@@ -1,3 +1,4 @@
+import { ProjectOverviewChangeSection } from "@app/components/project/ProjectOverviewChangeSection";
import { useWorkspace } from "@app/context";
import { ProjectType, ProjectVersion } from "@app/hooks/api/workspace/types";
@@ -7,7 +8,6 @@ import { BackfillSecretReferenceSecretion } from "../BackfillSecretReferenceSect
import { DeleteProjectSection } from "../DeleteProjectSection";
import { EnvironmentSection } from "../EnvironmentSection";
import { PointInTimeVersionLimitSection } from "../PointInTimeVersionLimitSection";
-import { ProjectOverviewChangeSection } from "../ProjectOverviewChangeSection";
import { RebuildSecretIndicesSection } from "../RebuildSecretIndicesSection/RebuildSecretIndicesSection";
import { SecretTagsSection } from "../SecretTagsSection";
@@ -17,7 +17,7 @@ export const ProjectGeneralTab = () => {
return (
<div>
- <ProjectOverviewChangeSection />
+ <ProjectOverviewChangeSection showSlugField />
{isSecretManager && <EnvironmentSection />}
{isSecretManager && <SecretTagsSection />}
{isSecretManager && <AutoCapitalizationSection />}
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/ProjectOverviewChangeSection/CopyButton.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/ProjectOverviewChangeSection/CopyButton.tsx
deleted file mode 100644
index 34fe365ec8..0000000000
--- a/frontend/src/pages/secret-manager/SettingsPage/components/ProjectOverviewChangeSection/CopyButton.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-import { useCallback } from "react";
-import { faCheck, faCopy } from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-
-import { createNotification } from "@app/components/notifications";
-import { Button } from "@app/components/v2";
-import { useToggle } from "@app/hooks";
-
-type Props = {
- value: string;
- hoverText: string;
- notificationText: string;
- children: React.ReactNode;
-};
-
-export const CopyButton = ({ value, children, hoverText, notificationText }: Props) => {
- const [isProjectIdCopied, setIsProjectIdCopied] = useToggle(false);
-
- const copyToClipboard = useCallback(() => {
- if (isProjectIdCopied) {
- return;
- }
-
- setIsProjectIdCopied.on();
- navigator.clipboard.writeText(value);
-
- createNotification({
- text: notificationText,
- type: "success"
- });
-
- const timer = setTimeout(() => setIsProjectIdCopied.off(), 2000);
-
- // eslint-disable-next-line consistent-return
- return () => clearTimeout(timer);
- }, [isProjectIdCopied]);
-
- return (
- <Button
- colorSchema="secondary"
- className="group relative"
- leftIcon={<FontAwesomeIcon icon={isProjectIdCopied ? faCheck : faCopy} />}
- onClick={copyToClipboard}
- >
- {children}
- <span className="absolute -left-8 -top-20 hidden translate-y-full justify-center rounded-md bg-bunker-800 px-3 py-2 text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
- {hoverText}
- </span>
- </Button>
- );
-};
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/ProjectOverviewChangeSection/ProjectOverviewChangeSection.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/ProjectOverviewChangeSection/ProjectOverviewChangeSection.tsx
deleted file mode 100644
index d82415c0d9..0000000000
--- a/frontend/src/pages/secret-manager/SettingsPage/components/ProjectOverviewChangeSection/ProjectOverviewChangeSection.tsx
+++ /dev/null
@@ -1,168 +0,0 @@
-import { useEffect } from "react";
-import { Controller, useForm } from "react-hook-form";
-import { zodResolver } from "@hookform/resolvers/zod";
-import { z } from "zod";
-
-import { createNotification } from "@app/components/notifications";
-import { ProjectPermissionCan } from "@app/components/permissions";
-import { Button, FormControl, Input, TextArea } from "@app/components/v2";
-import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@app/context";
-import { useUpdateProject } from "@app/hooks/api";
-
-import { CopyButton } from "./CopyButton";
-
-const formSchema = z.object({
- name: z.string().min(1, "Required").max(64, "Too long, maximum length is 64 characters"),
- description: z
- .string()
- .trim()
- .max(256, "Description too long, max length is 256 characters")
- .optional()
-});
-
-type FormData = z.infer<typeof formSchema>;
-
-export const ProjectOverviewChangeSection = () => {
- const { currentWorkspace } = useWorkspace();
- const { mutateAsync, isPending } = useUpdateProject();
-
- const { handleSubmit, control, reset } = useForm<FormData>({ resolver: zodResolver(formSchema) });
-
- useEffect(() => {
- if (currentWorkspace) {
- reset({
- name: currentWorkspace.name,
- description: currentWorkspace.description ?? ""
- });
- }
- }, [currentWorkspace]);
-
- const onFormSubmit = async ({ name, description }: FormData) => {
- try {
- if (!currentWorkspace?.id) return;
-
- await mutateAsync({
- projectID: currentWorkspace.id,
- newProjectName: name,
- newProjectDescription: description
- });
-
- createNotification({
- text: "Successfully updated project overview",
- type: "success"
- });
- } catch (err) {
- console.error(err);
- createNotification({
- text: "Failed to update project overview",
- type: "error"
- });
- }
- };
-
- return (
- <div className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
- <div className="justify-betweens flex">
- <h2 className="mb-8 flex-1 text-xl font-semibold text-mineshaft-100">Project Overview</h2>
- <div className="space-x-2">
- <CopyButton
- value={currentWorkspace?.slug || ""}
- hoverText="Click to project slug"
- notificationText="Copied project slug to clipboard"
- >
- Copy Project Slug
- </CopyButton>
- <CopyButton
- value={currentWorkspace?.id || ""}
- hoverText="Click to project ID"
- notificationText="Copied project ID to clipboard"
- >
- Copy Project ID
- </CopyButton>
- </div>
- </div>
- <div>
- <form onSubmit={handleSubmit(onFormSubmit)} className="flex w-full flex-col gap-0">
- <div className="flex w-full flex-row items-end gap-4">
- <div className="w-full max-w-md">
- <ProjectPermissionCan
- I={ProjectPermissionActions.Edit}
- a={ProjectPermissionSub.Project}
- >
- {(isAllowed) => (
- <Controller
- defaultValue=""
- render={({ field, fieldState: { error } }) => (
- <FormControl
- isError={Boolean(error)}
- errorText={error?.message}
- label="Project name"
- >
- <Input
- placeholder="Project name"
- {...field}
- className="bg-mineshaft-800"
- isDisabled={!isAllowed}
- />
- </FormControl>
- )}
- control={control}
- name="name"
- />
- )}
- </ProjectPermissionCan>
- </div>
- </div>
- <div className="flex w-full flex-row items-end gap-4">
- <div className="w-full max-w-md">
- <ProjectPermissionCan
- I={ProjectPermissionActions.Edit}
- a={ProjectPermissionSub.Project}
- >
- {(isAllowed) => (
- <Controller
- defaultValue=""
- render={({ field, fieldState: { error } }) => (
- <FormControl
- isError={Boolean(error)}
- errorText={error?.message}
- label="Project description"
- >
- <TextArea
- placeholder="Project description"
- {...field}
- rows={3}
- className="thin-scrollbar max-w-md !resize-none bg-mineshaft-800"
- isDisabled={!isAllowed}
- />
- </FormControl>
- )}
- control={control}
- name="description"
- />
- )}
- </ProjectPermissionCan>
- </div>
- </div>
- <div>
- <ProjectPermissionCan
- I={ProjectPermissionActions.Edit}
- a={ProjectPermissionSub.Project}
- >
- {(isAllowed) => (
- <Button
- colorSchema="secondary"
- type="submit"
- isLoading={isPending}
- isDisabled={isPending || !isAllowed}
- >
- Save
- </Button>
- )}
- </ProjectPermissionCan>
- </div>
- </form>
- </div>
- </div>
- );
-};
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/ProjectOverviewChangeSection/index.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/ProjectOverviewChangeSection/index.tsx
deleted file mode 100644
index 66120d7fac..0000000000
--- a/frontend/src/pages/secret-manager/SettingsPage/components/ProjectOverviewChangeSection/index.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { ProjectOverviewChangeSection } from "./ProjectOverviewChangeSection";
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/index.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/index.tsx
index 6fb72e4c4a..92bda9d3b7 100644
--- a/frontend/src/pages/secret-manager/SettingsPage/components/index.tsx
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/index.tsx
@@ -2,5 +2,4 @@ export { AutoCapitalizationSection } from "./AutoCapitalizationSection";
export { BackfillSecretReferenceSecretion } from "./BackfillSecretReferenceSection";
export { DeleteProjectSection } from "./DeleteProjectSection";
export { EnvironmentSection } from "./EnvironmentSection";
-export { ProjectOverviewChangeSection } from "./ProjectOverviewChangeSection";
export { SecretTagsSection } from "./SecretTagsSection";
diff --git a/frontend/src/pages/ssh/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx b/frontend/src/pages/ssh/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
index ef684a21b9..41e8107e09 100644
--- a/frontend/src/pages/ssh/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
+++ b/frontend/src/pages/ssh/SettingsPage/components/ProjectGeneralTab/ProjectGeneralTab.tsx
@@ -1,11 +1,12 @@
+import { ProjectOverviewChangeSection } from "@app/components/project/ProjectOverviewChangeSection";
+
import { AuditLogsRetentionSection } from "../AuditLogsRetentionSection";
import { DeleteProjectSection } from "../DeleteProjectSection";
-import { ProjectOverviewChangeSection } from "../ProjectOverviewChangeSection";
export const ProjectGeneralTab = () => {
return (
<div>
- <ProjectOverviewChangeSection />
+ <ProjectOverviewChangeSection showSlugField />
<AuditLogsRetentionSection />
<DeleteProjectSection />
</div>
diff --git a/frontend/src/pages/ssh/SettingsPage/components/ProjectOverviewChangeSection/CopyButton.tsx b/frontend/src/pages/ssh/SettingsPage/components/ProjectOverviewChangeSection/CopyButton.tsx
deleted file mode 100644
index 34fe365ec8..0000000000
--- a/frontend/src/pages/ssh/SettingsPage/components/ProjectOverviewChangeSection/CopyButton.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-import { useCallback } from "react";
-import { faCheck, faCopy } from "@fortawesome/free-solid-svg-icons";
-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-
-import { createNotification } from "@app/components/notifications";
-import { Button } from "@app/components/v2";
-import { useToggle } from "@app/hooks";
-
-type Props = {
- value: string;
- hoverText: string;
- notificationText: string;
- children: React.ReactNode;
-};
-
-export const CopyButton = ({ value, children, hoverText, notificationText }: Props) => {
- const [isProjectIdCopied, setIsProjectIdCopied] = useToggle(false);
-
- const copyToClipboard = useCallback(() => {
- if (isProjectIdCopied) {
- return;
- }
-
- setIsProjectIdCopied.on();
- navigator.clipboard.writeText(value);
-
- createNotification({
- text: notificationText,
- type: "success"
- });
-
- const timer = setTimeout(() => setIsProjectIdCopied.off(), 2000);
-
- // eslint-disable-next-line consistent-return
- return () => clearTimeout(timer);
- }, [isProjectIdCopied]);
-
- return (
- <Button
- colorSchema="secondary"
- className="group relative"
- leftIcon={<FontAwesomeIcon icon={isProjectIdCopied ? faCheck : faCopy} />}
- onClick={copyToClipboard}
- >
- {children}
- <span className="absolute -left-8 -top-20 hidden translate-y-full justify-center rounded-md bg-bunker-800 px-3 py-2 text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn">
- {hoverText}
- </span>
- </Button>
- );
-};
diff --git a/frontend/src/pages/ssh/SettingsPage/components/ProjectOverviewChangeSection/ProjectOverviewChangeSection.tsx b/frontend/src/pages/ssh/SettingsPage/components/ProjectOverviewChangeSection/ProjectOverviewChangeSection.tsx
deleted file mode 100644
index d82415c0d9..0000000000
--- a/frontend/src/pages/ssh/SettingsPage/components/ProjectOverviewChangeSection/ProjectOverviewChangeSection.tsx
+++ /dev/null
@@ -1,168 +0,0 @@
-import { useEffect } from "react";
-import { Controller, useForm } from "react-hook-form";
-import { zodResolver } from "@hookform/resolvers/zod";
-import { z } from "zod";
-
-import { createNotification } from "@app/components/notifications";
-import { ProjectPermissionCan } from "@app/components/permissions";
-import { Button, FormControl, Input, TextArea } from "@app/components/v2";
-import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@app/context";
-import { useUpdateProject } from "@app/hooks/api";
-
-import { CopyButton } from "./CopyButton";
-
-const formSchema = z.object({
- name: z.string().min(1, "Required").max(64, "Too long, maximum length is 64 characters"),
- description: z
- .string()
- .trim()
- .max(256, "Description too long, max length is 256 characters")
- .optional()
-});
-
-type FormData = z.infer<typeof formSchema>;
-
-export const ProjectOverviewChangeSection = () => {
- const { currentWorkspace } = useWorkspace();
- const { mutateAsync, isPending } = useUpdateProject();
-
- const { handleSubmit, control, reset } = useForm<FormData>({ resolver: zodResolver(formSchema) });
-
- useEffect(() => {
- if (currentWorkspace) {
- reset({
- name: currentWorkspace.name,
- description: currentWorkspace.description ?? ""
- });
- }
- }, [currentWorkspace]);
-
- const onFormSubmit = async ({ name, description }: FormData) => {
- try {
- if (!currentWorkspace?.id) return;
-
- await mutateAsync({
- projectID: currentWorkspace.id,
- newProjectName: name,
- newProjectDescription: description
- });
-
- createNotification({
- text: "Successfully updated project overview",
- type: "success"
- });
- } catch (err) {
- console.error(err);
- createNotification({
- text: "Failed to update project overview",
- type: "error"
- });
- }
- };
-
- return (
- <div className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
- <div className="justify-betweens flex">
- <h2 className="mb-8 flex-1 text-xl font-semibold text-mineshaft-100">Project Overview</h2>
- <div className="space-x-2">
- <CopyButton
- value={currentWorkspace?.slug || ""}
- hoverText="Click to project slug"
- notificationText="Copied project slug to clipboard"
- >
- Copy Project Slug
- </CopyButton>
- <CopyButton
- value={currentWorkspace?.id || ""}
- hoverText="Click to project ID"
- notificationText="Copied project ID to clipboard"
- >
- Copy Project ID
- </CopyButton>
- </div>
- </div>
- <div>
- <form onSubmit={handleSubmit(onFormSubmit)} className="flex w-full flex-col gap-0">
- <div className="flex w-full flex-row items-end gap-4">
- <div className="w-full max-w-md">
- <ProjectPermissionCan
- I={ProjectPermissionActions.Edit}
- a={ProjectPermissionSub.Project}
- >
- {(isAllowed) => (
- <Controller
- defaultValue=""
- render={({ field, fieldState: { error } }) => (
- <FormControl
- isError={Boolean(error)}
- errorText={error?.message}
- label="Project name"
- >
- <Input
- placeholder="Project name"
- {...field}
- className="bg-mineshaft-800"
- isDisabled={!isAllowed}
- />
- </FormControl>
- )}
- control={control}
- name="name"
- />
- )}
- </ProjectPermissionCan>
- </div>
- </div>
- <div className="flex w-full flex-row items-end gap-4">
- <div className="w-full max-w-md">
- <ProjectPermissionCan
- I={ProjectPermissionActions.Edit}
- a={ProjectPermissionSub.Project}
- >
- {(isAllowed) => (
- <Controller
- defaultValue=""
- render={({ field, fieldState: { error } }) => (
- <FormControl
- isError={Boolean(error)}
- errorText={error?.message}
- label="Project description"
- >
- <TextArea
- placeholder="Project description"
- {...field}
- rows={3}
- className="thin-scrollbar max-w-md !resize-none bg-mineshaft-800"
- isDisabled={!isAllowed}
- />
- </FormControl>
- )}
- control={control}
- name="description"
- />
- )}
- </ProjectPermissionCan>
- </div>
- </div>
- <div>
- <ProjectPermissionCan
- I={ProjectPermissionActions.Edit}
- a={ProjectPermissionSub.Project}
- >
- {(isAllowed) => (
- <Button
- colorSchema="secondary"
- type="submit"
- isLoading={isPending}
- isDisabled={isPending || !isAllowed}
- >
- Save
- </Button>
- )}
- </ProjectPermissionCan>
- </div>
- </form>
- </div>
- </div>
- );
-};
diff --git a/frontend/src/pages/ssh/SettingsPage/components/ProjectOverviewChangeSection/index.tsx b/frontend/src/pages/ssh/SettingsPage/components/ProjectOverviewChangeSection/index.tsx
deleted file mode 100644
index 66120d7fac..0000000000
--- a/frontend/src/pages/ssh/SettingsPage/components/ProjectOverviewChangeSection/index.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { ProjectOverviewChangeSection } from "./ProjectOverviewChangeSection";
diff --git a/frontend/src/pages/ssh/SettingsPage/components/index.tsx b/frontend/src/pages/ssh/SettingsPage/components/index.tsx
index 2f355dc941..04a624ec2f 100644
--- a/frontend/src/pages/ssh/SettingsPage/components/index.tsx
+++ b/frontend/src/pages/ssh/SettingsPage/components/index.tsx
@@ -1,2 +1 @@
export { DeleteProjectSection } from "./DeleteProjectSection";
-export { ProjectOverviewChangeSection } from "./ProjectOverviewChangeSection";