Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

feat(webui): give PasswordChangeForm horizontal/vertical layouts for the forced screen

Sergey Kozyrenko5765b05c1984
diff --git a/frontend/src/features/authentication/login-form.tsx b/frontend/src/features/authentication/login-form.tsx
index 6069454d..6174efd7 100644
--- a/frontend/src/features/authentication/login-form.tsx
+++ b/frontend/src/features/authentication/login-form.tsx
@@ -162,6 +162,7 @@ function LoginForm({ providers, returnUrl = routes.newFlow }: LoginFormProps) {
You need to change your password before continuing.
</p>
<PasswordChangeForm
+ layout="vertical"
onSkip={handleSkipPasswordChange}
onSuccess={handlePasswordChangeSuccess}
/>
diff --git a/frontend/src/features/authentication/password-change-form.test.tsx b/frontend/src/features/authentication/password-change-form.test.tsx
index 42958b27..4789fa35 100644
--- a/frontend/src/features/authentication/password-change-form.test.tsx
+++ b/frontend/src/features/authentication/password-change-form.test.tsx
@@ -52,6 +52,23 @@ describe('PasswordChangeForm', () => {
});
});
+ it('renders Skip only with onSkip, and puts submit before skip in the vertical layout', () => {
+ const { rerender } = render(<PasswordChangeForm />);
+ expect(screen.queryByRole('button', { name: 'Skip for now' })).not.toBeInTheDocument();
+
+ rerender(
+ <PasswordChangeForm
+ buttonSize="default"
+ layout="vertical"
+ onSkip={vi.fn()}
+ />,
+ );
+
+ const submit = screen.getByRole('button', { name: 'Update Password' });
+ const skip = screen.getByRole('button', { name: 'Skip for now' });
+ expect(submit.compareDocumentPosition(skip) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
+ });
+
it('maps a backend error code to friendly copy instead of the raw msg', async () => {
const user = userEvent.setup();
put.mockRejectedValueOnce(
diff --git a/frontend/src/features/authentication/password-change-form.tsx b/frontend/src/features/authentication/password-change-form.tsx
index 788b5077..fce450e4 100644
--- a/frontend/src/features/authentication/password-change-form.tsx
+++ b/frontend/src/features/authentication/password-change-form.tsx
@@ -1,5 +1,5 @@
import { zodResolver } from '@hookform/resolvers/zod';
-import { useState } from 'react';
+import { type ComponentProps, useState } from 'react';
import { useForm } from 'react-hook-form';
import { toast } from 'sonner';
import * as z from 'zod';
@@ -9,6 +9,7 @@ import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, For
import { FormSubmitButton } from '@/components/ui/form-submit-button';
import { InputPassword } from '@/components/ui/input-password';
import { api, resolveApiErrorMessage } from '@/lib/axios';
+import { cn } from '@/lib/utils';
const passwordChangeSchema = z
.object({
@@ -55,6 +56,8 @@ const ERROR_BY_CODE: Record<string, string> = {
};
interface PasswordChangeFormProps {
+ buttonSize?: ComponentProps<typeof Button>['size'];
+ layout?: 'horizontal' | 'vertical';
onCancel?: () => void;
onSkip?: () => void;
onSuccess?: () => void;
@@ -62,7 +65,13 @@ interface PasswordChangeFormProps {
type PasswordChangeFormValues = z.infer<typeof passwordChangeSchema>;
-export function PasswordChangeForm({ onCancel, onSkip, onSuccess }: PasswordChangeFormProps) {
+export function PasswordChangeForm({
+ buttonSize = 'default',
+ layout = 'horizontal',
+ onCancel,
+ onSkip,
+ onSuccess,
+}: PasswordChangeFormProps) {
const [error, setError] = useState<null | string>(null);
const form = useForm<PasswordChangeFormValues>({
@@ -93,6 +102,39 @@ export function PasswordChangeForm({ onCancel, onSkip, onSuccess }: PasswordChan
}
};
+ const isVertical = layout === 'vertical';
+
+ const skipButton = onSkip && (
+ <Button
+ className={cn('text-muted-foreground', isVertical && 'w-full')}
+ onClick={onSkip}
+ size={buttonSize}
+ type="button"
+ variant="ghost"
+ >
+ Skip for now
+ </Button>
+ );
+ const cancelButton = onCancel && (
+ <Button
+ className={cn(isVertical && 'w-full')}
+ onClick={onCancel}
+ size={buttonSize}
+ type="button"
+ variant="outline"
+ >
+ Cancel
+ </Button>
+ );
+ const submitButton = (
+ <FormSubmitButton
+ className={cn(isVertical && 'w-full')}
+ size={buttonSize}
+ >
+ <span>Update Password</span>
+ </FormSubmitButton>
+ );
+
return (
<Form {...form}>
<form
@@ -156,32 +198,19 @@ export function PasswordChangeForm({ onCancel, onSkip, onSuccess }: PasswordChan
{error && <div className="text-destructive text-sm">{error}</div>}
- <div className="flex justify-end gap-2 pt-2">
- {onSkip && (
- <Button
- className="text-muted-foreground"
- onClick={onSkip}
- size="sm"
- type="button"
- variant="ghost"
- >
- Skip for now
- </Button>
- )}
- {onCancel && (
- <Button
- onClick={onCancel}
- size="sm"
- type="button"
- variant="outline"
- >
- Cancel
- </Button>
- )}
- <FormSubmitButton size="sm">
- <span>Update Password</span>
- </FormSubmitButton>
- </div>
+ {isVertical ? (
+ <div className="flex flex-col gap-2 pt-2">
+ {submitButton}
+ {cancelButton}
+ {skipButton}
+ </div>
+ ) : (
+ <div className="flex justify-end gap-2 pt-2">
+ {skipButton}
+ {cancelButton}
+ {submitButton}
+ </div>
+ )}
</form>
</Form>
);
diff --git a/frontend/src/pages/settings/settings-account.tsx b/frontend/src/pages/settings/settings-account.tsx
index d65a92da..0c4bd08d 100644
--- a/frontend/src/pages/settings/settings-account.tsx
+++ b/frontend/src/pages/settings/settings-account.tsx
@@ -140,6 +140,7 @@ function SettingsAccount() {
<CardContent>
{editing === 'password' ? (
<PasswordChangeForm
+ buttonSize="sm"
onCancel={stopEditing}
onSuccess={stopEditing}
/>