From 148b1ff2db8c998af5c185101fefb49ce28db1dc Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 6 Apr 2025 03:32:39 -0600 Subject: [PATCH] refactor(user-nav): remove settings option for owner role and delete settings page - Removed the "Settings" dropdown menu item for users with the "owner" role in the UserNav component. - Deleted the settings page implementation, including all related components and logic. --- apps/dokploy/components/layouts/user-nav.tsx | 11 - .../pages/dashboard/settings/index.tsx | 219 ------------------ 2 files changed, 230 deletions(-) delete mode 100644 apps/dokploy/pages/dashboard/settings/index.tsx diff --git a/apps/dokploy/components/layouts/user-nav.tsx b/apps/dokploy/components/layouts/user-nav.tsx index 85cb96f30..0aca5b00d 100644 --- a/apps/dokploy/components/layouts/user-nav.tsx +++ b/apps/dokploy/components/layouts/user-nav.tsx @@ -120,17 +120,6 @@ export const UserNav = () => { Docker )} - - {data?.role === "owner" && ( - { - router.push("/dashboard/settings"); - }} - > - Settings - - )} ) : ( <> diff --git a/apps/dokploy/pages/dashboard/settings/index.tsx b/apps/dokploy/pages/dashboard/settings/index.tsx deleted file mode 100644 index 4c060cbb5..000000000 --- a/apps/dokploy/pages/dashboard/settings/index.tsx +++ /dev/null @@ -1,219 +0,0 @@ -import { DashboardLayout } from "@/components/layouts/dashboard-layout"; - -import { AlertBlock } from "@/components/shared/alert-block"; -import { Button } from "@/components/ui/button"; -import { - Card, - CardContent, - CardDescription, - CardHeader, - CardTitle, -} from "@/components/ui/card"; -import { DialogFooter } from "@/components/ui/dialog"; -import { - Form, - FormControl, - FormDescription, - FormField, - FormItem, - FormLabel, -} from "@/components/ui/form"; -import { Switch } from "@/components/ui/switch"; -import { appRouter } from "@/server/api/root"; -import { api } from "@/utils/api"; -import { validateRequest } from "@dokploy/server"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { createServerSideHelpers } from "@trpc/react-query/server"; -import { Settings } from "lucide-react"; -import type { GetServerSidePropsContext } from "next"; -import { type ReactElement, useEffect } from "react"; -import { useForm } from "react-hook-form"; -import { toast } from "sonner"; -import superjson from "superjson"; -import { z } from "zod"; - -const settings = z.object({ - cleanCacheOnApplications: z.boolean(), - cleanCacheOnCompose: z.boolean(), - cleanCacheOnPreviews: z.boolean(), -}); - -type SettingsType = z.infer; - -const Page = () => { - const { data, refetch } = api.user.get.useQuery(); - const { mutateAsync, isLoading, isError, error } = - api.user.update.useMutation(); - const form = useForm({ - defaultValues: { - cleanCacheOnApplications: false, - cleanCacheOnCompose: false, - cleanCacheOnPreviews: false, - }, - resolver: zodResolver(settings), - }); - useEffect(() => { - form.reset({ - cleanCacheOnApplications: data?.user.cleanupCacheApplications || false, - cleanCacheOnCompose: data?.user.cleanupCacheOnCompose || false, - cleanCacheOnPreviews: data?.user.cleanupCacheOnPreviews || false, - }); - }, [form, form.reset, form.formState.isSubmitSuccessful, data]); - - const onSubmit = async (values: SettingsType) => { - await mutateAsync({ - cleanupCacheApplications: values.cleanCacheOnApplications, - cleanupCacheOnCompose: values.cleanCacheOnCompose, - cleanupCacheOnPreviews: values.cleanCacheOnPreviews, - }) - .then(() => { - toast.success("Settings updated"); - refetch(); - }) - .catch(() => { - toast.error("Something went wrong"); - }); - }; - return ( -
- -
- - - - Settings - - Manage your Dokploy settings - {isError && {error?.message}} - - -
- - ( - -
- Clean Cache on Applications - - Clean the cache after every application deployment - -
- - - -
- )} - /> - ( - -
- Clean Cache on Previews - - Clean the cache after every preview deployment - -
- - - -
- )} - /> - ( - -
- Clean Cache on Compose - - Clean the cache after every compose deployment - -
- - - -
- )} - /> - - - - - -
-
-
-
- ); -}; - -export default Page; - -Page.getLayout = (page: ReactElement) => { - return {page}; -}; -export async function getServerSideProps( - ctx: GetServerSidePropsContext<{ serviceId: string }>, -) { - const { req, res } = ctx; - const { user, session } = await validateRequest(ctx.req); - if (!user) { - return { - redirect: { - permanent: true, - destination: "/", - }, - }; - } - if (user.role === "member") { - return { - redirect: { - permanent: true, - destination: "/dashboard/settings/profile", - }, - }; - } - - const helpers = createServerSideHelpers({ - router: appRouter, - ctx: { - req: req as any, - res: res as any, - db: null as any, - session: session as any, - user: user as any, - }, - transformer: superjson, - }); - await helpers.user.get.prefetch(); - - return { - props: { - trpcState: helpers.dehydrate(), - }, - }; -}