diff --git a/src/app/paperless/page.tsx b/src/app/paperless/page.tsx index 9ee33d1..4f2c6ad 100644 --- a/src/app/paperless/page.tsx +++ b/src/app/paperless/page.tsx @@ -60,7 +60,7 @@ function DocumentsSearch() { return (
- + { + const data = await getUserData(); + return data; + }, + }); + const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { @@ -40,8 +57,11 @@ function PaperlessURL({ }, }); - if (!isLoaded) { + if (!isLoaded || isLoading || !userData) { return Loading...; + } else if (userData.paperlessURL && !isAutofilled) { + form.setValue("URL", userData.paperlessURL); + setIsAutofilled(true); } if (!user) { @@ -65,7 +85,7 @@ function PaperlessURL({ description: "Your Paperless URL preferences were not saved.", action: { label: "Go back", - onClick: () => setActiveTab(1), // Go back to try again + onClick: () => setActiveTab((prevTab) => prevTab - 1), // Go back to try again }, }); } @@ -81,7 +101,7 @@ function PaperlessURL({ Paperless URL - + Leave empty to disable @@ -101,9 +121,18 @@ function PaperlessToken({ }) { const { user, isLoaded } = useUser(); const pathname = usePathname(); + const [isAutofilled, setIsAutofilled] = useState(false); + const [isHidden, setIsHidden] = useState(false); const formSchema = z.object({ token: z.string(), }); + const { data: userData, isLoading } = useQuery({ + queryKey: ["userData"], + queryFn: async () => { + const data = await getUserData(); + return data; + }, + }); const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { @@ -111,8 +140,11 @@ function PaperlessToken({ }, }); - if (!isLoaded) { + if (!isLoaded || isLoading || !userData) { return Loading...; + } else if (userData.paperlessToken && !isAutofilled) { + form.setValue("token", userData.paperlessToken); + setIsAutofilled(true); } if (!user) { @@ -132,7 +164,7 @@ function PaperlessToken({ description: "Your Paperless token preferences were not saved.", action: { label: "Go back", - onClick: () => setActiveTab(1), // Go back to try again + onClick: () => setActiveTab((prevTab) => prevTab - 1), // Go back to try again }, }); } @@ -148,7 +180,14 @@ function PaperlessToken({ Paperless API Token - +
+ + {isHidden ? ( + setIsHidden(false)} /> + ) : ( + setIsHidden(true)} /> + )} +
You can create (or re-create) an API token by opening the @@ -177,7 +216,7 @@ const ProgressIndicator: React.FC = ({ }) => { return (
- {Array.from({ length: totalTabs - 1 }, (_, index) => ( + {Array.from({ length: totalTabs }, (_, index) => ( setActiveTab(index)} key={index} @@ -199,7 +238,9 @@ export default function SettingsPage() { ]; return ( <> - {formElements[activeTab]} + + {formElements[activeTab]} +