Feat: Copy project slug button

This commit is contained in:
Daniel Hougaard
2024-03-07 02:01:31 +01:00
parent b89925c61c
commit 5dfe62e306
@@ -1,7 +1,5 @@
import { useEffect } from "react"; import { useEffect } from "react";
import { Controller, useForm } from "react-hook-form"; import { Controller, useForm } from "react-hook-form";
import { faCheck, faCopy } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { yupResolver } from "@hookform/resolvers/yup"; import { yupResolver } from "@hookform/resolvers/yup";
import * as yup from "yup"; import * as yup from "yup";
@@ -12,6 +10,8 @@ import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@a
import { useToggle } from "@app/hooks"; import { useToggle } from "@app/hooks";
import { useRenameWorkspace } from "@app/hooks/api"; import { useRenameWorkspace } from "@app/hooks/api";
import { CopyButton } from "./CopyButton";
const formSchema = yup.object({ const formSchema = yup.object({
name: yup.string().required().label("Project Name") name: yup.string().required().label("Project Name")
}); });
@@ -42,7 +42,7 @@ export const ProjectNameChangeSection = () => {
} }
return () => clearTimeout(timer); return () => clearTimeout(timer);
}, [setIsProjectIdCopied]); }, [setIsProjectIdCopied]);
const onFormSubmit = async ({ name }: FormData) => { const onFormSubmit = async ({ name }: FormData) => {
try { try {
@@ -66,35 +66,20 @@ export const ProjectNameChangeSection = () => {
} }
}; };
const copyProjectIdToClipboard = () => {
navigator.clipboard.writeText(currentWorkspace?.id || "");
setIsProjectIdCopied.on();
createNotification({
text: "Copied Project ID to clipboard",
type: "success"
});
}
return ( return (
<form <form
onSubmit={handleSubmit(onFormSubmit)} onSubmit={handleSubmit(onFormSubmit)}
className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4" className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4"
> >
<div className="flex justify-betweens"> <div className="justify-betweens flex">
<h2 className="text-xl font-semibold flex-1 text-mineshaft-100 mb-8">Project Name</h2> <h2 className="mb-8 flex-1 text-xl font-semibold text-mineshaft-100">Project Name</h2>
<div> <div className="space-x-2">
<Button <CopyButton value={currentWorkspace?.slug || ""} hoverText="Click to slug">
colorSchema="secondary" Copy Project Slug
className="group relative" </CopyButton>
leftIcon={<FontAwesomeIcon icon={isProjectIdCopied ? faCheck : faCopy} />} <CopyButton value={currentWorkspace?.id || ""} hoverText="Click to ID">
onClick={copyProjectIdToClipboard}
>
Copy Project ID Copy Project ID
<span className="absolute -left-8 -top-20 hidden w-28 translate-y-full rounded-md bg-bunker-800 py-2 pl-3 text-center text-sm text-gray-400 group-hover:flex group-hover:animate-fadeIn"> </CopyButton>
Click to copy
</span>
</Button>
</div> </div>
</div> </div>