Skip to content

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

improvement(frontend): expose AppConnectionForm pending state to creation dialogs (#8838)

Andrew Huangefb619fb4857
diff --git a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/useConnectionCreation.tsx b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/useConnectionCreation.tsx
index fa670b7f55..8e8b1df9cf 100644
--- a/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/useConnectionCreation.tsx
+++ b/frontend/src/pages/cert-manager/CertificateAuthoritiesPage/components/CaInstallCertModal/useConnectionCreation.tsx
@@ -10,12 +10,13 @@ import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { AppConnectionForm } from "@app/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm";
export const useConnectionCreation = (
- app: AppConnection,
+ app: AppConnection | undefined,
onCreated: (connection: TAppConnection) => void
): ComboboxDialogCreationConfig<TAvailableAppConnection> | undefined => {
const { currentProject } = useProject();
const { permission } = useProjectPermission();
const [isDirty, setIsDirty] = useState(false);
+ const [isPending, setIsPending] = useState(false);
const cancelRef = useRef<VoidFunction>(() => {});
// Bumped on dismissal so a create request that resolves after the dialog closed is ignored.
const attemptRef = useRef(0);
@@ -36,6 +37,7 @@ export const useConnectionCreation = (
};
if (
+ !app ||
!permission.can(
ProjectPermissionAppConnectionActions.Create,
ProjectPermissionSub.AppConnections
@@ -52,6 +54,7 @@ export const useConnectionCreation = (
description: "The new connection is selected once it is created.",
emptyLabel: label,
formatLabel: () => label,
+ isPending,
onDismiss: requestCancel,
renderForm: ({ complete, cancel }) => (
<>
@@ -61,6 +64,7 @@ export const useConnectionCreation = (
projectId={currentProject.id}
projectType={currentProject.type}
onDirtyChange={setIsDirty}
+ onPendingChange={setIsPending}
onComplete={(connection) => {
if (attempt !== attemptRef.current) return;
setIsDirty(false);
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx
index fd15440010..903951c669 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx
@@ -180,22 +180,27 @@ type UpdateFormProps = FormProps & {
};
const CreateForm = ({ app, onComplete, projectId, projectType }: CreateFormProps) => {
- const { layout } = useAppConnectionForm();
+ const { layout, onPendingChange } = useAppConnectionForm();
const [pendingFormData, setPendingFormData] = useState<AppConnectionFormData | null>(null);
const [isConfirmSubmitting, setIsConfirmSubmitting] = useState(false);
const createAppConnection = useCreateAppConnection();
const { name: appName } = APP_CONNECTION_MAP[app];
const submitForm = async (formData: AppConnectionFormData) => {
- const connection = await createAppConnection.mutateAsync({
- ...formData,
- projectId
- });
- createNotification({
- text: `Successfully added ${appName} Connection`,
- type: "success"
- });
- onComplete(connection);
+ onPendingChange?.(true);
+ try {
+ const connection = await createAppConnection.mutateAsync({
+ ...formData,
+ projectId
+ });
+ createNotification({
+ text: `Successfully added ${appName} Connection`,
+ type: "success"
+ });
+ onComplete(connection);
+ } finally {
+ onPendingChange?.(false);
+ }
};
const onSubmit = async (formData: AppConnectionFormData) => {
@@ -432,22 +437,27 @@ const CreateForm = ({ app, onComplete, projectId, projectType }: CreateFormProps
};
const UpdateForm = ({ appConnection, onComplete }: UpdateFormProps) => {
- const { layout } = useAppConnectionForm();
+ const { layout, onPendingChange } = useAppConnectionForm();
const [pendingFormData, setPendingFormData] = useState<AppConnectionFormData | null>(null);
const [isConfirmSubmitting, setIsConfirmSubmitting] = useState(false);
const updateAppConnection = useUpdateAppConnection();
const { name: appName } = APP_CONNECTION_MAP[appConnection.app];
const submitForm = async (formData: AppConnectionFormData) => {
- const connection = await updateAppConnection.mutateAsync({
- connectionId: appConnection.id,
- ...formData
- });
- createNotification({
- text: `Successfully updated ${appName} Connection`,
- type: "success"
- });
- onComplete(connection);
+ onPendingChange?.(true);
+ try {
+ const connection = await updateAppConnection.mutateAsync({
+ connectionId: appConnection.id,
+ ...formData
+ });
+ createNotification({
+ text: `Successfully updated ${appName} Connection`,
+ type: "success"
+ });
+ onComplete(connection);
+ } finally {
+ onPendingChange?.(false);
+ }
};
const onSubmit = async (formData: AppConnectionFormData) => {
@@ -747,6 +757,7 @@ const UpdateForm = ({ appConnection, onComplete }: UpdateFormProps) => {
type Props = {
onCancel: () => void;
onDirtyChange?: (isDirty: boolean) => void;
+ onPendingChange?: (isPending: boolean) => void;
layout?: "sheet" | "dialog";
projectId?: string;
projectType?: ProjectType;
@@ -758,6 +769,7 @@ type Props = {
export const AppConnectionForm = ({
onCancel,
onDirtyChange,
+ onPendingChange,
layout = "sheet",
projectId,
projectType,
@@ -766,8 +778,8 @@ export const AppConnectionForm = ({
const { app, appConnection } = props;
const contextValue = useMemo(
- () => ({ onCancel, onDirtyChange, layout }),
- [onCancel, onDirtyChange, layout]
+ () => ({ onCancel, onDirtyChange, onPendingChange, layout }),
+ [onCancel, onDirtyChange, onPendingChange, layout]
);
return (
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionFormContext.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionFormContext.tsx
index 214fdf3a24..b56850dc8d 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionFormContext.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionFormContext.tsx
@@ -7,6 +7,7 @@ type AppConnectionFormContextValue = {
*/
onCancel: () => void;
onDirtyChange?: (isDirty: boolean) => void;
+ onPendingChange?: (isPending: boolean) => void;
layout?: "sheet" | "dialog";
};