-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,106 @@ | ||
import { zodResolver } from "@hookform/resolvers/zod" | ||
import { useForm } from "react-hook-form" | ||
import { z } from "zod" | ||
import { Button } from "@renderer/components/ui/button" | ||
import { | ||
Form, | ||
FormControl, | ||
FormDescription, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from "@renderer/components/ui/form" | ||
import { Input } from "@renderer/components/ui/input" | ||
import { useSession } from "@hono/auth-js/react" | ||
import { useMutation } from "@tanstack/react-query" | ||
import { apiFetch } from "@renderer/lib/queries/api-fetch" | ||
import { useToast } from "@renderer/components/ui/use-toast" | ||
|
||
const formSchema = z.object({ | ||
handle: z.string().max(50), | ||
name: z.string().min(3).max(50), | ||
avatar: z.string().url(), | ||
}) | ||
|
||
export function Component() { | ||
return <>profile</> | ||
const { data: session } = useSession() | ||
|
||
const form = useForm<z.infer<typeof formSchema>>({ | ||
resolver: zodResolver(formSchema), | ||
defaultValues: { | ||
handle: session?.user?.handle || "", | ||
name: session?.user?.name || "", | ||
avatar: session?.user?.image || "", | ||
}, | ||
}) | ||
|
||
const { toast } = useToast() | ||
|
||
const updateMutation = useMutation({ | ||
mutationFn: async (values: z.infer<typeof formSchema>) => | ||
apiFetch("/auth-app/update-account", { | ||
method: "PATCH", | ||
body: values, | ||
}), | ||
onSuccess: () => { | ||
toast({ | ||
duration: 3000, | ||
description: "Profile updated.", | ||
}) | ||
}, | ||
}) | ||
|
||
function onSubmit(values: z.infer<typeof formSchema>) { | ||
updateMutation.mutate(values) | ||
} | ||
|
||
return ( | ||
<Form {...form}> | ||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4"> | ||
<FormField | ||
control={form.control} | ||
name="handle" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Handle</FormLabel> | ||
<FormControl> | ||
<Input {...field} /> | ||
</FormControl> | ||
<FormDescription>Your unique identifier.</FormDescription> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="name" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Display Name</FormLabel> | ||
<FormControl> | ||
<Input {...field} /> | ||
</FormControl> | ||
<FormDescription>Your public display name.</FormDescription> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="avatar" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Avatar</FormLabel> | ||
<FormControl> | ||
<Input {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<Button type="submit">Submit</Button> | ||
</form> | ||
</Form> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { User } from "@auth/core/types" | ||
|
||
declare module "@auth/core/types" { | ||
interface User { | ||
handle?: string | null | ||
} | ||
} |