From 6ee92bc6bbaff2b535883eeebb0461296a95cb07 Mon Sep 17 00:00:00 2001 From: vanshavenger Date: Wed, 2 Oct 2024 20:58:22 +0530 Subject: [PATCH] test 1 --- .eslintrc | 2 + .husky/pre-commit | 52 ++++++-- .prettierrc | 3 +- package.json | 2 + src/actions/payoutMethods/schema.ts | 23 ++-- src/app/admin/add-course/page.tsx | 124 +++++++++++------- src/app/admin/comment/ApproveComment.tsx | 37 +++--- src/app/admin/comment/page.tsx | 8 +- .../content/[courseId]/[...moduleId]/page.tsx | 2 +- src/app/admin/content/[courseId]/page.tsx | 4 +- src/app/admin/discord/page.tsx | 65 ++++----- src/app/admin/layout.tsx | 12 +- src/app/admin/page.tsx | 50 ++++--- src/app/admin/user/LogoutUser.tsx | 36 ++--- src/app/admin/user/page.tsx | 6 +- src/app/admin/userflags/page.tsx | 60 ++++----- src/app/api/admin/contentmetadata/route.ts | 4 +- src/app/api/admin/updatecontent/route.ts | 4 +- src/app/payout-methods/page.tsx | 2 +- src/components/NewPostDialog.tsx | 12 +- src/components/Sidebar.tsx | 5 +- src/components/Signin.tsx | 9 +- src/components/admin/AddContent.tsx | 120 +++++++++-------- src/components/admin/UpdateVideoClient.tsx | 59 +++++---- src/components/posts/PostCard.tsx | 2 +- src/components/posts/form/form-input.tsx | 2 +- src/components/ui/radio-group.tsx | 16 +-- 27 files changed, 423 insertions(+), 298 deletions(-) diff --git a/.eslintrc b/.eslintrc index 55a8a9198..fe8ac2bf3 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,11 +9,13 @@ env: plugins: - "@typescript-eslint" + - "prettier" extends: - eslint:recommended - plugin:@typescript-eslint/eslint-recommended - plugin:@typescript-eslint/recommended + - plugin:prettier/recommended parserOptions: ecmaVersion: 2018 diff --git a/.husky/pre-commit b/.husky/pre-commit index d663f7203..c6165307b 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,12 +1,48 @@ #!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" -npm run format:fix -npm run lint:fix +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' -git add . +print_color() { + printf "${!1}%s${NC}\n" "$2" +} -if [ -f "yarn.lock" ] || [ -f "package-lock.json" ]; then - echo "Error: yarn.lock or package-lock.json is present. Please remove them before committing." - exit 1 -fi \ No newline at end of file +run_command() { + print_color "YELLOW" "Running $1..." + if eval "$1"; then + print_color "GREEN" "$1 completed successfully." + else + print_color "RED" "$1 failed. Please fix the issues and try committing again." + exit 1 + fi +} + +check_lock_files() { + local lock_files=("yarn.lock" "package-lock.json" "pnpm-lock.yaml") + local staged_files=$(git diff --cached --name-only) + + for file in "${lock_files[@]}"; do + if echo "$staged_files" | grep -q "$file"; then + print_color "RED" "Error: $file is staged for commit. Please remove it before committing." + exit 1 + fi + done +} + +main() { + check_lock_files + + run_command "npm run format:fix" + + run_command "npm run lint:fix" + + git add . + + run_command "npm run lint:check" + + print_color "GREEN" "Pre-commit checks passed successfully!" +} + +main \ No newline at end of file diff --git a/.prettierrc b/.prettierrc index 2cb8898d0..47c652986 100644 --- a/.prettierrc +++ b/.prettierrc @@ -5,5 +5,6 @@ "trailingComma": "all", "plugins": [ "prettier-plugin-tailwindcss" - ] + ], + "embeddedLanguageFormatting": "off" } \ No newline at end of file diff --git a/package.json b/package.json index f26aa8e56..3f60d1c2b 100644 --- a/package.json +++ b/package.json @@ -126,6 +126,8 @@ "autoprefixer": "^10.0.1", "eslint": "^8.56.0", "eslint-plugin-storybook": "^0.8.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.2.1", "husky": "^9.0.7", "jsdom": "^24.0.0", "postcss": "^8", diff --git a/src/actions/payoutMethods/schema.ts b/src/actions/payoutMethods/schema.ts index 461a934aa..961756e09 100644 --- a/src/actions/payoutMethods/schema.ts +++ b/src/actions/payoutMethods/schema.ts @@ -1,32 +1,35 @@ import { z } from 'zod'; +const UPI_REGEX = new RegExp('^[0-9A-Za-z._-]{2,256}@[A-Za-z]{2,64}$'); +const SOLANA_ADDRESS_REGEX = new RegExp('^[A-Za-z0-9]{44}$'); + export const payoutMethodSchema = z.object({ upiId: z .string() - .refine((value) => (/^[0-9A-Za-z._-]{2,256}@[A-Za-z]{2,64}$/).test(value), { + .refine((value) => UPI_REGEX.test(value), { message: 'Enter a valid UPI address', }) .optional(), solanaAddress: z .string() - .refine((value) => (/^[A-Za-z0-9]{44}$/).test(value), { + .refine((value) => SOLANA_ADDRESS_REGEX.test(value), { message: 'Enter a valid Solana address', }) .optional(), }); export const upiIdInsertSchema = z.object({ - upiId: z - .string() - .refine((value) => (/^[0-9A_Za-z._-]{2,256}@[A_Za-z]{2,64}$/).test(value), { - message: 'Invalid UPI address', - }), + upiId: z.string().refine((value) => UPI_REGEX.test(value), { + message: 'Invalid UPI address', + }), }); export const solanaAddressInsertSchema = z.object({ - solanaAddress: z.string().refine((value) => (/^[A-Za-z0-9]{44}$/).test(value), { - message: 'Invalid Solana address', - }), + solanaAddress: z + .string() + .refine((value) => SOLANA_ADDRESS_REGEX.test(value), { + message: 'Invalid Solana address', + }), }); export const payoutMethodDeleteSchema = z.object({ diff --git a/src/app/admin/add-course/page.tsx b/src/app/admin/add-course/page.tsx index dace4c5a8..d4b6d5609 100644 --- a/src/app/admin/add-course/page.tsx +++ b/src/app/admin/add-course/page.tsx @@ -1,12 +1,7 @@ 'use client'; import { Button } from '@/components/ui/button'; -import { - Card, - CardContent, - CardHeader, - CardTitle, -} from '@/components/ui/card'; +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Form, FormControl, @@ -29,7 +24,7 @@ import { AccordionContent, AccordionItem, AccordionTrigger, -} from "@/components/ui/accordion"; +} from '@/components/ui/accordion'; import { Cuboid, PackagePlus } from 'lucide-react'; import { FaDiscord } from 'react-icons/fa'; @@ -86,24 +81,32 @@ export default function Courses() { return (
- -
+
-

View Content

+

View Content

- + - -
- New course + +
+ + New course
-
-
Create new course for 100xdevs community and let user explore new courses
-
- +
+
+ Create new course for 100xdevs community and let user explore + new courses +
+
+ {/* Create a new course */} Fill in the course details below @@ -121,7 +124,11 @@ export default function Courses() { Title - + @@ -134,7 +141,11 @@ export default function Courses() { Image url - + @@ -144,11 +155,12 @@ export default function Courses() { control={form.control} name="description" render={({ field }: { field: any }) => ( - + Description