From bd1f02996ff967fa47af1a08ab3cd820103fb078 Mon Sep 17 00:00:00 2001 From: Aman Kumar Bairagi <118182376+amanbairagi30@users.noreply.github.com> Date: Fri, 13 Sep 2024 02:44:12 +0530 Subject: [PATCH] Revamp Admin UI & Discord Notifcation (#1181) * revamped admin ui and added discord notifications * updated the video client component * some lint fix * minor change in .env.example * Update src/app/api/admin/content/route.ts --------- Co-authored-by: Sargam --- .env.example | 1 + package.json | 3 +- src/app/admin/add-course/page.tsx | 348 ++++++++++++++ src/app/admin/comment/ApproveComment.tsx | 104 +++-- src/app/admin/comment/page.tsx | 7 +- .../content/[courseId]/[...moduleId]/page.tsx | 6 +- src/app/admin/content/[courseId]/page.tsx | 10 +- src/app/admin/discord/page.tsx | 224 +++++---- src/app/admin/layout.tsx | 4 +- src/app/admin/page.tsx | 431 ++++++------------ src/app/admin/user/LogoutUser.tsx | 98 ++-- src/app/admin/user/page.tsx | 7 +- src/app/admin/userflags/page.tsx | 267 ++++++----- src/app/api/admin/content/route.ts | 85 +++- src/app/globals.css | 12 + src/components/Navbar.tsx | 2 +- src/components/admin/AddContent.tsx | 181 ++++++-- src/components/admin/UpdateVideoClient.tsx | 302 +++++++----- src/components/ui/radio-group.tsx | 44 ++ 19 files changed, 1407 insertions(+), 729 deletions(-) create mode 100644 src/app/admin/add-course/page.tsx create mode 100644 src/components/ui/radio-group.tsx diff --git a/.env.example b/.env.example index 5bc2afbce..53179cb37 100644 --- a/.env.example +++ b/.env.example @@ -21,6 +21,7 @@ NEXT_PUBLIC_DISABLE_FEATURES = "featurea,featureb,featurec" REDIS_URL= GITHUB_ID= GITHUB_SECRET= +NEXT_PUBLIC_DISCORD_WEBHOOK_URL = COHORT3_DISCORD_ACCESS_KEY = diff --git a/package.json b/package.json index b1454d812..f26aa8e56 100644 --- a/package.json +++ b/package.json @@ -47,10 +47,11 @@ "@radix-ui/react-label": "^2.0.2", "@radix-ui/react-navigation-menu": "^1.1.4", "@radix-ui/react-popover": "^1.1.1", + "@radix-ui/react-radio-group": "^1.2.0", "@radix-ui/react-scroll-area": "^1.1.0", + "@radix-ui/react-separator": "^1.1.0", "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-switch": "^1.1.0", - "@radix-ui/react-separator": "^1.1.0", "@radix-ui/react-tooltip": "^1.0.7", "@tabler/icons-react": "^3.14.0", "@types/bcrypt": "^5.0.2", diff --git a/src/app/admin/add-course/page.tsx b/src/app/admin/add-course/page.tsx new file mode 100644 index 000000000..dace4c5a8 --- /dev/null +++ b/src/app/admin/add-course/page.tsx @@ -0,0 +1,348 @@ +'use client'; + +import { Button } from '@/components/ui/button'; +import { + Card, + CardContent, + 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'; +import { + Accordion, + AccordionContent, + AccordionItem, + AccordionTrigger, +} from "@/components/ui/accordion"; +import { Cuboid, PackagePlus } from 'lucide-react'; +import { FaDiscord } from 'react-icons/fa'; + +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(false); + const router = useRouter(); + const [email, setEmail] = useState(''); + const [adminPassword, setAdminPassword] = useState(''); + + const form = useForm>({ + resolver: zodResolver(courseSchema), + defaultValues: { + title: '', + imageUrl: '', + description: '', + slug: '', + id: '', + adminSecret: '', + appxCourseId: '', + discordRoleId: '', + }, + }); + + const onSubmit = async (data: z.infer) => { + 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 ( +
+ +
+ +

View Content

+
+ + + + +
+ New course +
+
+ +
+
Create new course for 100xdevs community and let user explore new courses
+
+ + + {/* Create a new course */} + Fill in the course details below + + +
+ + ( + + Title + + + + + + )} + /> + ( + + Image url + + + + + + )} + /> + ( + + Description + +