Skip to content

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

fix(agent-vault): confirm discard before returning to the template step

Devin AI3324cf42374f
diff --git a/frontend/src/components/agent-vault/service-sheet/ServiceSheet.tsx b/frontend/src/components/agent-vault/service-sheet/ServiceSheet.tsx
index 67f9afff4d..cf6f15fef4 100644
--- a/frontend/src/components/agent-vault/service-sheet/ServiceSheet.tsx
+++ b/frontend/src/components/agent-vault/service-sheet/ServiceSheet.tsx
@@ -197,8 +197,14 @@ export const ServiceSheet = ({
formState: { errors, isDirty, isSubmitting }
} = formMethods;
+ const discardActionRef = useRef<VoidFunction>(() => onOpenChange(false));
const { confirmDiscard, isDiscardDialogOpen, requestDiscard, setIsDiscardDialogOpen } =
- useDiscardChangesGuard({ isDirty, onDiscard: () => onOpenChange(false) });
+ useDiscardChangesGuard({ isDirty, onDiscard: () => discardActionRef.current() });
+
+ const requestDiscardAction = (action: VoidFunction) => {
+ discardActionRef.current = action;
+ requestDiscard();
+ };
// A prefilled host has already been matched against the templates, and anything picked on the
// template step would replace that host.
@@ -308,10 +314,6 @@ export const ServiceSheet = ({
}, [isOpen, service, isUpdate, prefillHost, reset, setStep]);
const handleTemplatePicked = (picked: AgentVaultTemplate | null) => {
- if (isDirty && picked?.key === template?.key) {
- setStep(1);
- return;
- }
setTemplate(picked);
reset(
picked
@@ -324,6 +326,13 @@ export const ServiceSheet = ({
setStep(1);
};
+ const returnToTemplates = () =>
+ requestDiscardAction(() => {
+ setTemplate(null);
+ reset(BLANK_SERVICE_FORM);
+ setStep(0);
+ });
+
const buildCredential = (data: TServiceForm) => {
if (data.credentialType === AgentVaultCredentialType.Passthrough) {
return { type: AgentVaultCredentialType.Passthrough as const };
@@ -492,7 +501,8 @@ export const ServiceSheet = ({
const handleStepChange = async (target: number) => {
if (target === step) return;
if (target < step) {
- setStep(target);
+ if (stepKeys[target] === ServiceStep.Template) returnToTemplates();
+ else setStep(target);
return;
}
for (let i = step; i < target; i += 1) {
@@ -530,7 +540,7 @@ export const ServiceSheet = ({
onOpenChange(true);
return;
}
- requestDiscard();
+ requestDiscardAction(() => onOpenChange(false));
}}
>
<SheetContent className="flex h-full max-h-full w-screen flex-col gap-y-0 sm:max-w-[90vw] xl:max-w-7xl">
@@ -632,7 +642,13 @@ export const ServiceSheet = ({
Step {step + 1} of {steps.length}
</span>
{step > 0 && (
- <Button type="button" variant="outline" onClick={goBack}>
+ <Button
+ type="button"
+ variant="outline"
+ onClick={
+ stepKeys[step - 1] === ServiceStep.Template ? returnToTemplates : goBack
+ }
+ >
Back
</Button>
)}