Skip to content

Commit 2432e34

Browse files
committed
Linted and formatted shadcn/ui components with ESLint and Prettier. Refactored form to use optional chaining in defaultValues assignments
1 parent 10e9889 commit 2432e34

File tree

16 files changed

+297
-294
lines changed

16 files changed

+297
-294
lines changed

app/(root)/ask-question/page.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ export const metadata: Metadata = {
1010
title: "Ask a Question — DevOverflow",
1111
};
1212

13-
type Props = {};
14-
15-
const Page = async (props: Props) => {
13+
const Page = async () => {
1614
const { userId } = auth();
1715

1816
if (!userId) return null;

components/forms/Profile.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ const Profile = ({ clerkId, user }: Props) => {
3737
const form = useForm<z.infer<typeof ProfileValidation>>({
3838
resolver: zodResolver(ProfileValidation),
3939
defaultValues: {
40-
name: parsedUser.name || "",
41-
username: parsedUser.username || "",
42-
portfolioWebsite: parsedUser.portfolioWebsite || "",
43-
location: parsedUser.location || "",
44-
bio: parsedUser.bio || "",
40+
name: parsedUser?.name || "",
41+
username: parsedUser?.username || "",
42+
portfolioWebsite: parsedUser?.portfolioWebsite || "",
43+
location: parsedUser?.location || "",
44+
bio: parsedUser?.bio || "",
4545
},
4646
});
4747

@@ -61,7 +61,7 @@ const Profile = ({ clerkId, user }: Props) => {
6161
},
6262
path: pathname,
6363
});
64-
router.back();
64+
router.push("/");
6565
} catch (error) {
6666
toast({
6767
title: "Error updating profile ⚠️",

components/ui/badge.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import * as React from "react"
2-
import { cva, type VariantProps } from "class-variance-authority"
1+
import * as React from "react";
2+
import { cva, type VariantProps } from "class-variance-authority";
33

4-
import { cn } from "@/lib/utils"
4+
import { cn } from "@/lib/utils";
55

66
const badgeVariants = cva(
7-
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
7+
"focus:ring-ring inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2",
88
{
99
variants: {
1010
variant: {
1111
default:
12-
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
12+
"bg-primary text-primary-foreground hover:bg-primary/80 border-transparent",
1313
secondary:
14-
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
14+
"bg-secondary text-secondary-foreground hover:bg-secondary/80 border-transparent",
1515
destructive:
16-
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
16+
"bg-destructive text-destructive-foreground hover:bg-destructive/80 border-transparent",
1717
outline: "text-foreground",
1818
},
1919
},
2020
defaultVariants: {
2121
variant: "default",
2222
},
2323
}
24-
)
24+
);
2525

2626
export interface BadgeProps
2727
extends React.HTMLAttributes<HTMLDivElement>,
@@ -30,7 +30,7 @@ export interface BadgeProps
3030
function Badge({ className, variant, ...props }: BadgeProps) {
3131
return (
3232
<div className={cn(badgeVariants({ variant }), className)} {...props} />
33-
)
33+
);
3434
}
3535

36-
export { Badge, badgeVariants }
36+
export { Badge, badgeVariants };

components/ui/button.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import * as React from "react"
2-
import { Slot } from "@radix-ui/react-slot"
3-
import { cva, type VariantProps } from "class-variance-authority"
1+
import * as React from "react";
2+
import { Slot } from "@radix-ui/react-slot";
3+
import { cva, type VariantProps } from "class-variance-authority";
44

5-
import { cn } from "@/lib/utils"
5+
import { cn } from "@/lib/utils";
66

77
const buttonVariants = cva(
8-
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
8+
"ring-offset-background focus-visible:ring-ring inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
99
{
1010
variants: {
1111
variant: {
1212
default: "bg-primary text-primary-foreground hover:bg-primary/90",
1313
destructive:
1414
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
1515
outline:
16-
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
16+
"border-input bg-background hover:bg-accent hover:text-accent-foreground border",
1717
secondary:
1818
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
1919
ghost: "hover:bg-accent hover:text-accent-foreground",
@@ -31,26 +31,26 @@ const buttonVariants = cva(
3131
size: "default",
3232
},
3333
}
34-
)
34+
);
3535

3636
export interface ButtonProps
3737
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
3838
VariantProps<typeof buttonVariants> {
39-
asChild?: boolean
39+
asChild?: boolean;
4040
}
4141

4242
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
4343
({ className, variant, size, asChild = false, ...props }, ref) => {
44-
const Comp = asChild ? Slot : "button"
44+
const Comp = asChild ? Slot : "button";
4545
return (
4646
<Comp
4747
className={cn(buttonVariants({ variant, size, className }))}
4848
ref={ref}
4949
{...props}
5050
/>
51-
)
51+
);
5252
}
53-
)
54-
Button.displayName = "Button"
53+
);
54+
Button.displayName = "Button";
5555

