@@ -13,7 +13,7 @@ import { saveSettingsSchema } from "@/schema/profile";
1313import { uploadFile } from "@/utils/s3helpers" ;
1414import type { user } from "@/server/db/schema" ;
1515import { Button } from "@/components/ui-components/button" ;
16- import { CheckCheck , Loader } from "lucide-react" ;
16+ import { CheckCheck , Loader2 } from "lucide-react" ;
1717
1818function classNames ( ...classes : string [ ] ) {
1919 return classes . filter ( Boolean ) . join ( " " ) ;
@@ -49,7 +49,6 @@ const Settings = ({ profile }: { profile: User }) => {
4949 defaultValues : {
5050 ...profile ,
5151 username : profile . username || "" ,
52- email : profile . email || "" ,
5352 } ,
5453 } ) ;
5554
@@ -140,22 +139,23 @@ const Settings = ({ profile }: { profile: User }) => {
140139
141140 const handleNewEmailUpdate = async ( ) => {
142141 setLoading ( true ) ;
143- try {
144- await updateEmail ( { newEmail } ) ;
145-
146- toast . success ( "Verification link sent to your email." ) ;
147- setSendForVerification ( true ) ;
148- } catch ( error : any ) {
149- if (
150- error . data . code === "BAD_REQUEST" ||
151- error . data ?. code === "INTERNAL_SERVER_ERROR"
152- ) {
153- toast . error ( error . data . message ) ;
154- } else {
155- toast . error ( "Something went wrong" ) ;
156- }
157- }
158- setLoading ( false ) ;
142+ await updateEmail (
143+ { newEmail } ,
144+ {
145+ onError ( error ) {
146+ setLoading ( false ) ;
147+ if ( error ) return toast . error ( error . message ) ;
148+ return toast . error (
149+ "Something went wrong sending the verification link." ,
150+ ) ;
151+ } ,
152+ onSuccess ( ) {
153+ setLoading ( false ) ;
154+ toast . success ( "Verification link sent to your email." ) ;
155+ setSendForVerification ( true ) ;
156+ } ,
157+ } ,
158+ ) ;
159159 } ;
160160
161161 return (
@@ -381,7 +381,7 @@ const Settings = ({ profile }: { profile: User }) => {
381381 < input
382382 type = "email"
383383 id = "currEmail"
384- { ... register ( " email" ) }
384+ value = { profile . email ! }
385385 disabled
386386 />
387387 </ div >
@@ -404,7 +404,7 @@ const Settings = ({ profile }: { profile: User }) => {
404404 onClick = { handleNewEmailUpdate }
405405 >
406406 { loading && (
407- < Loader className = "text-primary h-4 w-4 animate-spin" />
407+ < Loader2 className = "text-primary h-6 w-6 animate-spin" />
408408 ) }
409409 Send verification link
410410 </ Button >
@@ -415,12 +415,12 @@ const Settings = ({ profile }: { profile: User }) => {
415415 Verification link sent
416416 </ h2 >
417417 < Button
418- className = "w-[200px ]"
418+ className = "w-[250px ]"
419419 disabled = { ! ( newEmail || loading ) }
420420 onClick = { handleNewEmailUpdate }
421421 >
422422 { loading && (
423- < Loader className = "text-primary h-8 w-8 animate-spin" />
423+ < Loader2 className = "text-primary h-6 w-6 animate-spin" />
424424 ) }
425425 Resend verification link
426426 </ Button >
0 commit comments