1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
import { redirect } from "next/navigation";
import MobileSidebar from "@/components/shared/sidebar/MobileSidebar";
import Sidebar from "@/components/shared/sidebar/Sidebar";
import SidebarLayout from "@/components/shared/sidebar/SidebarLayout";
import { ReaderSettingsProvider } from "@/lib/readerSettings";
import { UserSettingsContextProvider } from "@/lib/userSettings";
import { api } from "@/server/api/client";
import { getServerAuthSession } from "@/server/auth";
import { TRPCError } from "@trpc/server";
import { TFunction } from "i18next";
import {
ArrowLeft,
BarChart3,
CloudDownload,
CreditCard,
Download,
GitBranch,
Image,
KeyRound,
Link,
Rss,
Sparkles,
User,
Webhook,
} from "lucide-react";
import serverConfig from "@karakeep/shared/config";
import { tryCatch } from "@karakeep/shared/tryCatch";
const settingsSidebarItems = (
t: TFunction,
): {
name: string;
icon: React.ReactElement;
path: string;
}[] => {
return [
{
name: t("settings.back_to_app"),
icon: <ArrowLeft size={18} />,
path: "/dashboard/bookmarks",
},
{
name: t("settings.info.user_info"),
icon: <User size={18} />,
path: "/settings/info",
},
{
name: t("settings.stats.usage_statistics"),
icon: <BarChart3 size={18} />,
path: "/settings/stats",
},
...(serverConfig.stripe.isConfigured
? [
{
name: t("settings.subscription.subscription"),
icon: <CreditCard size={18} />,
path: "/settings/subscription",
},
]
: []),
...(serverConfig.inference.isConfigured
? [
{
name: t("settings.ai.ai_settings"),
icon: <Sparkles size={18} />,
path: "/settings/ai",
},
]
: []),
{
name: t("settings.feeds.rss_subscriptions"),
icon: <Rss size={18} />,
path: "/settings/feeds",
},
{
name: t("settings.backups.backups"),
icon: <CloudDownload size={18} />,
path: "/settings/backups",
},
{
name: t("settings.import.import_export"),
icon: <Download size={18} />,
path: "/settings/import",
},
{
name: t("settings.api_keys.api_keys"),
icon: <KeyRound size={18} />,
path: "/settings/api-keys",
},
{
name: t("settings.broken_links.broken_links"),
icon: <Link size={18} />,
path: "/settings/broken-links",
},
{
name: t("settings.webhooks.webhooks"),
icon: <Webhook size={18} />,
path: "/settings/webhooks",
},
{
name: t("settings.rules.rules"),
icon: <GitBranch size={18} />,
path: "/settings/rules",
},
{
name: t("settings.manage_assets.manage_assets"),
icon: <Image size={18} />,
path: "/settings/assets",
},
];
};
export default async function SettingsLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
const session = await getServerAuthSession();
if (!session) {
redirect("/");
}
const userSettings = await tryCatch(api.users.settings());
if (userSettings.error) {
if (userSettings.error instanceof TRPCError) {
if (
userSettings.error.code === "NOT_FOUND" ||
userSettings.error.code === "UNAUTHORIZED"
) {
redirect("/logout");
}
}
throw userSettings.error;
}
return (
<UserSettingsContextProvider userSettings={userSettings.data}>
<ReaderSettingsProvider>
<SidebarLayout
sidebar={<Sidebar items={settingsSidebarItems} />}
mobileSidebar={<MobileSidebar items={settingsSidebarItems} />}
>
{children}
</SidebarLayout>
</ReaderSettingsProvider>
</UserSettingsContextProvider>
);
}
|