Skip to content

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

fix(ui): serialize environment creation with mutations

Andrew Huangf06b78da49a1
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/EnvironmentSection/EnvironmentSection.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/EnvironmentSection/EnvironmentSection.tsx
index 4d423b1538..0366c751e4 100644
--- a/frontend/src/pages/secret-manager/SettingsPage/components/EnvironmentSection/EnvironmentSection.tsx
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/EnvironmentSection/EnvironmentSection.tsx
@@ -46,6 +46,10 @@ export const EnvironmentSection = () => {
const deleteWsEnvironment = useDeleteWsEnvironment();
const [hardDeleteConfirmation, setHardDeleteConfirmation] = useState("");
+ const [isTableMutationPending, setIsTableMutationPending] = useState(false);
+ const [isDeleteSubmitting, setIsDeleteSubmitting] = useState(false);
+
+ const isDeletePending = deleteWsEnvironment.isPending || isDeleteSubmitting;
const isMoreEnvironmentsAllowed =
subscription?.environmentLimit && currentProject?.environments
@@ -69,43 +73,55 @@ export const EnvironmentSection = () => {
| undefined;
const onEnvDeleteSubmit = async () => {
- if (!currentProject?.id || !deleteEnvData?.id || deleteWsEnvironment.isPending) return;
+ if (!currentProject?.id || !deleteEnvData?.id || isDeletePending) return;
- await deleteWsEnvironment.mutateAsync({
- projectId: currentProject.id,
- id: deleteEnvData.id
- });
+ setIsDeleteSubmitting(true);
- createNotification({
- text: "Environment scheduled for deletion",
- type: "success"
- });
+ try {
+ await deleteWsEnvironment.mutateAsync({
+ projectId: currentProject.id,
+ id: deleteEnvData.id
+ });
- handlePopUpClose("deleteEnv");
+ createNotification({
+ text: "Environment scheduled for deletion",
+ type: "success"
+ });
+
+ handlePopUpClose("deleteEnv");
+ } finally {
+ setIsDeleteSubmitting(false);
+ }
};
const onSwitchToHardDelete = () => {
- if (!deleteEnvData || deleteWsEnvironment.isPending) return;
+ if (!deleteEnvData || isDeletePending) return;
handlePopUpClose("deleteEnv");
handlePopUpOpen("hardDeleteEnv", deleteEnvData);
};
const onEnvHardDeleteSubmit = async () => {
- if (!currentProject?.id || !hardDeleteEnvData?.id || deleteWsEnvironment.isPending) return;
+ if (!currentProject?.id || !hardDeleteEnvData?.id || isDeletePending) return;
- await deleteWsEnvironment.mutateAsync({
- projectId: currentProject.id,
- id: hardDeleteEnvData.id,
- hardDelete: true
- });
+ setIsDeleteSubmitting(true);
- createNotification({
- text: "Successfully deleted environment",
- type: "success"
- });
+ try {
+ await deleteWsEnvironment.mutateAsync({
+ projectId: currentProject.id,
+ id: hardDeleteEnvData.id,
+ hardDelete: true
+ });
- handlePopUpClose("hardDeleteEnv");
- setHardDeleteConfirmation("");
+ createNotification({
+ text: "Successfully deleted environment",
+ type: "success"
+ });
+
+ handlePopUpClose("hardDeleteEnv");
+ setHardDeleteConfirmation("");
+ } finally {
+ setIsDeleteSubmitting(false);
+ }
};
return (
@@ -126,14 +142,14 @@ export const EnvironmentSection = () => {
variant="project"
size="sm"
onClick={() => {
- if (deleteWsEnvironment.isPending) return;
+ if (isDeletePending || isTableMutationPending) return;
if (isMoreEnvironmentsAllowed) {
handlePopUpOpen("createEnv");
} else {
handlePopUpOpen("upgradePlan");
}
}}
- isDisabled={!isAllowed || deleteWsEnvironment.isPending}
+ isDisabled={!isAllowed || isDeletePending || isTableMutationPending}
>
<PlusIcon className="size-4" />
Create Environment
@@ -146,7 +162,8 @@ export const EnvironmentSection = () => {
{permission.can(ProjectPermissionActions.Read, ProjectPermissionSub.Environments) ? (
<EnvironmentTable
handlePopUpOpen={handlePopUpOpen}
- isDeletePending={deleteWsEnvironment.isPending}
+ isDeletePending={isDeletePending}
+ onMutationPendingChange={setIsTableMutationPending}
/>
) : (
<PermissionDeniedBanner />
@@ -164,7 +181,7 @@ export const EnvironmentSection = () => {
<AlertDialog
open={popUp.deleteEnv.isOpen}
onOpenChange={(isOpen) => {
- if (!isOpen && deleteWsEnvironment.isPending) return;
+ if (!isOpen && isDeletePending) return;
handlePopUpToggle("deleteEnv", isOpen);
}}
>
@@ -207,18 +224,19 @@ export const EnvironmentSection = () => {
variant="danger"
size="sm"
onClick={onSwitchToHardDelete}
- isDisabled={deleteWsEnvironment.isPending}
+ isDisabled={isDeletePending}
>
Delete Permanently
</Button>
<div className="flex gap-2">
- <AlertDialogCancel isDisabled={deleteWsEnvironment.isPending}>
- Cancel
- </AlertDialogCancel>
+ <AlertDialogCancel isDisabled={isDeletePending}>Cancel</AlertDialogCancel>
<AlertDialogAction
variant="project"
- onClick={onEnvDeleteSubmit}
- isPending={deleteWsEnvironment.isPending}
+ onClick={(event) => {
+ event.preventDefault();
+ onEnvDeleteSubmit().catch(() => undefined);
+ }}
+ isPending={isDeletePending}
>
Confirm
</AlertDialogAction>
@@ -229,7 +247,7 @@ export const EnvironmentSection = () => {
<AlertDialog
open={popUp.hardDeleteEnv.isOpen}
onOpenChange={(isOpen) => {
- if (!isOpen && deleteWsEnvironment.isPending) return;
+ if (!isOpen && isDeletePending) return;
handlePopUpToggle("hardDeleteEnv", isOpen);
if (!isOpen) setHardDeleteConfirmation("");
}}
@@ -265,16 +283,16 @@ export const EnvironmentSection = () => {
value={hardDeleteConfirmation}
onChange={(e) => setHardDeleteConfirmation(e.target.value)}
placeholder={hardDeleteEnvData?.slug ?? ""}
- disabled={deleteWsEnvironment.isPending}
+ disabled={isDeletePending}
/>
</div>
<AlertDialogFooter>
- <AlertDialogCancel isDisabled={deleteWsEnvironment.isPending}>Cancel</AlertDialogCancel>
+ <AlertDialogCancel isDisabled={isDeletePending}>Cancel</AlertDialogCancel>
<Button
variant="danger"
size="sm"
onClick={onEnvHardDeleteSubmit}
- isPending={deleteWsEnvironment.isPending}
+ isPending={isDeletePending}
isDisabled={
!hardDeleteEnvData?.slug || hardDeleteConfirmation !== hardDeleteEnvData.slug
}
diff --git a/frontend/src/pages/secret-manager/SettingsPage/components/EnvironmentSection/EnvironmentTable.tsx b/frontend/src/pages/secret-manager/SettingsPage/components/EnvironmentSection/EnvironmentTable.tsx
index 2b7f8c7a41..6e2f23a5ce 100644
--- a/frontend/src/pages/secret-manager/SettingsPage/components/EnvironmentSection/EnvironmentTable.tsx
+++ b/frontend/src/pages/secret-manager/SettingsPage/components/EnvironmentSection/EnvironmentTable.tsx
@@ -50,6 +50,7 @@ type EnvPayload = { name: string; slug: string; id: string; deleteAfter?: string
type Props = {
handlePopUpOpen: (popUpName: keyof UsePopUpState<[PopUpKeys]>, env: EnvPayload) => void;
isDeletePending: boolean;
+ onMutationPendingChange: (isPending: boolean) => void;
};
const getActorLabel = (actor: ProjectDeletedEnvActor | null): string => {
@@ -78,7 +79,11 @@ const formatRemainingDuration = (target: Date): string | null => {
return nonZero.map(([value, suffix]) => `${value}${suffix}`).join(" ");
};
-export const EnvironmentTable = ({ handlePopUpOpen, isDeletePending }: Props) => {
+export const EnvironmentTable = ({
+ handlePopUpOpen,
+ isDeletePending,
+ onMutationPendingChange
+}: Props) => {
const { currentProject } = useProject();
const { subscription } = useSubscription();
@@ -104,6 +109,7 @@ export const EnvironmentTable = ({ handlePopUpOpen, isDeletePending }: Props) =>
}
setPendingAction({ type: "reorder", id, direction });
+ onMutationPendingChange(true);
try {
await updateEnvironment.mutateAsync({
@@ -118,6 +124,7 @@ export const EnvironmentTable = ({ handlePopUpOpen, isDeletePending }: Props) =>
});
} finally {
setPendingAction(undefined);
+ onMutationPendingChange(false);
}
};
@@ -132,6 +139,7 @@ export const EnvironmentTable = ({ handlePopUpOpen, isDeletePending }: Props) =>
}
setPendingAction({ type: "restore", id });
+ onMutationPendingChange(true);
try {
await restoreEnvironment.mutateAsync({
@@ -151,6 +159,7 @@ export const EnvironmentTable = ({ handlePopUpOpen, isDeletePending }: Props) =>
});
} finally {
setPendingAction(undefined);
+ onMutationPendingChange(false);
}
};