Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,71 @@
|
||||
import { ActionFunction, LoaderFunctionArgs, MetaFunction, useLoaderData } from "react-router";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { getTenantWithProfile, updateTenantTheme, TenantWithProfile } from "~/utils/db/tenants.db.server";
|
||||
import { getTenantIdFromUrl } from "~/utils/services/.server/urlService";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import EditPageLayout from "~/components/ui/layouts/EditPageLayout";
|
||||
import UpdateTenantFormTheme from "~/components/core/tenants/forms/UpdateTenantFormTheme";
|
||||
import { validateCSRFToken } from "~/utils/session.server";
|
||||
|
||||
type LoaderData = {
|
||||
title: string;
|
||||
tenant: TenantWithProfile;
|
||||
};
|
||||
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const tenantId = await getTenantIdFromUrl(params);
|
||||
await verifyUserHasPermission(request, "app.settings.account.view", tenantId);
|
||||
const { t } = await getTranslations(request);
|
||||
const tenant = await getTenantWithProfile(tenantId);
|
||||
if (!tenant) {
|
||||
throw Error(t("shared.notFound"));
|
||||
}
|
||||
const data: LoaderData = {
|
||||
title: t("settings.theme.metaTitle", { appName: process.env.APP_NAME }),
|
||||
tenant,
|
||||
};
|
||||
return data;
|
||||
};
|
||||
|
||||
type ActionData = {
|
||||
error?: string;
|
||||
success?: string;
|
||||
};
|
||||
|
||||
const badRequest = (data: ActionData) => Response.json(data, { status: 400 });
|
||||
|
||||
export const action: ActionFunction = async ({ request, params }) => {
|
||||
const { t } = await getTranslations(request);
|
||||
const tenantId = await getTenantIdFromUrl(params);
|
||||
await verifyUserHasPermission(request, "app.settings.account.update", tenantId);
|
||||
|
||||
await validateCSRFToken(request);
|
||||
const form = await request.formData();
|
||||
const action = form.get("action")?.toString() ?? "";
|
||||
|
||||
if (action === "update-theme") {
|
||||
try {
|
||||
const theme = form.get("theme")?.toString() || null;
|
||||
const themeConfig = form.get("themeConfig")?.toString() || null;
|
||||
await updateTenantTheme(tenantId, { theme, themeConfig });
|
||||
return Response.json({ success: t("shared.updated") });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return badRequest({ error: t("shared.unexpectedError") });
|
||||
}
|
||||
}
|
||||
|
||||
return badRequest({ error: t("shared.invalidForm") });
|
||||
};
|
||||
|
||||
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
export default function ThemeSettingsRoute() {
|
||||
const data = useLoaderData<LoaderData>();
|
||||
|
||||
return (
|
||||
<EditPageLayout>
|
||||
<UpdateTenantFormTheme tenant={data.tenant} />
|
||||
</EditPageLayout>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user