-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Admin page & some UI Changes #819
Closed
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7599c86
added admin page & some UI fix
pruthviraj7714 fafb1d2
small fix
pruthviraj7714 512ad40
small fix
pruthviraj7714 756d3b1
Merge branch 'main' into feature/admin-page
pruthviraj7714 9e25819
Merge branch 'main' into feature/admin-page
pruthviraj7714 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,209 @@ | ||
'use client'; | ||
|
||
import { Button } from '@/components/ui/button'; | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from '@/components/ui/card'; | ||
import { | ||
Form, | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from '@/components/ui/form'; | ||
import { Input } from '@/components/ui/input'; | ||
import { Textarea } from '@/components/ui/textarea'; | ||
import axios from 'axios'; | ||
import { useRouter } from 'next/navigation'; | ||
import { useState } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { toast } from 'sonner'; | ||
import { z } from 'zod'; | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
|
||
const courseSchema = z.object({ | ||
title: z.string().min(5, { | ||
message: 'Title must be at least 5 characters long.', | ||
}), | ||
imageUrl: z.string().url({ | ||
message: 'Invalid URL format for imageUrl.', | ||
}), | ||
description: z.string().min(8, { | ||
message: 'Description must be at least of 8 characters long.', | ||
}), | ||
slug: z.string(), | ||
id: z.string(), | ||
adminSecret: z.string(), | ||
appxCourseId: z.string(), | ||
discordRoleId: z.string(), | ||
}); | ||
|
||
export default function Courses() { | ||
const [isLoading, setIsLoading] = useState<boolean>(false); | ||
const router = useRouter(); | ||
|
||
const form = useForm<z.infer<typeof courseSchema>>({ | ||
resolver: zodResolver(courseSchema), | ||
defaultValues: { | ||
title: '', | ||
imageUrl: '', | ||
description: '', | ||
slug: '', | ||
id: '', | ||
adminSecret: '', | ||
appxCourseId: '', | ||
discordRoleId: '', | ||
}, | ||
}); | ||
|
||
const onSubmit = async (data: z.infer<typeof courseSchema>) => { | ||
setIsLoading(true); | ||
try { | ||
await axios.post('/api/admin/course', data); | ||
toast('course succesfully created'); | ||
router.push('/'); | ||
} catch (error: any) { | ||
console.log(error); | ||
toast(error.message); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Card className="mx-auto w-full max-w-6xl overflow-y-auto lg:mt-10"> | ||
<CardHeader> | ||
<CardTitle>Create a new course</CardTitle> | ||
<CardDescription>Fill in the course details below</CardDescription> | ||
</CardHeader> | ||
<CardContent className="grid gap-4 p-4 pt-0"> | ||
<Form {...form}> | ||
<form | ||
onSubmit={form.handleSubmit(onSubmit)} | ||
className="grid gap-4 lg:grid-cols-2" | ||
> | ||
<FormField | ||
control={form.control} | ||
name="title" | ||
render={({ field }: { field: any }) => ( | ||
<FormItem> | ||
<FormLabel>Title</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter the Course name" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="imageUrl" | ||
render={({ field }: { field: any }) => ( | ||
<FormItem> | ||
<FormLabel>Image url</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter the url of Image" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="description" | ||
render={({ field }: { field: any }) => ( | ||
<FormItem> | ||
<FormLabel>Description</FormLabel> | ||
<FormControl> | ||
<Textarea | ||
placeholder="Enter the Description of course" | ||
{...field} | ||
/> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="slug" | ||
render={({ field }: { field: any }) => ( | ||
<FormItem> | ||
<FormLabel>Slug</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter the Course slug" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="id" | ||
render={({ field }: { field: any }) => ( | ||
<FormItem> | ||
<FormLabel>Id</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter the Course ID" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="adminSecret" | ||
render={({ field }: { field: any }) => ( | ||
<FormItem> | ||
<FormLabel>Admin Secret</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter the Admin Secret" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="appxCourseId" | ||
render={({ field }: { field: any }) => ( | ||
<FormItem> | ||
<FormLabel>app x course id</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter the appx course ID" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="discordRoleId" | ||
render={({ field }: { field: any }) => ( | ||
<FormItem> | ||
<FormLabel>Discord Role Id</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Enter the Discord Role Id" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<div className="lg:col-span-2"> | ||
{isLoading ? ( | ||
<Button>Loading...</Button> | ||
) : ( | ||
<Button type="submit">Create</Button> | ||
)} | ||
</div> | ||
</form> | ||
</Form> | ||
</CardContent> | ||
</Card> | ||
); | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this public? we dont need this public as the role is inside session