Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(frontend): update settings form (#10628)

Ubbea135f093361a
diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/actions.ts b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/actions.ts
deleted file mode 100644
index 97c9d8b153..0000000000
--- a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/actions.ts
+++ /dev/null
@@ -1,67 +0,0 @@
-"use server";
-
-import { revalidatePath } from "next/cache";
-import { getServerSupabase } from "@/lib/supabase/server/getServerSupabase";
-import { NotificationPreferenceDTO } from "@/lib/autogpt-server-api/types";
-import {
- postV1UpdateNotificationPreferences,
- postV1UpdateUserEmail,
-} from "@/app/api/__generated__/endpoints/auth/auth";
-
-export async function updateSettings(formData: FormData) {
- const supabase = await getServerSupabase();
- const {
- data: { user },
- } = await supabase.auth.getUser();
-
- // Handle auth-related updates
- const password = formData.get("password") as string;
- const email = formData.get("email") as string;
-
- if (password) {
- const { error: passwordError } = await supabase.auth.updateUser({
- password,
- });
-
- if (passwordError) {
- throw new Error(`${passwordError.message}`);
- }
- }
-
- if (email !== user?.email) {
- const { error: emailError } = await supabase.auth.updateUser({
- email,
- });
- await postV1UpdateUserEmail(email);
-
- if (emailError) {
- throw new Error(`${emailError.message}`);
- }
- }
-
- try {
- const preferences: NotificationPreferenceDTO = {
- email: user?.email || "",
- preferences: {
- AGENT_RUN: formData.get("notifyOnAgentRun") === "true",
- ZERO_BALANCE: formData.get("notifyOnZeroBalance") === "true",
- LOW_BALANCE: formData.get("notifyOnLowBalance") === "true",
- BLOCK_EXECUTION_FAILED:
- formData.get("notifyOnBlockExecutionFailed") === "true",
- CONTINUOUS_AGENT_ERROR:
- formData.get("notifyOnContinuousAgentError") === "true",
- DAILY_SUMMARY: formData.get("notifyOnDailySummary") === "true",
- WEEKLY_SUMMARY: formData.get("notifyOnWeeklySummary") === "true",
- MONTHLY_SUMMARY: formData.get("notifyOnMonthlySummary") === "true",
- },
- daily_limit: 0,
- };
- await postV1UpdateNotificationPreferences(preferences);
- } catch (error) {
- console.error(error);
- throw new Error(`Failed to update preferences: ${error}`);
- }
-
- revalidatePath("/profile/settings");
- return { success: true };
-}
diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/SettingsForm.tsx b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/SettingsForm.tsx
index 13734ad8de..861d82cd77 100644
--- a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/SettingsForm.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/SettingsForm.tsx
@@ -1,316 +1,22 @@
"use client";
-import { Button } from "@/components/ui/button";
-import {
- Form,
- FormControl,
- FormDescription,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from "@/components/ui/form";
-import { Input } from "@/components/ui/input";
-import { Switch } from "@/components/ui/switch";
import { Separator } from "@/components/ui/separator";
import { NotificationPreference } from "@/app/api/__generated__/models/notificationPreference";
import { User } from "@supabase/supabase-js";
-import { useSettingsForm } from "./useSettingsForm";
+import { EmailForm } from "./components/EmailForm/EmailForm";
+import { NotificationForm } from "./components/NotificationForm/NotificationForm";
-export const SettingsForm = ({
- preferences,
- user,
-}: {
+type SettingsFormProps = {
preferences: NotificationPreference;
user: User;
-}) => {
- const { form, onSubmit, onCancel } = useSettingsForm({
- preferences,
- user,
- });
+};
+export function SettingsForm({ preferences, user }: SettingsFormProps) {
return (
- <Form {...form}>
- <form
- onSubmit={form.handleSubmit(onSubmit)}
- className="flex flex-col gap-8"
- >
- {/* Account Settings Section */}
- <div className="flex flex-col gap-4">
- <FormField
- control={form.control}
- name="email"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Email</FormLabel>
- <FormControl>
- <Input {...field} type="email" />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
- name="password"
- render={({ field }) => (
- <FormItem>
- <FormLabel>New Password</FormLabel>
- <FormControl>
- <Input
- {...field}
- type="password"
- placeholder="************"
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
- name="confirmPassword"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Confirm New Password</FormLabel>
- <FormControl>
- <Input
- {...field}
- type="password"
- placeholder="************"
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- </div>
-
- <Separator />
-
- {/* Notifications Section */}
- <div className="flex flex-col gap-6">
- <h3 className="text-lg font-medium">Notifications</h3>
-
- {/* Agent Notifications */}
- <div className="flex flex-col gap-4">
- <h4 className="text-sm font-medium text-muted-foreground">
- Agent Notifications
- </h4>
- <FormField
- control={form.control}
- name="notifyOnAgentRun"
- render={({ field }) => (
- <FormItem className="flex flex-row items-center justify-between p-4">
- <div className="space-y-0.5">
- <FormLabel className="text-base">
- Agent Run Notifications
- </FormLabel>
- <FormDescription>
- Receive notifications when an agent starts or completes a
- run
- </FormDescription>
- </div>
- <FormControl>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
- name="notifyOnBlockExecutionFailed"
- render={({ field }) => (
- <FormItem className="flex flex-row items-center justify-between p-4">
- <div className="space-y-0.5">
- <FormLabel className="text-base">
- Block Execution Failures
- </FormLabel>
- <FormDescription>
- Get notified when a block execution fails during agent
- runs
- </FormDescription>
- </div>
- <FormControl>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
- name="notifyOnContinuousAgentError"
- render={({ field }) => (
- <FormItem className="flex flex-row items-center justify-between p-4">
- <div className="space-y-0.5">
- <FormLabel className="text-base">
- Continuous Agent Errors
- </FormLabel>
- <FormDescription>
- Receive alerts when an agent encounters repeated errors
- </FormDescription>
- </div>
- <FormControl>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- )}
- />
- </div>
-
- {/* Balance Notifications */}
- <div className="flex flex-col gap-4">
- <h4 className="text-sm font-medium text-muted-foreground">
- Balance Notifications
- </h4>
- <FormField
- control={form.control}
- name="notifyOnZeroBalance"
- render={({ field }) => (
- <FormItem className="flex flex-row items-center justify-between p-4">
- <div className="space-y-0.5">
- <FormLabel className="text-base">
- Zero Balance Alert
- </FormLabel>
- <FormDescription>
- Get notified when your account balance reaches zero
- </FormDescription>
- </div>
- <FormControl>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
- name="notifyOnLowBalance"
- render={({ field }) => (
- <FormItem className="flex flex-row items-center justify-between p-4">
- <div className="space-y-0.5">
- <FormLabel className="text-base">
- Low Balance Warning
- </FormLabel>
- <FormDescription>
- Receive warnings when your balance is running low
- </FormDescription>
- </div>
- <FormControl>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- )}
- />
- </div>
-
- {/* Summary Reports */}
- <div className="flex flex-col gap-4">
- <h4 className="text-sm font-medium text-muted-foreground">
- Summary Reports
- </h4>
- <FormField
- control={form.control}
- name="notifyOnDailySummary"
- render={({ field }) => (
- <FormItem className="flex flex-row items-center justify-between p-4">
- <div className="space-y-0.5">
- <FormLabel className="text-base">Daily Summary</FormLabel>
- <FormDescription>
- Receive a daily summary of your account activity
- </FormDescription>
- </div>
- <FormControl>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
- name="notifyOnWeeklySummary"
- render={({ field }) => (
- <FormItem className="flex flex-row items-center justify-between p-4">
- <div className="space-y-0.5">
- <FormLabel className="text-base">Weekly Summary</FormLabel>
- <FormDescription>
- Get a weekly overview of your account performance
- </FormDescription>
- </div>
- <FormControl>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
- name="notifyOnMonthlySummary"
- render={({ field }) => (
- <FormItem className="flex flex-row items-center justify-between p-4">
- <div className="space-y-0.5">
- <FormLabel className="text-base">Monthly Summary</FormLabel>
- <FormDescription>
- Receive a comprehensive monthly report of your account
- </FormDescription>
- </div>
- <FormControl>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- )}
- />
- </div>
- </div>
-
- {/* Form Actions */}
- <div className="flex justify-end gap-4">
- <Button
- variant="outline"
- type="button"
- onClick={onCancel}
- disabled={form.formState.isSubmitting}
- >
- Cancel
- </Button>
- <Button
- type="submit"
- disabled={form.formState.isSubmitting || !form.formState.isDirty}
- >
- {form.formState.isSubmitting ? "Saving..." : "Save changes"}
- </Button>
- </div>
- </form>
- </Form>
+ <div className="flex flex-col gap-8">
+ <EmailForm user={user} />
+ <Separator />
+ <NotificationForm preferences={preferences} user={user} />
+ </div>
);
-};
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/EmailForm/EmailForm.tsx b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/EmailForm/EmailForm.tsx
new file mode 100644
index 0000000000..fda46b41cc
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/EmailForm/EmailForm.tsx
@@ -0,0 +1,72 @@
+"use client";
+
+import { Form, FormControl, FormField, FormItem } from "@/components/ui/form";
+import { Input } from "@/components/atoms/Input/Input";
+import { Text } from "@/components/atoms/Text/Text";
+import { Button } from "@/components/atoms/Button/Button";
+import { User } from "@supabase/supabase-js";
+import { useEmailForm } from "./useEmailForm";
+
+type EmailFormProps = {
+ user: User;
+};
+
+export function EmailForm({ user }: EmailFormProps) {
+ const { form, onSubmit, isLoading, currentEmail } = useEmailForm({ user });
+
+ const hasError = Object.keys(form.formState.errors).length > 0;
+ const isSameEmail = form.watch("email") === currentEmail;
+
+ return (
+ <div>
+ <Text variant="h3" size="large-semibold">
+ Security & Access
+ </Text>
+ <Form {...form}>
+ <form
+ onSubmit={form.handleSubmit(onSubmit)}
+ className="mt-6 flex flex-col gap-4"
+ >
+ <FormField
+ control={form.control}
+ name="email"
+ render={({ field, fieldState }) => (
+ <FormItem>
+ <FormControl>
+ <Input
+ id={field.name}
+ label="Email"
+ placeholder="[email protected]"
+ type="text"
+ autoComplete="off"
+ className="w-full"
+ error={fieldState.error?.message}
+ {...field}
+ />
+ </FormControl>
+ </FormItem>
+ )}
+ />
+ <div className="flex items-center gap-4">
+ <Button
+ variant="outline"
+ as="NextLink"
+ href="/reset-password"
+ className="min-w-[10rem]"
+ >
+ Reset password
+ </Button>
+ <Button
+ type="submit"
+ disabled={hasError || isSameEmail}
+ loading={isLoading}
+ className="min-w-[10rem]"
+ >
+ {isLoading ? "Saving..." : "Update email"}
+ </Button>
+ </div>
+ </form>
+ </Form>
+ </div>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/EmailForm/actions.ts b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/EmailForm/actions.ts
new file mode 100644
index 0000000000..95ffb9139f
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/EmailForm/actions.ts
@@ -0,0 +1,10 @@
+import { getServerSupabase } from "@/lib/supabase/server/getServerSupabase";
+
+export async function updateSupabaseUserEmail(email: string) {
+ const supabase = await getServerSupabase();
+ const { data, error } = await supabase.auth.updateUser({
+ email,
+ });
+
+ return { data, error };
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/EmailForm/useEmailForm.ts b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/EmailForm/useEmailForm.ts
new file mode 100644
index 0000000000..b6a6d1074b
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/EmailForm/useEmailForm.ts
@@ -0,0 +1,92 @@
+"use client";
+
+import { useForm } from "react-hook-form";
+import { z } from "zod";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useToast } from "@/components/molecules/Toast/use-toast";
+import { User } from "@supabase/supabase-js";
+import { usePostV1UpdateUserEmail } from "@/app/api/__generated__/endpoints/auth/auth";
+
+const emailFormSchema = z.object({
+ email: z
+ .string()
+ .min(1, "Email is required")
+ .email("Please enter a valid email address"),
+});
+
+function createEmailDefaultValues(user: { email?: string }) {
+ return {
+ email: user.email || "",
+ };
+}
+
+async function updateUserEmailAPI(email: string) {
+ const response = await fetch("/api/auth/user", {
+ method: "PUT",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ email }),
+ });
+
+ if (!response.ok) {
+ const error = await response.json();
+ throw new Error(error.error || "Failed to update email");
+ }
+
+ return response.json();
+}
+
+export function useEmailForm({ user }: { user: User }) {
+ const { toast } = useToast();
+ const defaultValues = createEmailDefaultValues(user);
+ const currentEmail = user.email;
+
+ const form = useForm<z.infer<typeof emailFormSchema>>({
+ resolver: zodResolver(emailFormSchema),
+ defaultValues,
+ mode: "onSubmit",
+ });
+
+ const updateEmailMutation = usePostV1UpdateUserEmail({
+ mutation: {
+ onError: (error) => {
+ toast({
+ title: "Error updating email",
+ description:
+ error instanceof Error ? error.message : "Failed to update email",
+ variant: "destructive",
+ });
+ },
+ },
+ });
+
+ async function onSubmit(values: z.infer<typeof emailFormSchema>) {
+ try {
+ if (values.email !== user.email) {
+ await Promise.all([
+ updateUserEmailAPI(values.email),
+ updateEmailMutation.mutateAsync({ data: values.email }),
+ ]);
+
+ toast({
+ title: "Successfully updated email",
+ });
+ }
+ } catch (error) {
+ toast({
+ title: "Error updating email",
+ description:
+ error instanceof Error ? error.message : "Something went wrong",
+ variant: "destructive",
+ });
+ }
+ }
+
+ return {
+ form,
+ onSubmit,
+ isLoading: updateEmailMutation.isPending,
+ currentEmail,
+ };
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/NotificationForm/NotificationForm.tsx b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/NotificationForm/NotificationForm.tsx
new file mode 100644
index 0000000000..ccfd8e39bc
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/NotificationForm/NotificationForm.tsx
@@ -0,0 +1,260 @@
+"use client";
+
+import { Form, FormControl, FormField, FormItem } from "@/components/ui/form";
+import { Switch } from "@/components/ui/switch";
+import { Text } from "@/components/atoms/Text/Text";
+import { Button } from "@/components/atoms/Button/Button";
+import { NotificationPreference } from "@/app/api/__generated__/models/notificationPreference";
+import { User } from "@supabase/supabase-js";
+import { useNotificationForm } from "./useNotificationForm";
+
+type NotificationFormProps = {
+ preferences: NotificationPreference;
+ user: User;
+};
+
+export function NotificationForm({ preferences, user }: NotificationFormProps) {
+ const { form, onSubmit, onCancel, isLoading } = useNotificationForm({
+ preferences,
+ user,
+ });
+
+ return (
+ <div>
+ <Text variant="h3" size="large-semibold">
+ Notifications
+ </Text>
+ <Form {...form}>
+ <form
+ onSubmit={form.handleSubmit(onSubmit)}
+ className="mt-6 flex flex-col gap-10"
+ >
+ {/* Agent Notifications */}
+ <div className="flex flex-col gap-6">
+ <Text variant="h4" size="body-medium" className="text-slate-400">
+ Agent Notifications
+ </Text>
+ <FormField
+ control={form.control}
+ name="notifyOnAgentRun"
+ render={({ field }) => (
+ <FormItem className="flex flex-row items-center justify-between">
+ <div className="space-y-0.5">
+ <Text variant="h4" size="body-medium">
+ Agent Run Notifications
+ </Text>
+ <Text variant="body">
+ Receive notifications when an agent starts or completes a
+ run
+ </Text>
+ </div>
+ <FormControl>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </FormControl>
+ </FormItem>
+ )}
+ />
+
+ <FormField
+ control={form.control}
+ name="notifyOnBlockExecutionFailed"
+ render={({ field }) => (
+ <FormItem className="flex flex-row items-center justify-between">
+ <div className="space-y-0.5">
+ <Text variant="h4" size="body-medium">
+ Block Execution Failures
+ </Text>
+ <Text variant="body">
+ Get notified when a block execution fails during agent
+ runs
+ </Text>
+ </div>
+ <FormControl>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </FormControl>
+ </FormItem>
+ )}
+ />
+
+ <FormField
+ control={form.control}
+ name="notifyOnContinuousAgentError"
+ render={({ field }) => (
+ <FormItem className="flex flex-row items-center justify-between">
+ <div className="space-y-0.5">
+ <Text variant="h4" size="body-medium">
+ Continuous Agent Errors
+ </Text>
+ <Text variant="body">
+ Receive alerts when an agent encounters repeated errors
+ </Text>
+ </div>
+ <FormControl>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </FormControl>
+ </FormItem>
+ )}
+ />
+ </div>
+
+ {/* Balance Notifications */}
+ <div className="flex flex-col gap-4">
+ <Text variant="h4" size="body-medium" className="text-slate-400">
+ Balance Notifications
+ </Text>
+ <FormField
+ control={form.control}
+ name="notifyOnZeroBalance"
+ render={({ field }) => (
+ <FormItem className="flex flex-row items-center justify-between">
+ <div className="space-y-0.5">
+ <Text variant="h4" size="body-medium">
+ Zero Balance Alert
+ </Text>
+ <Text variant="body">
+ Get notified when your account balance reaches zero
+ </Text>
+ </div>
+ <FormControl>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </FormControl>
+ </FormItem>
+ )}
+ />
+
+ <FormField
+ control={form.control}
+ name="notifyOnLowBalance"
+ render={({ field }) => (
+ <FormItem className="flex flex-row items-center justify-between">
+ <div className="space-y-0.5">
+ <Text variant="h4" size="body-medium">
+ Low Balance Warning
+ </Text>
+ <Text variant="body">
+ Receive warnings when your balance is running low
+ </Text>
+ </div>
+ <FormControl>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </FormControl>
+ </FormItem>
+ )}
+ />
+ </div>
+
+ {/* Summary Reports */}
+ <div className="flex flex-col gap-4">
+ <Text variant="h4" size="body-medium" className="text-slate-400">
+ Summary reports
+ </Text>
+ <FormField
+ control={form.control}
+ name="notifyOnDailySummary"
+ render={({ field }) => (
+ <FormItem className="flex flex-row items-center justify-between">
+ <div className="space-y-1">
+ <Text variant="h4" size="body-medium">
+ Daily Summary
+ </Text>
+ <Text variant="body">
+ Receive a daily summary of your account activity
+ </Text>
+ </div>
+ <FormControl>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </FormControl>
+ </FormItem>
+ )}
+ />
+
+ <FormField
+ control={form.control}
+ name="notifyOnWeeklySummary"
+ render={({ field }) => (
+ <FormItem className="flex flex-row items-center justify-between">
+ <div className="space-y-0.5">
+ <Text variant="h4" size="body-medium">
+ Weekly Summary
+ </Text>
+ <Text variant="body">
+ Get a weekly overview of your account performance
+ </Text>
+ </div>
+ <FormControl>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </FormControl>
+ </FormItem>
+ )}
+ />
+
+ <FormField
+ control={form.control}
+ name="notifyOnMonthlySummary"
+ render={({ field }) => (
+ <FormItem className="flex flex-row items-center justify-between">
+ <div className="space-y-0.5">
+ <Text variant="h4" size="body-medium">
+ Monthly Summary
+ </Text>
+ <Text variant="body">
+ Receive a comprehensive monthly report of your account
+ </Text>
+ </div>
+ <FormControl>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </FormControl>
+ </FormItem>
+ )}
+ />
+ </div>
+
+ {/* Form Actions */}
+ <div className="flex justify-end gap-4 pt-8">
+ <Button
+ variant="outline"
+ type="button"
+ onClick={onCancel}
+ disabled={isLoading}
+ className="min-w-[10rem]"
+ >
+ Cancel
+ </Button>
+ <Button
+ type="submit"
+ disabled={isLoading || !form.formState.isDirty}
+ className="min-w-[10rem]"
+ loading={isLoading}
+ >
+ {isLoading ? "Saving..." : "Save preferences"}
+ </Button>
+ </div>
+ </form>
+ </Form>
+ </div>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/NotificationForm/useNotificationForm.ts b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/NotificationForm/useNotificationForm.ts
new file mode 100644
index 0000000000..ba639a35a6
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/components/NotificationForm/useNotificationForm.ts
@@ -0,0 +1,114 @@
+"use client";
+
+import { useForm } from "react-hook-form";
+import { z } from "zod";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useToast } from "@/components/molecules/Toast/use-toast";
+import { NotificationPreference } from "@/app/api/__generated__/models/notificationPreference";
+import { User } from "@supabase/supabase-js";
+import { usePostV1UpdateNotificationPreferences } from "@/app/api/__generated__/endpoints/auth/auth";
+import { NotificationPreferenceDTO } from "@/lib/autogpt-server-api/types";
+
+const notificationFormSchema = z.object({
+ notifyOnAgentRun: z.boolean(),
+ notifyOnZeroBalance: z.boolean(),
+ notifyOnLowBalance: z.boolean(),
+ notifyOnBlockExecutionFailed: z.boolean(),
+ notifyOnContinuousAgentError: z.boolean(),
+ notifyOnDailySummary: z.boolean(),
+ notifyOnWeeklySummary: z.boolean(),
+ notifyOnMonthlySummary: z.boolean(),
+});
+
+function createNotificationDefaultValues(preferences: {
+ preferences?: Record<string, boolean>;
+}) {
+ return {
+ notifyOnAgentRun: preferences.preferences?.AGENT_RUN,
+ notifyOnZeroBalance: preferences.preferences?.ZERO_BALANCE,
+ notifyOnLowBalance: preferences.preferences?.LOW_BALANCE,
+ notifyOnBlockExecutionFailed:
+ preferences.preferences?.BLOCK_EXECUTION_FAILED,
+ notifyOnContinuousAgentError:
+ preferences.preferences?.CONTINUOUS_AGENT_ERROR,
+ notifyOnDailySummary: preferences.preferences?.DAILY_SUMMARY,
+ notifyOnWeeklySummary: preferences.preferences?.WEEKLY_SUMMARY,
+ notifyOnMonthlySummary: preferences.preferences?.MONTHLY_SUMMARY,
+ };
+}
+
+export function useNotificationForm({
+ preferences,
+ user,
+}: {
+ preferences: NotificationPreference;
+ user: User;
+}) {
+ const { toast } = useToast();
+ const defaultValues = createNotificationDefaultValues(preferences);
+
+ const form = useForm<z.infer<typeof notificationFormSchema>>({
+ resolver: zodResolver(notificationFormSchema),
+ defaultValues,
+ });
+
+ const updateNotificationsMutation = usePostV1UpdateNotificationPreferences({
+ mutation: {
+ onError: (error) => {
+ toast({
+ title: "Error updating notifications",
+ description:
+ error instanceof Error
+ ? error.message
+ : "Failed to update notification preferences",
+ variant: "destructive",
+ });
+ },
+ },
+ });
+
+ async function onSubmit(values: z.infer<typeof notificationFormSchema>) {
+ try {
+ const notificationPreferences: NotificationPreferenceDTO = {
+ email: user.email || "",
+ preferences: {
+ AGENT_RUN: values.notifyOnAgentRun,
+ ZERO_BALANCE: values.notifyOnZeroBalance,
+ LOW_BALANCE: values.notifyOnLowBalance,
+ BLOCK_EXECUTION_FAILED: values.notifyOnBlockExecutionFailed,
+ CONTINUOUS_AGENT_ERROR: values.notifyOnContinuousAgentError,
+ DAILY_SUMMARY: values.notifyOnDailySummary,
+ WEEKLY_SUMMARY: values.notifyOnWeeklySummary,
+ MONTHLY_SUMMARY: values.notifyOnMonthlySummary,
+ },
+ daily_limit: 0,
+ };
+
+ await updateNotificationsMutation.mutateAsync({
+ data: notificationPreferences,
+ });
+
+ toast({
+ title: "Successfully updated notification preferences",
+ });
+ } catch (error) {
+ toast({
+ title: "Error updating notifications",
+ description:
+ error instanceof Error ? error.message : "Something went wrong",
+ variant: "destructive",
+ });
+ }
+ }
+
+ function onCancel() {
+ form.reset(defaultValues);
+ }
+
+ return {
+ form,
+ onSubmit,
+ onCancel,
+ isLoading: updateNotificationsMutation.isPending,
+ };
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/helper.ts b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/helper.ts
deleted file mode 100644
index ad04713af2..0000000000
--- a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/helper.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-import { z } from "zod";
-
-export const formSchema = z
- .object({
- email: z.string().email(),
- password: z
- .string()
- .optional()
- .refine((val) => {
- if (val) return val.length >= 12;
- return true;
- }, "String must contain at least 12 character(s)"),
- confirmPassword: z.string().optional(),
- notifyOnAgentRun: z.boolean(),
- notifyOnZeroBalance: z.boolean(),
- notifyOnLowBalance: z.boolean(),
- notifyOnBlockExecutionFailed: z.boolean(),
- notifyOnContinuousAgentError: z.boolean(),
- notifyOnDailySummary: z.boolean(),
- notifyOnWeeklySummary: z.boolean(),
- notifyOnMonthlySummary: z.boolean(),
- })
- .refine((data) => {
- if (data.password || data.confirmPassword) {
- return data.password === data.confirmPassword;
- }
- return true;
- });
-
-export const createDefaultValues = (
- user: { email?: string },
- preferences: { preferences?: Record<string, boolean> },
-) => {
- const defaultValues = {
- email: user.email || "",
- password: "",
- confirmPassword: "",
- notifyOnAgentRun: preferences.preferences?.AGENT_RUN,
- notifyOnZeroBalance: preferences.preferences?.ZERO_BALANCE,
- notifyOnLowBalance: preferences.preferences?.LOW_BALANCE,
- notifyOnBlockExecutionFailed:
- preferences.preferences?.BLOCK_EXECUTION_FAILED,
- notifyOnContinuousAgentError:
- preferences.preferences?.CONTINUOUS_AGENT_ERROR,
- notifyOnDailySummary: preferences.preferences?.DAILY_SUMMARY,
- notifyOnWeeklySummary: preferences.preferences?.WEEKLY_SUMMARY,
- notifyOnMonthlySummary: preferences.preferences?.MONTHLY_SUMMARY,
- };
-
- return defaultValues;
-};
diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/useSettingsForm.tsx b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/useSettingsForm.tsx
deleted file mode 100644
index 3b6361bb3b..0000000000
--- a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/components/SettingsForm/useSettingsForm.tsx
+++ /dev/null
@@ -1,57 +0,0 @@
-"use client";
-import { useForm } from "react-hook-form";
-import { createDefaultValues, formSchema } from "./helper";
-import { z } from "zod";
-import { zodResolver } from "@hookform/resolvers/zod";
-import { updateSettings } from "../../actions";
-import { useToast } from "@/components/molecules/Toast/use-toast";
-import { NotificationPreference } from "@/app/api/__generated__/models/notificationPreference";
-import { User } from "@supabase/supabase-js";
-
-export const useSettingsForm = ({
- preferences,
- user,
-}: {
- preferences: NotificationPreference;
- user: User;
-}) => {
- const { toast } = useToast();
- const defaultValues = createDefaultValues(user, preferences);
-
- const form = useForm<z.infer<typeof formSchema>>({
- resolver: zodResolver(formSchema),
- defaultValues,
- });
-
- async function onSubmit(values: z.infer<typeof formSchema>) {
- try {
- const formData = new FormData();
-
- Object.entries(values).forEach(([key, value]) => {
- if (key !== "confirmPassword") {
- formData.append(key, value.toString());
- }
- });
-
- await updateSettings(formData);
-
- toast({
- title: "Successfully updated settings",
- });
- } catch (error) {
- toast({
- title: "Error",
- description:
- error instanceof Error ? error.message : "Something went wrong",
- variant: "destructive",
- });
- throw error;
- }
- }
-
- function onCancel() {
- form.reset(defaultValues);
- }
-
- return { form, onSubmit, onCancel };
-};
diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/page.tsx b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/page.tsx
index 8152999b5c..b97e72b40f 100644
--- a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/page.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/settings/page.tsx
@@ -5,6 +5,7 @@ import { useSupabase } from "@/lib/supabase/hooks/useSupabase";
import * as React from "react";
import SettingsLoading from "./loading";
import { redirect } from "next/navigation";
+import { Text } from "@/components/atoms/Text/Text";
export default function SettingsPage() {
const {
@@ -35,11 +36,11 @@ export default function SettingsPage() {
return (
<div className="container max-w-2xl space-y-6 py-10">
- <div>
- <h3 className="text-lg font-medium">My account</h3>
- <p className="text-sm text-muted-foreground">
+ <div className="flex flex-col gap-2">
+ <Text variant="h3">My account</Text>
+ <Text variant="large">
Manage your account settings and preferences.
- </p>
+ </Text>
</div>
<SettingsForm preferences={preferences} user={user} />
</div>
diff --git a/autogpt_platform/frontend/src/app/api/auth/user/route.ts b/autogpt_platform/frontend/src/app/api/auth/user/route.ts
new file mode 100644
index 0000000000..896385d865
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/api/auth/user/route.ts
@@ -0,0 +1,39 @@
+import { getServerSupabase } from "@/lib/supabase/server/getServerSupabase";
+import { NextResponse } from "next/server";
+
+export async function GET() {
+ const supabase = await getServerSupabase();
+ const { data, error } = await supabase.auth.getUser();
+
+ if (error) {
+ return NextResponse.json({ error: error.message }, { status: 400 });
+ }
+
+ return NextResponse.json(data);
+}
+
+export async function PUT(request: Request) {
+ try {
+ const supabase = await getServerSupabase();
+ const { email } = await request.json();
+
+ if (!email) {
+ return NextResponse.json({ error: "Email is required" }, { status: 400 });
+ }
+
+ const { data, error } = await supabase.auth.updateUser({
+ email,
+ });
+
+ if (error) {
+ return NextResponse.json({ error: error.message }, { status: 400 });
+ }
+
+ return NextResponse.json(data);
+ } catch {
+ return NextResponse.json(
+ { error: "Failed to update user email" },
+ { status: 500 },
+ );
+ }
+}
diff --git a/autogpt_platform/frontend/src/app/api/mutators/custom-mutator.ts b/autogpt_platform/frontend/src/app/api/mutators/custom-mutator.ts
index fb86f27813..c884c17df3 100644
--- a/autogpt_platform/frontend/src/app/api/mutators/custom-mutator.ts
+++ b/autogpt_platform/frontend/src/app/api/mutators/custom-mutator.ts
@@ -93,7 +93,7 @@ export const customMutator = async <T = any>(
// 4. If the request succeeds on the server side, the data will be cached, and the client will use it instead of sending a request to the proxy.
if (!response.ok && isServerSide()) {
- console.error("Request failed on server side", response);
+ console.error("Request failed on server side", response, fullUrl);
throw new Error(`Request failed with status ${response.status}`);
}
diff --git a/autogpt_platform/frontend/src/tests/build.spec.ts b/autogpt_platform/frontend/src/tests/build.spec.ts
index 01d772c67a..1b6bd9b5ca 100644
--- a/autogpt_platform/frontend/src/tests/build.spec.ts
+++ b/autogpt_platform/frontend/src/tests/build.spec.ts
@@ -53,8 +53,6 @@ test.describe("Build", () => { //(1)!
for (const block of blocksToAdd) {
await buildPage.addBlock(block);
}
-
- await buildPage.saveAgent(`Saved blocks ${letter} test part ${part}`);
}
// Reason Ignore: admonishment is in the wrong place visually with correct prettier rules
diff --git a/autogpt_platform/frontend/src/tests/settings.spec.ts b/autogpt_platform/frontend/src/tests/settings.spec.ts
new file mode 100644
index 0000000000..72152ea66f
--- /dev/null
+++ b/autogpt_platform/frontend/src/tests/settings.spec.ts
@@ -0,0 +1,144 @@
+import test, { expect } from "@playwright/test";
+import { getTestUser } from "./utils/auth";
+import { LoginPage } from "./pages/login.page";
+import { hasAttribute, hasUrl, isHidden, isVisible } from "./utils/assertion";
+import { getSelectors } from "./utils/selectors";
+
+test.beforeEach(async ({ page }) => {
+ const testUser = await getTestUser();
+ const loginPage = new LoginPage(page);
+
+ // Login and navigate to settings
+ await page.goto("/login");
+ await loginPage.login(testUser.email, testUser.password);
+ await hasUrl(page, "/marketplace");
+
+ // Navigate to settings page
+ await page.goto("/profile/settings");
+ await hasUrl(page, "/profile/settings");
+});
+
+test("should display email form elements correctly", async ({ page }) => {
+ const { getField, getButton, getText, getLink } = getSelectors(page);
+
+ // Check email form elements are displayed
+ await isVisible(getText("Security & Access"));
+ await isVisible(getField("Email"));
+ await isVisible(getLink("Reset password"));
+ await isVisible(getButton("Update email"));
+
+ const updateEmailButton = getButton("Update email");
+ const resetPasswordButton = getLink("Reset password");
+
+ // Button should be disabled initially (no changes)
+ await expect(updateEmailButton).toBeDisabled();
+
+ // Test reset password navigation
+ await hasAttribute(resetPasswordButton, "href", "/reset-password");
+});
+
+test("should show validation error for empty email", async ({ page }) => {
+ const { getField, getButton } = getSelectors(page);
+
+ const emailField = getField("Email");
+ const updateEmailButton = getButton("Update email");
+
+ await emailField.fill("");
+ await updateEmailButton.click();
+ await isVisible(page.getByText("Email is required"));
+});
+
+test("should show validation error for invalid email", async ({ page }) => {
+ const { getField, getButton } = getSelectors(page);
+
+ const emailField = getField("Email");
+ const updateEmailButton = getButton("Update email");
+
+ await emailField.fill("invalid email");
+ await updateEmailButton.click();
+ await isVisible(page.getByText("Please enter a valid email address"));
+});
+
+test("should handle valid email", async ({ page }) => {
+ const { getField, getButton } = getSelectors(page);
+
+ const emailField = getField("Email");
+ const updateEmailButton = getButton("Update email");
+
+ // Test successful email update
+ const newEmail = `test+${Date.now()}@example.com`;
+ await emailField.fill(newEmail);
+ await expect(updateEmailButton).toBeEnabled();
+ await updateEmailButton.click();
+ await isHidden(page.getByText("Email is required"));
+ await isHidden(page.getByText("Please enter a valid email address"));
+});
+
+test("should handle complete notification form functionality and form interactions", async ({
+ page,
+}) => {
+ const { getButton } = getSelectors(page);
+
+ // Check notification form elements are displayed
+ await isVisible(
+ page.getByRole("heading", { name: "Notifications", exact: true }),
+ );
+
+ await isVisible(getButton("Cancel"));
+ await isVisible(getButton("Save preferences"));
+
+ // Check all notification switches are present - get all switches on page
+ const switches = await page.getByRole("switch").all();
+
+ for (const switchElement of switches) {
+ await isVisible(switchElement);
+ }
+
+ const savePreferencesButton = getButton("Save preferences");
+ const cancelButton = getButton("Cancel");
+
+ // Button should be disabled initially (no changes)
+ await expect(savePreferencesButton).toBeDisabled();
+
+ // Test switch toggling functionality
+ for (const switchElement of switches) {
+ const initialState = await switchElement.isChecked();
+ await switchElement.click();
+ const newState = await switchElement.isChecked();
+ expect(newState).toBe(!initialState);
+ }
+
+ // Test button enabling when changes are made
+ if (switches.length > 0) {
+ await expect(savePreferencesButton).toBeEnabled();
+ }
+
+ // Test cancel functionality
+ await cancelButton.click();
+ // Wait for form state to update after cancel
+ await page.waitForTimeout(100);
+ await expect(savePreferencesButton).toBeDisabled();
+
+ // Test successful save with multiple switches
+ const testSwitches = switches.slice(0, Math.min(3, switches.length));
+ for (const switchElement of testSwitches) {
+ await switchElement.click();
+ }
+ await expect(savePreferencesButton).toBeEnabled();
+ await savePreferencesButton.click();
+ await isVisible(getButton("Saving..."));
+ await isVisible(
+ page.getByText("Successfully updated notification preferences"),
+ );
+
+ // Test persistence after page reload
+ if (testSwitches.length > 0) {
+ const finalState = await testSwitches[0].isChecked();
+ await page.reload();
+ await hasUrl(page, "/profile/settings");
+ const reloadedSwitches = await page.getByRole("switch").all();
+ if (reloadedSwitches.length > 0) {
+ expect(await reloadedSwitches[0].isChecked()).toBe(finalState);
+ }
+ }
+});