1
- import { ReactNode } from 'react' ;
2
- import { cookies } from 'next/headers'
3
- import { redirect } from 'next/navigation' ;
4
- import { revalidatePath } from 'next/cache'
5
- import Link from 'next/link' ;
1
+ import ManageSubscriptionButton from './ManageSubscriptionButton' ;
6
2
import {
7
3
getSession ,
8
4
getUserDetails ,
9
5
getSubscription
10
6
} from '@/app/supabase-server' ;
11
- import { createServerActionClient } from '@supabase/auth-helpers-nextjs'
12
- import ManageSubscriptionButton from './ManageSubscriptionButton' ;
13
7
import Button from '@/components/ui/Button' ;
14
8
import { Database } from '@/types_db' ;
9
+ import { createServerActionClient } from '@supabase/auth-helpers-nextjs' ;
10
+ import { revalidatePath } from 'next/cache' ;
11
+ import { cookies } from 'next/headers' ;
12
+ import Link from 'next/link' ;
13
+ import { redirect } from 'next/navigation' ;
14
+ import { ReactNode } from 'react' ;
15
15
16
16
export default async function Account ( ) {
17
17
const session = await getSession ( ) ;
@@ -27,35 +27,38 @@ export default async function Account() {
27
27
subscription &&
28
28
new Intl . NumberFormat ( 'en-US' , {
29
29
style : 'currency' ,
30
- currency : subscription ?. prices ?. currency ,
30
+ currency : subscription ?. prices ?. currency ! ,
31
31
minimumFractionDigits : 0
32
32
} ) . format ( ( subscription ?. prices ?. unit_amount || 0 ) / 100 ) ;
33
33
34
34
const updateName = async ( formData : FormData ) => {
35
- 'use server'
35
+ 'use server' ;
36
36
37
- const newName = formData . get ( 'name' )
38
- const supabase = createServerActionClient < Database > ( { cookies } )
37
+ const newName = formData . get ( 'name' ) as string ;
38
+ const supabase = createServerActionClient < Database > ( { cookies } ) ;
39
39
const session = await getSession ( ) ;
40
40
const user = session ?. user ;
41
- const { error } = await supabase . from ( 'users' ) . update ( { full_name : newName } ) . eq ( 'id' , user ?. id )
41
+ const { error } = await supabase
42
+ . from ( 'users' )
43
+ . update ( { full_name : newName } )
44
+ . eq ( 'id' , user ?. id ) ;
42
45
if ( error ) {
43
- console . log ( error )
46
+ console . log ( error ) ;
44
47
}
45
- revalidatePath ( '/account' )
46
- }
48
+ revalidatePath ( '/account' ) ;
49
+ } ;
47
50
48
51
const updateEmail = async ( formData : FormData ) => {
49
- 'use server'
52
+ 'use server' ;
50
53
51
- const newEmail = formData . get ( 'email' )
52
- const supabase = createServerActionClient < Database > ( { cookies } )
53
- const { error } = await supabase . auth . updateUser ( { email : newEmail } )
54
+ const newEmail = formData . get ( 'email' ) as string ;
55
+ const supabase = createServerActionClient < Database > ( { cookies } ) ;
56
+ const { error } = await supabase . auth . updateUser ( { email : newEmail } ) ;
54
57
if ( error ) {
55
- console . log ( error )
58
+ console . log ( error ) ;
56
59
}
57
- revalidatePath ( '/account' )
58
- }
60
+ revalidatePath ( '/account' ) ;
61
+ } ;
59
62
60
63
return (
61
64
< section className = "mb-32 bg-black" >
@@ -93,7 +96,12 @@ export default async function Account() {
93
96
footer = {
94
97
< div className = "flex flex-col items-start justify-between sm:flex-row sm:items-center" >
95
98
< p className = "pb-4 sm:pb-0" > 64 characters maximum</ p >
96
- < Button variant = "slim" type = "submit" form = "nameForm" disabled = { true } >
99
+ < Button
100
+ variant = "slim"
101
+ type = "submit"
102
+ form = "nameForm"
103
+ disabled = { true }
104
+ >
97
105
{ /* WARNING - In Next.js 13.4.x server actions are in alpha and should not be used in production code! */ }
98
106
Update Name
99
107
</ Button >
@@ -106,7 +114,7 @@ export default async function Account() {
106
114
type = "text"
107
115
name = "name"
108
116
className = "w-1/2 p-3 rounded-md bg-zinc-800"
109
- defaultValue = { userDetails ?. full_name }
117
+ defaultValue = { userDetails ?. full_name ?? '' }
110
118
placeholder = "Your name"
111
119
maxLength = { 64 }
112
120
/>
@@ -118,8 +126,15 @@ export default async function Account() {
118
126
description = "Please enter the email address you want to use to login."
119
127
footer = {
120
128
< div className = "flex flex-col items-start justify-between sm:flex-row sm:items-center" >
121
- < p className = "pb-4 sm:pb-0" > We will email you to verify the change.</ p >
122
- < Button variant = "slim" type = "submit" form = "emailForm" disabled = { true } >
129
+ < p className = "pb-4 sm:pb-0" >
130
+ We will email you to verify the change.
131
+ </ p >
132
+ < Button
133
+ variant = "slim"
134
+ type = "submit"
135
+ form = "emailForm"
136
+ disabled = { true }
137
+ >
123
138
{ /* WARNING - In Next.js 13.4.x server actions are in alpha and should not be used in production code! */ }
124
139
Update Email
125
140
</ Button >
@@ -132,7 +147,7 @@ export default async function Account() {
132
147
type = "text"
133
148
name = "email"
134
149
className = "w-1/2 p-3 rounded-md bg-zinc-800"
135
- defaultValue = { user ? user . email : "" }
150
+ defaultValue = { user ? user . email : '' }
136
151
placeholder = "Your email"
137
152
maxLength = { 64 }
138
153
/>
0 commit comments