@@ -20,7 +20,15 @@ import {
2020import { json } from "@remix-run/server-runtime" ;
2121import { useVirtualizer } from "@tanstack/react-virtual" ;
2222import { fromPromise } from "neverthrow" ;
23- import { useEffect , useLayoutEffect , useMemo , useRef , useState , type RefObject } from "react" ;
23+ import {
24+ useEffect ,
25+ useLayoutEffect ,
26+ useMemo ,
27+ useRef ,
28+ useState ,
29+ type FormEvent ,
30+ type RefObject ,
31+ } from "react" ;
2432import { typedjson , useTypedLoaderData } from "remix-typedjson" ;
2533import { z } from "zod" ;
2634import { UserAvatar } from "~/components/UserProfilePhoto" ;
@@ -815,6 +823,26 @@ function EditEnvironmentVariablePanel({
815823
816824 const isLoading = fetcher . state !== "idle" ;
817825
826+ function handleOpenChange ( open : boolean ) {
827+ if ( open ) {
828+ setIsSecret ( variable . isSecret ) ;
829+ }
830+
831+ setIsOpen ( open ) ;
832+ }
833+
834+ function handleSubmit ( event : FormEvent < HTMLFormElement > ) {
835+ if (
836+ isSecret &&
837+ ! variable . isSecret &&
838+ ! window . confirm (
839+ "Making this variable secret is irreversible. The value will be hidden and cannot be revealed again. Continue?"
840+ )
841+ ) {
842+ event . preventDefault ( ) ;
843+ }
844+ }
845+
818846 // Close dialog on successful submission
819847 useEffect ( ( ) => {
820848 if ( lastSubmission ?. success && fetcher . state === "idle" ) {
@@ -834,13 +862,13 @@ function EditEnvironmentVariablePanel({
834862 } ) ;
835863
836864 return (
837- < Dialog open = { isOpen } onOpenChange = { setIsOpen } >
865+ < Dialog open = { isOpen } onOpenChange = { handleOpenChange } >
838866 < DialogTrigger asChild >
839867 < Button variant = "small-menu-item" LeadingIcon = { PencilSquareIcon } fullWidth textAlignLeft />
840868 </ DialogTrigger >
841869 < DialogContent >
842870 < DialogHeader > Edit environment variable</ DialogHeader >
843- < fetcher . Form method = "post" { ...getFormProps ( form ) } >
871+ < fetcher . Form method = "post" { ...getFormProps ( form ) } onSubmit = { handleSubmit } >
844872 < input type = "hidden" name = "action" value = "edit" />
845873 < input type = "hidden" name = "isSecret" value = { isSecret ? "true" : "false" } />
846874 < input { ...getInputProps ( id , { type : "hidden" } ) } value = { variable . id } />
@@ -898,7 +926,11 @@ function EditEnvironmentVariablePanel({
898926 </ Button >
899927 }
900928 cancelButton = {
901- < Button onClick = { ( ) => setIsOpen ( false ) } variant = "tertiary/medium" type = "button" >
929+ < Button
930+ onClick = { ( ) => handleOpenChange ( false ) }
931+ variant = "tertiary/medium"
932+ type = "button"
933+ >
902934 Cancel
903935 </ Button >
904936 }
0 commit comments