aboutsummaryrefslogtreecommitdiff
path: root/src/app/settings/profile-form.tsx
diff options
context:
space:
mode:
authorschererleander <leander@schererleander.de>2025-12-26 18:08:25 +0100
committerschererleander <leander@schererleander.de>2025-12-26 18:08:25 +0100
commita23753f65272dca3f0b54bed16d96512a3cbe20d (patch)
tree244122f7297fe2480f198b9c3208bc25e8bd08df /src/app/settings/profile-form.tsx
parentd4052a1f73eb9fa293ac3ac2ab2bad0729474115 (diff)
refactor(settings): split settings page into separate form components
Diffstat (limited to 'src/app/settings/profile-form.tsx')
-rw-r--r--src/app/settings/profile-form.tsx12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/app/settings/profile-form.tsx b/src/app/settings/profile-form.tsx
index 6f532f0..2cd8b52 100644
--- a/src/app/settings/profile-form.tsx
+++ b/src/app/settings/profile-form.tsx
@@ -4,8 +4,8 @@ import { useState } from "react"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { Loader2, User, Save } from "lucide-react"
-import { toast } from "sonner"
import { Session } from "next-auth"
+import { toast } from "sonner"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
@@ -22,8 +22,6 @@ interface ProfileFormProps {
}
export function ProfileForm({ user, update }: ProfileFormProps) {
- const [isLoading, setIsLoading] = useState(false)
-
const form = useForm<UpdateProfileInput>({
resolver: zodResolver(updateProfileSchema),
defaultValues: {
@@ -33,8 +31,6 @@ export function ProfileForm({ user, update }: ProfileFormProps) {
})
const onSubmit = async (data: UpdateProfileInput) => {
- setIsLoading(true)
-
try {
const response = await fetch("/api/user/profile", {
method: "PATCH",
@@ -57,8 +53,6 @@ export function ProfileForm({ user, update }: ProfileFormProps) {
toast.success("Profile updated successfully!")
} catch {
toast.error("An unexpected error occurred")
- } finally {
- setIsLoading(false)
}
}
@@ -102,8 +96,8 @@ export function ProfileForm({ user, update }: ProfileFormProps) {
</FormItem>
)}
/>
- <Button type="submit" disabled={isLoading}>
- {isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
+ <Button type="submit" disabled={form.formState.isSubmitting}>
+ {form.formState.isSubmitting && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
<Save className="mr-2 h-4 w-4" />
Save Changes
</Button>