Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix health check bug that reset form state
Andrey84e5495cb4cf
diff --git a/frontend/src/pages/pam/PamAccountsPage/components/CredentialHealthSection.tsx b/frontend/src/pages/pam/PamAccountsPage/components/CredentialHealthSection.tsxindex cc21b99393..09c765fd50 100644--- a/frontend/src/pages/pam/PamAccountsPage/components/CredentialHealthSection.tsx+++ b/frontend/src/pages/pam/PamAccountsPage/components/CredentialHealthSection.tsx@@ -56,9 +56,10 @@ const relative = (value?: string | null) =>type Props = {accountId?: string;+ onBeforeCheck?: () => Promise<boolean>;};-export const CredentialHealthSection = ({ accountId }: Props) => {+export const CredentialHealthSection = ({ accountId, onBeforeCheck }: Props) => {const { data: heartbeat, isPending } = useGetPamAccountHeartbeat(accountId);const { can } = usePamAccountActions(accountId ?? "", Boolean(accountId));const checkNow = useCheckPamAccountHeartbeat();@@ -74,6 +75,7 @@ export const CredentialHealthSection = ({ accountId }: Props) => {const reason = !isHealthy && heartbeat.lastMessage ? heartbeat.lastMessage : null;const handleCheckNow = async () => {+ if (onBeforeCheck && !(await onBeforeCheck())) return;try {await checkNow.mutateAsync({ accountId });createNotification({ text: "Credential check complete", type: "success" });diff --git a/frontend/src/pages/pam/PamAccountsPage/components/EditAccountForm.tsx b/frontend/src/pages/pam/PamAccountsPage/components/EditAccountForm.tsxindex 682ce1ec87..fb7c50f3c0 100644--- a/frontend/src/pages/pam/PamAccountsPage/components/EditAccountForm.tsx+++ b/frontend/src/pages/pam/PamAccountsPage/components/EditAccountForm.tsx@@ -118,8 +118,8 @@ export const EditAccountForm = ({ accountId, onDirtyChange }: Props) => {}}, [account, metadata, reset]);- const onSubmit = (values: TAccountFormValues) => {- if (!accountId || !account || !metadata) return;+ const onSubmit = async (values: TAccountFormValues): Promise<boolean> => {+ if (!accountId || !account || !metadata) return false;clearErrors();const missingConnection = getMissingRequiredFields(@@ -142,7 +142,7 @@ export const EditAccountForm = ({ accountId, onDirtyChange }: Props) => {missingCredentials.forEach((key) =>setError(`credentials.${key}`, { type: "required", message: "This field is required" }));- return;+ return false;}// Drop unchanged secrets (sentinel) so they're preserved server-side; send the rest@@ -157,31 +157,45 @@ export const EditAccountForm = ({ accountId, onDirtyChange }: Props) => {...metadata.credentialFields.map((f) => `credentials.${f.key}`)]);- updateAccount.mutate(- {- accountId,- accountType: values.accountType,- name: values.name,- description: values.description || null,- folderId: values.folderId,- templateId: values.templateId,- connectionDetails: values.connectionDetails,- ...(filteredCredentials ? { credentials: filteredCredentials } : {})- },- {- onSuccess: () => createNotification({ text: "Account updated", type: "success" }),- onError: (error) => {- const unmapped = applyServerValidationErrors(error, setError, knownFields);- if (unmapped.length) {- createNotification({- type: "error",- title: "Validation Error",- text: unmapped.join(", ")- });+ try {+ await updateAccount.mutateAsync(+ {+ accountId,+ accountType: values.accountType,+ name: values.name,+ description: values.description || null,+ folderId: values.folderId,+ templateId: values.templateId,+ connectionDetails: values.connectionDetails,+ ...(filteredCredentials ? { credentials: filteredCredentials } : {})+ },+ {+ onSuccess: () => createNotification({ text: "Account updated", type: "success" }),+ onError: (error) => {+ const unmapped = applyServerValidationErrors(error, setError, knownFields);+ if (unmapped.length) {+ createNotification({+ type: "error",+ title: "Validation Error",+ text: unmapped.join(", ")+ });+ }}}- }- );+ );+ return true;+ } catch {+ return false;+ }+ };++ const saveBeforeCheck = async () => {+ if (!isDirty) return true;+ let saved = false;+ await handleSubmit(async (values) => {+ saved = await onSubmit(values);+ })();+ return saved;};if (isLoadingAccount) {@@ -306,7 +320,7 @@ export const EditAccountForm = ({ accountId, onDirtyChange }: Props) => {</CardHeader><CardContent className="flex flex-col gap-4"><CredentialsForm control={control} setValue={setValue} />- <CredentialHealthSection accountId={accountId} />+ <CredentialHealthSection accountId={accountId} onBeforeCheck={saveBeforeCheck} /></CardContent></Card>)}