Skip to content

Commit

Permalink
Fix eslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aamirazad committed Jun 24, 2024
1 parent f39389c commit 4066f69
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 76 deletions.
5 changes: 3 additions & 2 deletions src/app/paperless/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { zodResolver } from "@hookform/resolvers/zod";
Expand Down Expand Up @@ -61,7 +62,7 @@ function DocumentsSearch() {

return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4 w-64">
<FormField
control={form.control}
name="query"
Expand All @@ -71,6 +72,7 @@ function DocumentsSearch() {
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
Expand All @@ -90,7 +92,6 @@ function DocumentsPage() {
queryKey: ["key", query],
queryFn: async () => {
if (!query) {
// Immediately resolve to null or an appropriate default value if there's no query
return Promise.resolve(null);
}
const response = await getPaperlessDocuments(query);
Expand Down
69 changes: 1 addition & 68 deletions src/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,74 +23,6 @@ import { setUserProperty } from "../actions";
import { Toaster } from "@/components/ui/sonner";
import { toast } from "sonner";

function FullName({
setActiveTab,
}: {
setActiveTab: Dispatch<SetStateAction<number>>;
}) {
const { user, isLoaded } = useUser();
const pathname = usePathname();
const formSchema = z.object({
FullName: z.string().min(1, {
message: "Required.",
}),
});
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: {
FullName: "",
},
});

if (!isLoaded) {
return <LoadingSpinner>Loading...</LoadingSpinner>;
}

if (!user) {
return redirect("/sign-in?redirect=" + pathname);
}

async function onSubmit(values: z.infer<typeof formSchema>) {
setActiveTab((prevTab) => prevTab + 1); // Increment activeTab
try {
await setUserProperty("fullName", values.FullName);
// Operation succeeded, show success toast
toast("Your name preferences was saved");
// Optionally, move to a new tab or take another action to indicate success
} catch {
// Operation failed, show error toast
toast("Uh oh! Something went wrong.", {
description: "Your name preferences were not saved.",
action: {
label: "Go back",
onClick: () => setActiveTab(0), // Go back to try again
},
});
}
}

return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="w-64 space-y-4">
<FormField
control={form.control}
name="FullName"
render={({ field }) => (
<FormItem>
<FormLabel>Full Name</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button type="submit">Submit</Button>
</form>
</Form>
);
}

function PaperlessURL({
setActiveTab,
}: {
Expand Down Expand Up @@ -152,6 +84,7 @@ function PaperlessURL({
<Input {...field} />
</FormControl>
<FormDescription>Leave empty to disable</FormDescription>
<FormMessage />
</FormItem>
)}
/>
Expand Down
8 changes: 4 additions & 4 deletions src/components/ui/form.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from "react"
import * as LabelPrimitive from "@radix-ui/react-label"
import type * as LabelPrimitive from "@radix-ui/react-label"
import { Slot } from "@radix-ui/react-slot"
import {
Controller,
ControllerProps,
FieldPath,
FieldValues,
type ControllerProps,
type FieldPath,
type FieldValues,
FormProvider,
useFormContext,
} from "react-hook-form"
Expand Down
3 changes: 1 addition & 2 deletions src/components/ui/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import * as React from "react"

import { cn } from "@/lib/utils"

export interface InputProps
extends React.InputHTMLAttributes<HTMLInputElement> {}
export type InputProps = React.InputHTMLAttributes<HTMLInputElement>

const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, ...props }, ref) => {
Expand Down

0 comments on commit 4066f69

Please sign in to comment.