Skip to content

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

improvement(kms): migrate MAC operation form controls to v3 (#8431)

Andrew Huange90587842d4e
diff --git a/frontend/src/pages/kms/OverviewPage/components/CmekGenerateMacModal.tsx b/frontend/src/pages/kms/OverviewPage/components/CmekGenerateMacModal.tsx
index 297fd76308..64eab58c00 100644
--- a/frontend/src/pages/kms/OverviewPage/components/CmekGenerateMacModal.tsx
+++ b/frontend/src/pages/kms/OverviewPage/components/CmekGenerateMacModal.tsx
@@ -1,3 +1,4 @@
+import { useId } from "react";
import { Controller, useForm } from "react-hook-form";
import { faCheckCircle, faFileSignature, faInfoCircle } 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, useCmekGenerateMac } from "@app/hooks/api/cmeks";
@@ -35,6 +39,7 @@ type FormProps = Pick<Props, "cmek">;
const GenerateMacForm = ({ cmek }: FormProps) => {
const cmekGenerateMac = useCmekGenerateMac();
+ const fieldId = useId();
const {
handleSubmit,
@@ -71,40 +76,63 @@ const GenerateMacForm = ({ cmek }: FormProps) => {
return (
<form onSubmit={handleSubmit(handleGenerateMac)}>
{mac ? (
- <FormControl label="Message Authentication Code">
- <TextArea className="max-h-80 min-h-40 max-w-full min-w-full" isDisabled value={mac} />
- </FormControl>
+ <Field className="mb-4">
+ <FieldLabel htmlFor={`${fieldId}-mac`}>Message Authentication Code</FieldLabel>
+ <TextArea id={`${fieldId}-mac`} rows={4} readOnly value={mac} />
+ </Field>
) : (
<>
- <FormControl
- label="Data to Authenticate"
- errorText={errors.data?.message}
- isError={Boolean(errors.data)}
- >
- <TextArea {...register("data")} className="max-h-80 min-h-40 max-w-full min-w-full" />
- </FormControl>
-
- <div className="mb-6 flex w-full items-center justify-end gap-2">
- <Controller
- control={control}
- name="isBase64Encoded"
- render={({ field: { onChange, value } }) => (
- <Switch id="encode-base-64" isChecked={value} onCheckedChange={onChange}>
- 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" />
- </Tooltip>
- </Switch>
- )}
+ <Field className="mb-4" data-invalid={Boolean(errors.data)}>
+ <FieldLabel htmlFor={`${fieldId}-data`}>Data to Authenticate</FieldLabel>
+ <TextArea
+ {...register("data")}
+ id={`${fieldId}-data`}
+ isError={Boolean(errors.data)}
+ aria-describedby={errors.data ? `${fieldId}-data-error` : undefined}
/>
- </div>
+ <FieldError id={`${fieldId}-data-error`} errors={[errors.data]} />
+ </Field>
+
+ <Controller
+ control={control}
+ name="isBase64Encoded"
+ render={({ field: { onChange, value } }) => (
+ <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>
+ </Field>
+ )}
+ />
</>
)}
- <div className="flex items-center">
+ <div className="flex flex-wrap items-center gap-4">
<Button
- className={`mr-4 ${mac ? "w-44" : ""}`}
+ className={mac ? "w-44" : undefined}
size="sm"
- leftIcon={
+ variant="project"
+ onClick={mac ? handleCopyToClipboard : undefined}
+ type={mac ? "button" : "submit"}
+ isPending={isSubmitting}
+ isDisabled={isSubmitting}
+ >
+ {
// eslint-disable-next-line no-nested-ternary
mac ? (
isCopyingMac ? (
@@ -116,17 +144,10 @@ const GenerateMacForm = ({ cmek }: FormProps) => {
<FontAwesomeIcon icon={faFileSignature} />
)
}
- onClick={mac ? handleCopyToClipboard : undefined}
- type={mac ? "button" : "submit"}
- isLoading={isSubmitting}
- isDisabled={isSubmitting}
- >
{mac ? copyMac : "Generate MAC"}
</Button>
<ModalClose asChild>
- <Button colorSchema="secondary" variant="plain">
- {mac ? "Close" : "Cancel"}
- </Button>
+ <Button variant="ghost">{mac ? "Close" : "Cancel"}</Button>
</ModalClose>
</div>
</form>
diff --git a/frontend/src/pages/kms/OverviewPage/components/CmekVerifyMacModal.tsx b/frontend/src/pages/kms/OverviewPage/components/CmekVerifyMacModal.tsx
index d364b9b6a6..718cd5776b 100644
--- a/frontend/src/pages/kms/OverviewPage/components/CmekVerifyMacModal.tsx
+++ b/frontend/src/pages/kms/OverviewPage/components/CmekVerifyMacModal.tsx
@@ -1,3 +1,4 @@
+import { useId } from "react";
import { Controller, useForm } from "react-hook-form";
import { faFileSignature, faInfoCircle } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@@ -5,17 +6,20 @@ 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 {
+ Badge,
Button,
- FormControl,
- Modal,
- ModalClose,
- ModalContent,
- Switch,
+ Field,
+ FieldError,
+ FieldLabel,
+ IconButton,
TextArea,
- Tooltip
-} from "@app/components/v2";
-import { Badge } from "@app/components/v3";
+ Toggle,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger
+} from "@app/components/v3";
import { TCmek, useCmekVerifyMac } from "@app/hooks/api/cmeks";
import { isBase64 } from "@app/lib/fn/base64";
@@ -47,6 +51,7 @@ type FormProps = Pick<Props, "cmek">;
const VerifyMacForm = ({ cmek }: FormProps) => {
const cmekVerifyMac = useCmekVerifyMac();
+ const fieldId = useId();
const {
handleSubmit,
@@ -86,16 +91,17 @@ const VerifyMacForm = ({ cmek }: FormProps) => {
<div className="mb-6 flex flex-col gap-2">
<div className="flex items-center justify-between space-x-2">
<span className="text-sm opacity-60">MAC Status:</span>
- <Tooltip
- content={
- macValid
+ <Tooltip hoverable selectable={false} delayDuration={50}>
+ <TooltipTrigger asChild>
+ <Badge variant={macValid ? "success" : "danger"} tabIndex={0}>
+ {macValid ? "Valid" : "Invalid"}
+ </Badge>
+ </TooltipTrigger>
+ <TooltipContent className="max-w-xs" sideOffset={5}>
+ {macValid
? "The MAC is valid. It was generated using the same key as the one used to verify it."
- : "The MAC is invalid. It was not generated using the same key as the one used to verify it, or the data has been tampered with."
- }
- >
- <Badge variant={macValid ? "success" : "danger"}>
- {macValid ? "Valid" : "Invalid"}
- </Badge>
+ : "The MAC is invalid. It was not generated using the same key as the one used to verify it, or the data has been tampered with."}
+ </TooltipContent>
</Tooltip>
</div>
@@ -106,57 +112,85 @@ const VerifyMacForm = ({ cmek }: FormProps) => {
</div>
) : (
<>
- <FormControl
- label="Data to Verify"
- errorText={errors.data?.message}
- isError={Boolean(errors.data)}
- >
- <TextArea {...register("data")} className="max-h-80 min-h-40 max-w-full min-w-full" />
- </FormControl>
-
- <FormControl
- label="Message Authentication Code"
- tooltipText="Must be base64-encoded, like the MAC you received when you generated it."
- errorText={errors.mac?.message}
- isError={Boolean(errors.mac)}
- >
- <TextArea {...register("mac")} className="max-h-80 min-h-40 max-w-full min-w-full" />
- </FormControl>
+ <Field className="mb-4" data-invalid={Boolean(errors.data)}>
+ <FieldLabel htmlFor={`${fieldId}-data`}>Data to Verify</FieldLabel>
+ <TextArea
+ {...register("data")}
+ id={`${fieldId}-data`}
+ isError={Boolean(errors.data)}
+ aria-describedby={errors.data ? `${fieldId}-data-error` : undefined}
+ />
+ <FieldError id={`${fieldId}-data-error`} errors={[errors.data]} />
+ </Field>
- <div className="mb-6 flex w-full items-center justify-end gap-2">
- <Controller
- control={control}
- name="isBase64Encoded"
- render={({ field: { onChange, value } }) => (
- <Switch id="encode-base-64" isChecked={value} onCheckedChange={onChange}>
- Data is Base64 encoded{" "}
- <Tooltip content="Toggle this switch on if your data is already Base64 encoded to avoid redundant encoding.">
+ <Field className="mb-4" data-invalid={Boolean(errors.mac)}>
+ <div className="flex items-center gap-1">
+ <FieldLabel htmlFor={`${fieldId}-mac`}>Message Authentication Code</FieldLabel>
+ <Tooltip hoverable selectable={false} delayDuration={50}>
+ <TooltipTrigger asChild>
+ <IconButton variant="ghost" size="2xs" aria-label="About MAC encoding">
<FontAwesomeIcon icon={faInfoCircle} className="text-muted" />
- </Tooltip>
- </Switch>
- )}
+ </IconButton>
+ </TooltipTrigger>
+ <TooltipContent className="max-w-xs" sideOffset={5}>
+ Must be base64-encoded, like the MAC you received when you generated it.
+ </TooltipContent>
+ </Tooltip>
+ </div>
+ <TextArea
+ {...register("mac")}
+ id={`${fieldId}-mac`}
+ isError={Boolean(errors.mac)}
+ aria-describedby={errors.mac ? `${fieldId}-mac-error` : undefined}
/>
- </div>
+ <FieldError id={`${fieldId}-mac-error`} errors={[errors.mac]} />
+ </Field>
+
+ <Controller
+ control={control}
+ name="isBase64Encoded"
+ render={({ field: { onChange, value } }) => (
+ <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>
+ </Field>
+ )}
+ />
</>
)}
- <div className="flex items-center">
+ <div className="flex flex-wrap items-center gap-4">
{macValid === undefined && (
<Button
- className="mr-4 w-44"
+ className="w-44"
size="sm"
- leftIcon={<FontAwesomeIcon icon={faFileSignature} />}
+ variant="project"
type="submit"
- isLoading={isSubmitting}
+ isPending={isSubmitting}
isDisabled={isSubmitting}
>
+ <FontAwesomeIcon icon={faFileSignature} />
Verify MAC
</Button>
)}
<ModalClose asChild>
- <Button
- colorSchema={macValid === undefined ? "secondary" : "primary"}
- variant={macValid === undefined ? "plain" : undefined}
- >
+ <Button variant={macValid === undefined ? "ghost" : "project"}>
{macValid !== undefined ? "Close" : "Cancel"}
</Button>
</ModalClose>