mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-04 02:26:19 +00:00
Merge pull request #2083 from Infisical/secret-sharing-ui-update
This commit is contained in:
@@ -6,12 +6,12 @@ import * as yup from "yup";
|
|||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
import { encryptSymmetric } from "@app/components/utilities/cryptography/crypto";
|
import { encryptSymmetric } from "@app/components/utilities/cryptography/crypto";
|
||||||
import { Button, FormControl, Input, ModalClose, Select, SelectItem } from "@app/components/v2";
|
import { Button, Checkbox, FormControl, Input, ModalClose, Select, SelectItem } from "@app/components/v2";
|
||||||
import { useCreatePublicSharedSecret, useCreateSharedSecret } from "@app/hooks/api/secretSharing";
|
import { useCreatePublicSharedSecret, useCreateSharedSecret } from "@app/hooks/api/secretSharing";
|
||||||
|
|
||||||
const schema = yup.object({
|
const schema = yup.object({
|
||||||
value: yup.string().max(10000).required().label("Shared Secret Value"),
|
value: yup.string().max(10000).required().label("Shared Secret Value"),
|
||||||
expiresAfterViews: yup.number().min(1).required().label("Expires After Views"),
|
expiresAfterSingleView: yup.boolean().required().label("Expires After Views"),
|
||||||
expiresInValue: yup.number().min(1).required().label("Expiration Value"),
|
expiresInValue: yup.number().min(1).required().label("Expiration Value"),
|
||||||
expiresInUnit: yup.string().required().label("Expiration Unit")
|
expiresInUnit: yup.string().required().label("Expiration Unit")
|
||||||
});
|
});
|
||||||
@@ -65,7 +65,7 @@ export const AddShareSecretForm = ({
|
|||||||
value,
|
value,
|
||||||
expiresInValue,
|
expiresInValue,
|
||||||
expiresInUnit,
|
expiresInUnit,
|
||||||
expiresAfterViews
|
expiresAfterSingleView
|
||||||
}: FormData) => {
|
}: FormData) => {
|
||||||
try {
|
try {
|
||||||
const key = crypto.randomBytes(16).toString("hex");
|
const key = crypto.randomBytes(16).toString("hex");
|
||||||
@@ -89,7 +89,7 @@ export const AddShareSecretForm = ({
|
|||||||
tag,
|
tag,
|
||||||
hashedHex,
|
hashedHex,
|
||||||
expiresAt,
|
expiresAt,
|
||||||
expiresAfterViews
|
expiresAfterViews: expiresAfterSingleView ? 1 : 1000
|
||||||
});
|
});
|
||||||
setNewSharedSecret(
|
setNewSharedSecret(
|
||||||
`${window.location.origin}/shared/secret/${id}?key=${encodeURIComponent(
|
`${window.location.origin}/shared/secret/${id}?key=${encodeURIComponent(
|
||||||
@@ -120,9 +120,9 @@ export const AddShareSecretForm = ({
|
|||||||
return (
|
return (
|
||||||
<form className="flex w-full flex-col items-center" onSubmit={handleSubmit(onFormSubmit)}>
|
<form className="flex w-full flex-col items-center" onSubmit={handleSubmit(onFormSubmit)}>
|
||||||
<div
|
<div
|
||||||
className={`${!inModal && "rounded-md border border-mineshaft-600 bg-mineshaft-800 p-6"}`}
|
className={`w-full ${!inModal && "rounded-md border border-mineshaft-600 bg-mineshaft-800 p-6"}`}
|
||||||
>
|
>
|
||||||
<div className="mb-4">
|
<div>
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="value"
|
name="value"
|
||||||
@@ -131,6 +131,7 @@ export const AddShareSecretForm = ({
|
|||||||
label="Shared Secret"
|
label="Shared Secret"
|
||||||
isError={Boolean(error)}
|
isError={Boolean(error)}
|
||||||
errorText={error?.message}
|
errorText={error?.message}
|
||||||
|
className="mb-2"
|
||||||
>
|
>
|
||||||
<textarea
|
<textarea
|
||||||
disabled={isInputDisabled}
|
disabled={isInputDisabled}
|
||||||
@@ -142,39 +143,20 @@ export const AddShareSecretForm = ({
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex w-full flex-row justify-center">
|
<div className="flex w-full flex-row justify-start">
|
||||||
<div className="flex hidden sm:block sm:w-2/6">
|
<div className="flex justify-start">
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name="expiresAfterViews"
|
|
||||||
defaultValue={1}
|
|
||||||
render={({ field, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
className="mb-4 w-full"
|
|
||||||
label="Expires after Views"
|
|
||||||
isError={Boolean(error)}
|
|
||||||
errorText="Please enter a valid number of views"
|
|
||||||
>
|
|
||||||
<Input {...field} type="number" min={1} />
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="sm:w-1/7 mx-auto hidden items-center justify-center px-2 sm:flex">
|
|
||||||
<p className="px-4 text-sm text-gray-400">OR</p>
|
|
||||||
</div>
|
|
||||||
<div className="flex w-full justify-end sm:w-3/6">
|
|
||||||
<div className="flex justify-start">
|
<div className="flex justify-start">
|
||||||
<div className="flex w-full justify-center pr-2">
|
<div className="flex w-full justify-center pr-2">
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="expiresInValue"
|
name="expiresInValue"
|
||||||
defaultValue={10}
|
defaultValue={1}
|
||||||
render={({ field, fieldState: { error } }) => (
|
render={({ field, fieldState: { error } }) => (
|
||||||
<FormControl
|
<FormControl
|
||||||
label="Expires after Time"
|
label="Expires after Time"
|
||||||
isError={Boolean(error)}
|
isError={Boolean(error)}
|
||||||
errorText="Please enter a valid time duration"
|
errorText="Please enter a valid time duration"
|
||||||
|
className="w-32"
|
||||||
>
|
>
|
||||||
<Input {...field} type="number" min={0} />
|
<Input {...field} type="number" min={0} />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@@ -185,7 +167,7 @@ export const AddShareSecretForm = ({
|
|||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="expiresInUnit"
|
name="expiresInUnit"
|
||||||
defaultValue={expirationUnitsAndActions[0].unit}
|
defaultValue={expirationUnitsAndActions[1].unit}
|
||||||
render={({ field: { onChange, ...field }, fieldState: { error } }) => (
|
render={({ field: { onChange, ...field }, fieldState: { error } }) => (
|
||||||
<FormControl label="Unit" errorText={error?.message} isError={Boolean(error)}>
|
<FormControl label="Unit" errorText={error?.message} isError={Boolean(error)}>
|
||||||
<Select
|
<Select
|
||||||
@@ -206,9 +188,47 @@ export const AddShareSecretForm = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="sm:w-1/7 mx-auto hidden items-center justify-center px-6 sm:flex">
|
||||||
|
<p className="px-4 mt-2 text-sm text-gray-400">AND</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center pt-2">
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="expiresAfterViews"
|
||||||
|
defaultValue={1}
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
className="mb-4 w-full hidden"
|
||||||
|
label="Expires after Views"
|
||||||
|
isError={Boolean(error)}
|
||||||
|
errorText="Please enter a valid number of views"
|
||||||
|
>
|
||||||
|
<Input {...field} type="number" min={1} />
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div className="bg-mineshaft-900 py-2 h-max rounded-md border border-mineshaft-600 px-4">
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="expiresAfterSingleView"
|
||||||
|
defaultValue={false}
|
||||||
|
render={({ field: { onBlur, value, onChange } }) => (
|
||||||
|
<Checkbox
|
||||||
|
id="is-single-view"
|
||||||
|
isChecked={value}
|
||||||
|
onCheckedChange={onChange}
|
||||||
|
isDisabled={false}
|
||||||
|
onBlur={onBlur}
|
||||||
|
>
|
||||||
|
Can be viewed only 1 time
|
||||||
|
</Checkbox>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={`flex items-center ${!inModal && "justify-left pt-2"}`}>
|
<div className={`flex items-center ${!inModal && "justify-start pt-2"}`}>
|
||||||
<Button className="mr-4" type="submit" isDisabled={isSubmitting} isLoading={isSubmitting}>
|
<Button className="mr-0" type="submit" isDisabled={isSubmitting} isLoading={isSubmitting}>
|
||||||
{inModal ? "Create" : "Share Secret"}
|
{inModal ? "Create" : "Share Secret"}
|
||||||
</Button>
|
</Button>
|
||||||
{inModal && (
|
{inModal && (
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export const SecretTable = ({
|
|||||||
</Tr>
|
</Tr>
|
||||||
)}
|
)}
|
||||||
{!isLoading && decryptedSecret && (
|
{!isLoading && decryptedSecret && (
|
||||||
<div className="dark relative flex h-full w-full items-center overflow-y-auto border border-mineshaft-700 bg-mineshaft-900 p-2">
|
<div className="dark relative flex h-full w-full items-center overflow-y-auto border border-mineshaft-700 bg-mineshaft-900 rounded-md p-3 pr-2">
|
||||||
<div className="thin-scrollbar flex h-full max-h-44 w-full flex-1 overflow-y-scroll break-words pr-4 dark:[color-scheme:dark]">
|
<div className="thin-scrollbar flex h-full max-h-44 w-full flex-1 overflow-y-scroll break-words pr-4 dark:[color-scheme:dark]">
|
||||||
<div className="align-center flex w-full min-w-full whitespace-pre-line">
|
<div className="align-center flex w-full min-w-full whitespace-pre-line">
|
||||||
{decryptedSecret}
|
{decryptedSecret}
|
||||||
|
|||||||
Reference in New Issue
Block a user