Skip to content
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

Fix: Husky, Pre-commit #1376

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 44 additions & 8 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -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
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
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"trailingComma": "all",
"plugins": [
"prettier-plugin-tailwindcss"
]
],
"embeddedLanguageFormatting": "off"
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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",
Expand Down
23 changes: 13 additions & 10 deletions src/actions/payoutMethods/schema.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
124 changes: 79 additions & 45 deletions src/app/admin/add-course/page.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';

Expand Down Expand Up @@ -86,24 +81,32 @@ export default function Courses() {

return (
<div className="wrapper my-16 flex flex-col gap-4">

<section className='flex gap-2 border-2 p-4 bg-primary/5 rounded-lg my-4 items-center'>
<section className="my-4 flex items-center gap-2 rounded-lg border-2 bg-primary/5 p-4">
<Cuboid size={18} />
<h2 className='text-md font-bold'>View Content</h2>
<h2 className="text-md font-bold">View Content</h2>
</section>

<Accordion defaultValue='add-new-course' className='border-2 p-4 rounded-2xl' type="single" collapsible>
<Accordion
defaultValue="add-new-course"
className="rounded-2xl border-2 p-4"
type="single"
collapsible
>
<AccordionItem value="add-new-course">
<AccordionTrigger className='p-6 text-2xl font-bold'>
<div className='flex gap-4 flex-col' >
<PackagePlus size={40} />New course
<AccordionTrigger className="p-6 text-2xl font-bold">
<div className="flex flex-col gap-4">
<PackagePlus size={40} />
New course
</div>
</AccordionTrigger>
<AccordionContent>
<div className='w-full grid grid-cols-1 lg:grid-cols-7'>
<div className='text-sm font-semibold text-gray-400 col-span-1 lg:col-span-2 p-6'>Create new course for 100xdevs community and let user explore new courses</div>
<div className='col-span-1 lg:col-span-5 p-4'>
<Card className='bg-background border-2'>
<div className="grid w-full grid-cols-1 lg:grid-cols-7">
<div className="col-span-1 p-6 text-sm font-semibold text-gray-400 lg:col-span-2">
Create new course for 100xdevs community and let user explore
new courses
</div>
<div className="col-span-1 p-4 lg:col-span-5">
<Card className="border-2 bg-background">
<CardHeader>
{/* <CardTitle>Create a new course</CardTitle> */}
<CardTitle>Fill in the course details below</CardTitle>
Expand All @@ -121,7 +124,11 @@ export default function Courses() {
<FormItem>
<FormLabel>Title</FormLabel>
<FormControl>
<Input className='h-12 px-3' placeholder="Enter the Course name" {...field} />
<Input
className="h-12 px-3"
placeholder="Enter the Course name"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -134,7 +141,11 @@ export default function Courses() {
<FormItem>
<FormLabel>Image url</FormLabel>
<FormControl>
<Input className='h-12 px-3' placeholder="Enter the url of Image" {...field} />
<Input
className="h-12 px-3"
placeholder="Enter the url of Image"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -144,11 +155,12 @@ export default function Courses() {
control={form.control}
name="description"
render={({ field }: { field: any }) => (
<FormItem className='col-span-1 lg:col-span-2'>
<FormItem className="col-span-1 lg:col-span-2">
<FormLabel>Description</FormLabel>
<FormControl>
<Textarea
className='h-12 px-3' placeholder="Enter the Description of course"
className="h-12 px-3"
placeholder="Enter the Description of course"
{...field}
/>
</FormControl>
Expand All @@ -163,7 +175,11 @@ export default function Courses() {
<FormItem>
<FormLabel>Slug</FormLabel>
<FormControl>
<Input className='h-12 px-3' placeholder="Enter the Course slug" {...field} />
<Input
className="h-12 px-3"
placeholder="Enter the Course slug"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -176,7 +192,11 @@ export default function Courses() {
<FormItem>
<FormLabel>Id</FormLabel>
<FormControl>
<Input className='h-12 px-3' placeholder="Enter the Course ID" {...field} />
<Input
className="h-12 px-3"
placeholder="Enter the Course ID"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -189,7 +209,11 @@ export default function Courses() {
<FormItem>
<FormLabel>Admin Secret</FormLabel>
<FormControl>
<Input className='h-12 px-3' placeholder="Enter the Admin Secret" {...field} />
<Input
className="h-12 px-3"
placeholder="Enter the Admin Secret"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
Expand All @@ -203,7 +227,8 @@ export default function Courses() {
<FormLabel>app x course id</FormLabel>
<FormControl>
<Input
className='h-12 px-3' placeholder="Enter the appx course ID"
className="h-12 px-3"
placeholder="Enter the appx course ID"
{...field}
/>
</FormControl>
Expand Down Expand Up @@ -231,7 +256,9 @@ export default function Courses() {
{isLoading ? (
<Button>Loading...</Button>
) : (
<Button className='w-[20%]' type="submit">Create</Button>
<Button className="w-[20%]" type="submit">
Create
</Button>
)}
</div>
</form>
Expand All @@ -243,24 +270,28 @@ export default function Courses() {
</AccordionContent>
</AccordionItem>

<AccordionItem className='border-none' value="discord-config">
<AccordionTrigger className='p-6 text-2xl font-bold'>
<div className='flex gap-4 flex-col' >
<FaDiscord className='text-5xl' /> Discord Config
<AccordionItem className="border-none" value="discord-config">
<AccordionTrigger className="p-6 text-2xl font-bold">
<div className="flex flex-col gap-4">
<FaDiscord className="text-5xl" /> Discord Config
</div>
</AccordionTrigger>
<AccordionContent>
<div className='w-full grid grid-cols-1 lg:grid-cols-7'>
<div className='text-sm font-semibold text-gray-400col-span-1 lg:col-span-2 p-6'>Mangae discord configuration for the users</div>
<div className='col-span-1 lg:col-span-5 p-4'>
<Card className='bg-background'>
<div className="grid w-full grid-cols-1 lg:grid-cols-7">
<div className="text-gray-400col-span-1 p-6 text-sm font-semibold lg:col-span-2">
Mangae discord configuration for the users
</div>
<div className="col-span-1 p-4 lg:col-span-5">
<Card className="bg-background">
<CardHeader>
<CardTitle>Discord</CardTitle>
</CardHeader>
<CardContent className="flex flex-col gap-5 lg:flex-row">
<Card className="mx-auto border-2 bg-background w-full max-w-3xl overflow-y-auto">
<Card className="mx-auto w-full max-w-3xl overflow-y-auto border-2 bg-background">
<CardHeader>
<CardTitle>Allow user another account in cohort 3</CardTitle>
<CardTitle>
Allow user another account in cohort 3
</CardTitle>
</CardHeader>
<CardContent className="grid gap-4 p-4 pt-0">
<Input
Expand All @@ -280,10 +311,13 @@ export default function Courses() {
<Button
onClick={async () => {
try {
const res = await axios.post('/api/admin/discordReset', {
email,
adminPassword,
});
const res = await axios.post(
'/api/admin/discordReset',
{
email,
adminPassword,
},
);
toast(JSON.stringify(res.data.data));
} catch (error) {
//@ts-ignore
Expand All @@ -295,9 +329,11 @@ export default function Courses() {
</Button>
</CardContent>
</Card>
<Card className="mx-auto border-2 bg-background w-full max-w-3xl overflow-y-auto">
<Card className="mx-auto w-full max-w-3xl overflow-y-auto border-2 bg-background">
<CardHeader>
<CardTitle>Get users discord username in cohort 3</CardTitle>
<CardTitle>
Get users discord username in cohort 3
</CardTitle>
</CardHeader>
<CardContent className="grid gap-4 p-4 pt-0">
<Input
Expand Down Expand Up @@ -340,9 +376,7 @@ export default function Courses() {
</div>
</AccordionContent>
</AccordionItem>

</Accordion>

</div>
);
}
Loading
Loading