Skip to content

Commit 312c432

Browse files
Merge pull request #58 from guillermoscript/52-implement-renewal-flow
"Refactor and Add UI Components for Improved User Experience"
2 parents 51a86d5 + 8de02b0 commit 312c432

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1792
-570
lines changed

actions/dashboard/studentActions.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { revalidatePath } from 'next/cache'
44

5+
import { updateUserProfileSchema } from '@/components/dashboards/student/account/EditProfileForm'
56
import { createResponse } from '@/utils/functions'
67
import { createClient } from '@/utils/supabase/server'
78

@@ -34,3 +35,58 @@ export async function studentSubmitLessonComment (state: {
3435
revalidatePath('/dashboard/student/courses/[courseId]/lessons/[lessonId]', 'layout')
3536
return createResponse('success', 'Lesson updated successfully', null, null)
3637
}
38+
39+
export async function cancelSubscription ({
40+
userId,
41+
planId
42+
}: {
43+
userId: string
44+
planId: number
45+
}) {
46+
console.log('Cancel subscription')
47+
const supabase = createClient()
48+
const cancelSubscription = await supabase
49+
.rpc('cancel_subscription', {
50+
_user_id: userId,
51+
_plan_id: planId
52+
})
53+
54+
if (cancelSubscription.error != null) {
55+
console.log(cancelSubscription.error)
56+
return createResponse('error', 'Error cancelling subscription', null, 'Error cancelling subscription')
57+
}
58+
59+
console.log(cancelSubscription)
60+
61+
revalidatePath('/dashboard/student/account/subscriptions', 'layout')
62+
return createResponse('success', 'Subscription cancelled successfully', null, null)
63+
}
64+
65+
export async function updateUserProfile ({
66+
fullName,
67+
bio,
68+
avatarUrl
69+
}: updateUserProfileSchema) {
70+
const supabase = createClient()
71+
const userData = await supabase.auth.getUser()
72+
73+
if (userData.error) {
74+
return createResponse('error', 'Error updating profile', null, 'Error updating profile')
75+
}
76+
77+
const profileUpdate = await supabase
78+
.from('profiles')
79+
.update({
80+
full_name: fullName,
81+
bio,
82+
avatar_url: avatarUrl
83+
})
84+
.eq('id', userData.data.user?.id)
85+
86+
if (profileUpdate.error) {
87+
return createResponse('error', 'Error updating profile', null, 'Error updating profile')
88+
}
89+
90+
revalidatePath('/dashboard/student/account/profile', 'layout')
91+
return createResponse('success', 'Profile updated successfully', null, null)
92+
}

app/auth/layout.tsx

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Image from 'next/image'
21
import Link from 'next/link'
32

43
import Header from '@/components/Header'
@@ -15,28 +14,12 @@ export default function LoginLayout ({
1514
<Header>
1615
<></>
1716
</Header>
18-
<div className="md:hidden">
19-
<Image
20-
src="/examples/authentication-light.png"
21-
width={1280}
22-
height={843}
23-
alt="Authentication"
24-
className="block dark:hidden"
25-
/>
26-
<Image
27-
src="/examples/authentication-dark.png"
28-
width={1280}
29-
height={843}
30-
alt="Authentication"
31-
className="hidden dark:block"
32-
/>
33-
</div>
34-
<div className="container relative hidden h-[800px] flex-col items-center justify-center md:grid lg:max-w-none lg:grid-cols-2 lg:px-0">
17+
<div className="container relative min-h-screen flex-col py-8 items-center justify-center md:grid lg:max-w-none lg:grid-cols-2 lg:px-0">
3518
<Link
3619
href="/examples/authentication"
3720
className={cn(
3821
buttonVariants({ variant: 'ghost' }),
39-
'absolute right-4 top-4 md:right-8 md:top-8'
22+
'absolute right-4 top-4 md:right-8 md:top-8 hidden md:flex'
4023
)}
4124
>
4225
Login
@@ -56,7 +39,7 @@ export default function LoginLayout ({
5639
>
5740
<path d="M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3" />
5841
</svg>
59-
Acme Inc
42+
LMS Inc
6043
</div>
6144
<div className="relative z-20 mt-auto">
6245
<blockquote className="space-y-2">

app/auth/login/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ export default function Login ({
3131
>
3232
Forgot your password?
3333
</Link>
34+
<p className="text-center text-sm text-muted-foreground">
35+
Don't have an account?
36+
</p>
3437
<Link
3538
href="/auth/signup"
3639
className={buttonVariants({ variant: 'secondary' })}
3740
>
38-
Don't have an account? Sign up
41+
Sign up
3942
</Link>
4043
</div>
4144
</>

app/dashboard/account/orders/columns.tsx

Lines changed: 0 additions & 107 deletions
This file was deleted.

app/dashboard/account/page.tsx

Lines changed: 0 additions & 126 deletions
This file was deleted.

app/dashboard/error.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function Error ({
2020
<GenericError
2121
retry={reset}
2222
title="An error occurred"
23-
description="An unexpected error occurred. Please try again."
23+
description={error.message}
2424
/>
2525
)
2626
}

app/dashboard/notifications/error.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use client' // Error components must be Client Components
2+
3+
import { useEffect } from 'react'
4+
5+
import GenericError from '@/components/GenericError'
6+
7+
export default function Error ({
8+
error,
9+
reset
10+
}: {
11+
error: Error & { digest?: string }
12+
reset: () => void
13+
}) {
14+
useEffect(() => {
15+
// Log the error to an error reporting service
16+
console.error(error)
17+
}, [error])
18+
19+
return (
20+
<GenericError
21+
retry={reset}
22+
title="Oh no! An error occurred"
23+
description={error.message}
24+
/>
25+
)
26+
}

0 commit comments

Comments
 (0)