56-
export { Button, buttonVariants }
56+
export { Button, buttonVariants };

components/ui/form.tsx

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
import * as React from "react"
2-
import * as LabelPrimitive from "@radix-ui/react-label"
3-
import { Slot } from "@radix-ui/react-slot"
1+
import * as React from "react";
2+
import * as LabelPrimitive from "@radix-ui/react-label";
3+
import { Slot } from "@radix-ui/react-slot";
44
import {
55
Controller,
66
ControllerProps,
77
FieldPath,
88
FieldValues,
99
FormProvider,
1010
useFormContext,
11-
} from "react-hook-form"
11+
} from "react-hook-form";
1212

13-
import { cn } from "@/lib/utils"
14-
import { Label } from "@/components/ui/label"
13+
import { cn } from "@/lib/utils";
14+
import { Label } from "@/components/ui/label";
1515

16-
const Form = FormProvider
16+
const Form = FormProvider;
1717

1818
type FormFieldContextValue<
1919
TFieldValues extends FieldValues = FieldValues,
20-
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
20+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
2121
> = {
22-
name: TName
23-
}
22+
name: TName;
23+
};
2424

2525
const FormFieldContext = React.createContext<FormFieldContextValue>(
2626
{} as FormFieldContextValue
27-
)
27+
);
2828

2929
const FormField = <
3030
TFieldValues extends FieldValues = FieldValues,
31-
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
31+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
3232
>({
3333
...props
3434
}: ControllerProps<TFieldValues, TName>) => {
3535
return (
3636
<FormFieldContext.Provider value={{ name: props.name }}>
3737
<Controller {...props} />
3838
</FormFieldContext.Provider>
39-
)
40-
}
39+
);
40+
};
4141

4242
const useFormField = () => {
43-
const fieldContext = React.useContext(FormFieldContext)
44-
const itemContext = React.useContext(FormItemContext)
45-
const { getFieldState, formState } = useFormContext()
43+
const fieldContext = React.useContext(FormFieldContext);
44+
const itemContext = React.useContext(FormItemContext);
45+
const { getFieldState, formState } = useFormContext();
4646

47-
const fieldState = getFieldState(fieldContext.name, formState)
47+
const fieldState = getFieldState(fieldContext.name, formState);
4848

4949
if (!fieldContext) {
50-
throw new Error("useFormField should be used within <FormField>")
50+
throw new Error("useFormField should be used within <FormField>");
5151
}
5252

53-
const { id } = itemContext
53+
const { id } = itemContext;
5454

5555
return {
5656
id,
@@ -59,36 +59,36 @@ const useFormField = () => {
5959
formDescriptionId: `${id}-form-item-description`,
6060
formMessageId: `${id}-form-item-message`,
6161
...fieldState,
62-
}
63-
}
62+
};
63+
};
6464

6565
type FormItemContextValue = {
66-
id: string
67-
}
66+
id: string;
67+
};
6868

6969
const FormItemContext = React.createContext<FormItemContextValue>(
7070
{} as FormItemContextValue
71-
)
71+
);
7272

