Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
improvement(kms): migrate encrypt and decrypt form controls to v3 (#8426)
Andrew Huang680ab0f7d2c6
diff --git a/frontend/src/pages/kms/OverviewPage/components/CmekDecryptModal.tsx b/frontend/src/pages/kms/OverviewPage/components/CmekDecryptModal.tsxindex 3920bd0b46..f77fe8f58f 100644--- a/frontend/src/pages/kms/OverviewPage/components/CmekDecryptModal.tsx+++ b/frontend/src/pages/kms/OverviewPage/components/CmekDecryptModal.tsx@@ -1,4 +1,4 @@-import { useEffect, useState } from "react";+import { useEffect, useId, useState } from "react";import { useForm } from "react-hook-form";import { faCheckCircle, faCopy, faInfoCircle, faLockOpen } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";@@ -7,16 +7,19 @@ import { z } from "zod";import { createNotification } from "@app/components/notifications";import { decodeBase64 } from "@app/components/utilities/cryptography/crypto";+import { Modal, ModalClose, ModalContent } from "@app/components/v2";import {Button,- FormControl,- Modal,- ModalClose,- ModalContent,- Switch,+ Field,+ FieldError,+ FieldLabel,+ IconButton,TextArea,- Tooltip-} from "@app/components/v2";+ Toggle,+ Tooltip,+ TooltipContent,+ TooltipTrigger+} from "@app/components/v3";import { useTimedReset } from "@app/hooks";import { TCmek, useCmekDecrypt } from "@app/hooks/api/cmeks";@@ -36,6 +39,7 @@ type FormProps = Pick<Props, "cmek">;const DecryptForm = ({ cmek }: FormProps) => {const cmekDecrypt = useCmekDecrypt();+ const fieldId = useId();const [shouldDecode, setShouldDecode] = useState(false);const [plaintext, setPlaintext] = useState("");@@ -79,41 +83,51 @@ const DecryptForm = ({ cmek }: FormProps) => {return (<form onSubmit={handleSubmit(handleDecryptData)}>{plaintext ? (- <FormControl label="Decrypted Data (plaintext)">- <TextArea- className="max-h-80 min-h-40 max-w-full min-w-full"- isDisabled- value={plaintext}- />- </FormControl>+ <Field className="mb-4">+ <FieldLabel htmlFor={`${fieldId}-plaintext`}>Decrypted Data (plaintext)</FieldLabel>+ <TextArea id={`${fieldId}-plaintext`} rows={4} readOnly value={plaintext} />+ </Field>) : (- <FormControl- label="Encrypted Data (ciphertext)"- errorText={errors.ciphertext?.message}- isError={Boolean(errors.ciphertext)}- >+ <Field className="mb-4" data-invalid={Boolean(errors.ciphertext)}>+ <FieldLabel htmlFor={`${fieldId}-ciphertext`}>Encrypted Data (ciphertext)</FieldLabel><TextArea{...register("ciphertext")}- className="max-h-80 min-h-40 max-w-full min-w-full"+ id={`${fieldId}-ciphertext`}+ isError={Boolean(errors.ciphertext)}+ aria-describedby={errors.ciphertext ? `${fieldId}-ciphertext-error` : undefined}/>- </FormControl>+ <FieldError id={`${fieldId}-ciphertext-error`} errors={[errors.ciphertext]} />+ </Field>)}- <Switch- id="decode-base-64"- isChecked={shouldDecode}- onCheckedChange={setShouldDecode}- containerClassName="mb-6 ml-0.5 -mt-2.5"- >- Decode Base64{" "}- <Tooltip content="Toggle this switch on if your data was originally plain text.">- <FontAwesomeIcon icon={faInfoCircle} className="text-muted" />+ <Field orientation="horizontal" className="mb-6">+ <Toggle+ id={`${fieldId}-decode-base-64`}+ checked={shouldDecode}+ onCheckedChange={setShouldDecode}+ />+ <FieldLabel htmlFor={`${fieldId}-decode-base-64`}>Decode Base64</FieldLabel>+ <Tooltip hoverable selectable={false} delayDuration={50}>+ <TooltipTrigger asChild>+ <IconButton variant="ghost" size="xs" aria-label="About Base64 decoding">+ <FontAwesomeIcon icon={faInfoCircle} className="text-muted" />+ </IconButton>+ </TooltipTrigger>+ <TooltipContent className="max-w-xs" sideOffset={5}>+ Toggle this switch on if your data was originally plain text.+ </TooltipContent></Tooltip>- </Switch>- <div className="flex items-center">+ </Field>+ <div className="flex flex-wrap items-center gap-4"><Button- className={`mr-4 ${plaintext ? "w-44" : ""}`}+ className={plaintext ? "w-44" : undefined}size="sm"- leftIcon={+ variant="project"+ onClick={plaintext ? handleCopyToClipboard : undefined}+ type={plaintext ? "button" : "submit"}+ isPending={isSubmitting}+ isDisabled={isSubmitting}+ >+ {// eslint-disable-next-line no-nested-ternaryplaintext ? (isCopyingCiphertext ? (@@ -125,17 +139,10 @@ const DecryptForm = ({ cmek }: FormProps) => {<FontAwesomeIcon icon={faLockOpen} />)}- onClick={plaintext ? handleCopyToClipboard : undefined}- type={plaintext ? "button" : "submit"}- isLoading={isSubmitting}- isDisabled={isSubmitting}- >{plaintext ? copyCiphertext : "Decrypt"}</Button><ModalClose asChild>- <Button colorSchema="secondary" variant="plain">- {plaintext ? "Close" : "Cancel"}- </Button>+ <Button variant="ghost">{plaintext ? "Close" : "Cancel"}</Button></ModalClose></div></form>diff --git a/frontend/src/pages/kms/OverviewPage/components/CmekEncryptModal.tsx b/frontend/src/pages/kms/OverviewPage/components/CmekEncryptModal.tsxindex 02ff76eb49..06b4351de1 100644--- a/frontend/src/pages/kms/OverviewPage/components/CmekEncryptModal.tsx+++ b/frontend/src/pages/kms/OverviewPage/components/CmekEncryptModal.tsx@@ -1,3 +1,4 @@+import { useId } from "react";import { Controller, useForm } from "react-hook-form";import { faCheckCircle, faCopy, faInfoCircle, faLock } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";@@ -5,16 +6,19 @@ import { zodResolver } from "@hookform/resolvers/zod";import { z } from "zod";import { createNotification } from "@app/components/notifications";+import { Modal, ModalClose, ModalContent } from "@app/components/v2";import {Button,- FormControl,- Modal,- ModalClose,- ModalContent,- Switch,+ Field,+ FieldError,+ FieldLabel,+ IconButton,TextArea,- Tooltip-} from "@app/components/v2";+ Toggle,+ Tooltip,+ TooltipContent,+ TooltipTrigger+} from "@app/components/v3";import { useTimedReset } from "@app/hooks";import { TCmek, useCmekEncrypt } from "@app/hooks/api/cmeks";@@ -35,6 +39,7 @@ type FormProps = Pick<Props, "cmek">;const EncryptForm = ({ cmek }: FormProps) => {const cmekEncrypt = useCmekEncrypt();+ const fieldId = useId();const {handleSubmit,@@ -71,49 +76,67 @@ const EncryptForm = ({ cmek }: FormProps) => {return (<form onSubmit={handleSubmit(handleEncryptData)}>{ciphertext ? (- <FormControl label="Encrypted Data (Ciphertext)">+ <Field className="mb-4">+ <FieldLabel htmlFor={`${fieldId}-ciphertext`}>Encrypted Data (Ciphertext)</FieldLabel><TextArea- className="max-h-80 min-h-40 max-w-full min-w-full"- isDisabled+ id={`${fieldId}-ciphertext`}+ rows={4}+ readOnlyvalue={cmekEncrypt.data?.ciphertext}/>- </FormControl>+ </Field>) : (<>- <FormControl- label="Data (Plaintext)"- errorText={errors.plaintext?.message}- isError={Boolean(errors.plaintext)}- >+ <Field className="mb-4" data-invalid={Boolean(errors.plaintext)}>+ <FieldLabel htmlFor={`${fieldId}-plaintext`}>Data (Plaintext)</FieldLabel><TextArea{...register("plaintext")}- className="max-h-80 min-h-40 max-w-full min-w-full"+ id={`${fieldId}-plaintext`}+ isError={Boolean(errors.plaintext)}+ aria-describedby={errors.plaintext ? `${fieldId}-plaintext-error` : undefined}/>- </FormControl>+ <FieldError id={`${fieldId}-plaintext-error`} errors={[errors.plaintext]} />+ </Field><Controllercontrol={control}name="isBase64Encoded"render={({ field: { onChange, value } }) => (- <Switch- id="encode-base-64"- isChecked={value}- onCheckedChange={onChange}- containerClassName="mb-6 ml-0.5 -mt-2.5"- >- Data is Base64 encoded{" "}- <Tooltip content="Toggle this switch on if your data is already Base64 encoded to avoid redundant encoding.">- <FontAwesomeIcon icon={faInfoCircle} className="text-muted" />+ <Field orientation="horizontal" className="mb-6">+ <Toggle+ id={`${fieldId}-encode-base-64`}+ checked={value}+ onCheckedChange={onChange}+ />+ <FieldLabel htmlFor={`${fieldId}-encode-base-64`}>+ Data is Base64 encoded+ </FieldLabel>+ <Tooltip hoverable selectable={false} delayDuration={50}>+ <TooltipTrigger asChild>+ <IconButton variant="ghost" size="xs" aria-label="About Base64 encoding">+ <FontAwesomeIcon icon={faInfoCircle} className="text-muted" />+ </IconButton>+ </TooltipTrigger>+ <TooltipContent className="max-w-xs" sideOffset={5}>+ Toggle this switch on if your data is already Base64 encoded to avoid redundant+ encoding.+ </TooltipContent></Tooltip>- </Switch>+ </Field>)}/></>)}- <div className="flex items-center">+ <div className="flex flex-wrap items-center gap-4"><Button- className={`mr-4 ${ciphertext ? "w-44" : ""}`}+ className={ciphertext ? "w-44" : undefined}size="sm"- leftIcon={+ variant="project"+ onClick={ciphertext ? handleCopyToClipboard : undefined}+ type={ciphertext ? "button" : "submit"}+ isPending={isSubmitting}+ isDisabled={isSubmitting}+ >+ {// eslint-disable-next-line no-nested-ternaryciphertext ? (isCopyingCiphertext ? (@@ -125,17 +148,10 @@ const EncryptForm = ({ cmek }: FormProps) => {<FontAwesomeIcon icon={faLock} />)}- onClick={ciphertext ? handleCopyToClipboard : undefined}- type={ciphertext ? "button" : "submit"}- isLoading={isSubmitting}- isDisabled={isSubmitting}- >{ciphertext ? copyCiphertext : "Encrypt"}</Button><ModalClose asChild>- <Button colorSchema="secondary" variant="plain">- {ciphertext ? "Close" : "Cancel"}- </Button>+ <Button variant="ghost">{ciphertext ? "Close" : "Cancel"}</Button></ModalClose></div></form>