From b3cf43b46de28dde8a44c495f52b0257fdd7f2f9 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Mon, 28 Oct 2024 10:25:09 -0700 Subject: [PATCH] fix: copy shared secret link to clipboard on generate --- .../components/ShareSecretForm.tsx | 14 +- .../components/PasswordContainer.tsx | 160 +++++++++--------- .../components/SecretContainer.tsx | 2 +- 3 files changed, 90 insertions(+), 86 deletions(-) diff --git a/frontend/src/views/ShareSecretPublicPage/components/ShareSecretForm.tsx b/frontend/src/views/ShareSecretPublicPage/components/ShareSecretForm.tsx index 6aa44f65d..d0f902886 100644 --- a/frontend/src/views/ShareSecretPublicPage/components/ShareSecretForm.tsx +++ b/frontend/src/views/ShareSecretPublicPage/components/ShareSecretForm.tsx @@ -85,18 +85,22 @@ export const ShareSecretForm = ({ isPublic, value }: Props) => { accessType }); - setSecretLink(`${window.location.origin}/shared/secret/${id}`); + const link = `${window.location.origin}/shared/secret/${id}`; + + setSecretLink(link); reset(); + navigator.clipboard.writeText(link); setCopyTextSecret("secret"); + createNotification({ - text: "Successfully created a shared secret", + text: "Shared secret link copied to clipboard.", type: "success" }); } catch (error) { console.error(error); createNotification({ - text: "Failed to create a shared secret", + text: "Failed to create a shared secret.", type: "error" }); } @@ -226,7 +230,7 @@ export const ShareSecretForm = ({ isPublic, value }: Props) => { isLoading={isSubmitting} isDisabled={isSubmitting} > - Create secret link + Create Secret Link ) : ( @@ -253,7 +257,7 @@ export const ShareSecretForm = ({ isPublic, value }: Props) => { onClick={() => setSecretLink("")} rightIcon={} > - Share another secret + Share Another Secret ); diff --git a/frontend/src/views/ViewSecretPublicPage/components/PasswordContainer.tsx b/frontend/src/views/ViewSecretPublicPage/components/PasswordContainer.tsx index edf60447b..a8030a70a 100644 --- a/frontend/src/views/ViewSecretPublicPage/components/PasswordContainer.tsx +++ b/frontend/src/views/ViewSecretPublicPage/components/PasswordContainer.tsx @@ -1,80 +1,80 @@ -import { Controller, useForm } from "react-hook-form"; -import { faArrowRight, faSpinner } from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { z } from "zod"; - -import { Button, FormControl, IconButton, Input } from "@app/components/v2"; - -type Props = { - onPasswordSubmit: (val: any) => void; - isSubmitting?: boolean; - isInvalidCredential?: boolean; -}; - -const formSchema = z.object({ - password: z.string() -}); - -export type FormData = z.infer; - -export const PasswordContainer = ({ - onPasswordSubmit, - isSubmitting, - isInvalidCredential -}: Props) => { - const { control, handleSubmit } = useForm({ - resolver: zodResolver(formSchema) - }); - - const onFormSubmit = async ({ password }: FormData) => { - onPasswordSubmit(password); - }; - - return ( -
-
- ( - -
- -
- - - -
-
-
- )} - /> - - -
- ); -}; +import { Controller, useForm } from "react-hook-form"; +import { faArrowRight, faSpinner } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { z } from "zod"; + +import { Button, FormControl, IconButton, Input } from "@app/components/v2"; + +type Props = { + onPasswordSubmit: (val: any) => void; + isSubmitting?: boolean; + isInvalidCredential?: boolean; +}; + +const formSchema = z.object({ + password: z.string() +}); + +export type FormData = z.infer; + +export const PasswordContainer = ({ + onPasswordSubmit, + isSubmitting, + isInvalidCredential +}: Props) => { + const { control, handleSubmit } = useForm({ + resolver: zodResolver(formSchema) + }); + + const onFormSubmit = async ({ password }: FormData) => { + onPasswordSubmit(password); + }; + + return ( +
+
+ ( + +
+ +
+ + + +
+
+
+ )} + /> + + +
+ ); +}; diff --git a/frontend/src/views/ViewSecretPublicPage/components/SecretContainer.tsx b/frontend/src/views/ViewSecretPublicPage/components/SecretContainer.tsx index f07ebfafd..3130f3c70 100644 --- a/frontend/src/views/ViewSecretPublicPage/components/SecretContainer.tsx +++ b/frontend/src/views/ViewSecretPublicPage/components/SecretContainer.tsx @@ -79,7 +79,7 @@ export const SecretContainer = ({ secret, secretKey: key }: Props) => { onClick={() => window.open("https://app.infisical.com/share-secret", "_blank")} rightIcon={} > - Share your own secret + Share Your Own Secret );