7373
const FormItem = React.forwardRef<
7474
HTMLDivElement,
7575
React.HTMLAttributes<HTMLDivElement>
7676
>(({ className, ...props }, ref) => {
77-
const id = React.useId()
77+
const id = React.useId();
7878

7979
return (
8080
<FormItemContext.Provider value={{ id }}>
8181
<div ref={ref} className={cn("space-y-2", className)} {...props} />
8282
</FormItemContext.Provider>
83-
)
84-
})
85-
FormItem.displayName = "FormItem"
83+
);
84+
});
85+
FormItem.displayName = "FormItem";
8686

8787
const FormLabel = React.forwardRef<
8888
React.ElementRef<typeof LabelPrimitive.Root>,
8989
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
9090
>(({ className, ...props }, ref) => {
91-
const { error, formItemId } = useFormField()
91+
const { error, formItemId } = useFormField();
9292

9393
return (
9494
<Label
@@ -97,15 +97,16 @@ const FormLabel = React.forwardRef<
9797
htmlFor={formItemId}
9898
{...props}
9999
/>
100-
)
101-
})
102-
FormLabel.displayName = "FormLabel"
100+
);
101+
});
102+
FormLabel.displayName = "FormLabel";
103103

104104
const FormControl = React.forwardRef<
105105
React.ElementRef<typeof Slot>,
106106
React.ComponentPropsWithoutRef<typeof Slot>
107107
>(({ ...props }, ref) => {
108-
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
108+
const { error, formItemId, formDescriptionId, formMessageId } =
109+
useFormField();
109110

110111
return (
111112
<Slot
@@ -119,15 +120,15 @@ const FormControl = React.forwardRef<
119120
aria-invalid={!!error}
120121
{...props}
121122
/>
122-
)
123-
})
124-
FormControl.displayName = "FormControl"
123+
);
124+
});
125+
FormControl.displayName = "FormControl";
125126

126127
const FormDescription = React.forwardRef<
127128
HTMLParagraphElement,
128129
React.HTMLAttributes<HTMLParagraphElement>
129130
>(({ className, ...props }, ref) => {
130-
const { formDescriptionId } = useFormField()
131+
const { formDescriptionId } = useFormField();
131132

132133
return (
133134
<p
@@ -136,19 +137,19 @@ const FormDescription = React.forwardRef<
136137
className={cn("text-sm text-muted-foreground", className)}
137138
{...props}
138139
/>
139-
)
140-
})
141-
FormDescription.displayName = "FormDescription"
140+
);
141+
});
142+
FormDescription.displayName = "FormDescription";
142143

143144
const FormMessage = React.forwardRef<
144145
HTMLParagraphElement,
145146
React.HTMLAttributes<HTMLParagraphElement>
146147
>(({ className, children, ...props }, ref) => {
147-
const { error, formMessageId } = useFormField()
148-
const body = error ? String(error?.message) : children
148+
const { error, formMessageId } = useFormField();
149+
const body = error ? String(error?.message) : children;
149150

150151
if (!body) {
151-
return null
152+
return null;
152153
}
153154

154155
return (
@@ -160,9 +161,9 @@ const FormMessage = React.forwardRef<
160161
>
161162
{body}
162163
</p>
163-
)
164-
})
165-
FormMessage.displayName = "FormMessage"
164+
);
165+
});
166+
FormMessage.displayName = "FormMessage";
166167

167168
export {
168169
useFormField,
@@ -173,4 +174,4 @@ export {
173174
FormDescription,
174175
FormMessage,
175176
FormField,
176-
}
177+
};

components/ui/input.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as React from "react"
1+
import * as React from "react";
22

3-
import { cn } from "@/lib/utils"
3+
import { cn } from "@/lib/utils";
44

55
export interface InputProps
66
extends React.InputHTMLAttributes<HTMLInputElement> {}
@@ -17,9 +17,9 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
1717
ref={ref}
1818
{...props}
1919
/>
20-
)
20+
);
2121
}
22-
)
23-
Input.displayName = "Input"
22+
);
23+
Input.displayName = "Input";
2424

25-
export { Input }
25+
export { Input };

0 commit comments

Comments
 (0)