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,81 @@
|
||||
import { ActionFunction, LoaderFunctionArgs, MetaFunction } from "react-router";
|
||||
import { Form, useActionData, useLoaderData } from "react-router";
|
||||
import { useEffect } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import ButtonPrimary from "~/components/ui/buttons/ButtonPrimary";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { deleteAppConfiguration } from "~/utils/db/appConfiguration.db.server";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import EditPageLayout from "~/components/ui/layouts/EditPageLayout";
|
||||
import BackButtonWithTitle from "~/components/ui/buttons/BackButtonWithTitle";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { validateCSRFToken } from "~/utils/session.server";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
|
||||
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
type LoaderData = {
|
||||
title: string;
|
||||
};
|
||||
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
const { t } = await getTranslations(request);
|
||||
await verifyUserHasPermission(request, "admin.settings.danger.reset");
|
||||
const data: LoaderData = {
|
||||
title: `${t("settings.admin.danger.title")} | ${process.env.APP_NAME}`,
|
||||
};
|
||||
return data;
|
||||
};
|
||||
|
||||
type ActionData = {
|
||||
error?: string;
|
||||
success?: string;
|
||||
};
|
||||
export const action: ActionFunction = async ({ request }) => {
|
||||
const { t } = await getTranslations(request);
|
||||
await validateCSRFToken(request);
|
||||
const form = await request.formData();
|
||||
const action = form.get("action");
|
||||
if (action === "delete") {
|
||||
await verifyUserHasPermission(request, "admin.settings.danger.reset");
|
||||
await deleteAppConfiguration();
|
||||
return Response.json({ success: t("settings.admin.danger.resetSuccess") });
|
||||
} else {
|
||||
return Response.json({ error: t("shared.invalidForm") }, { status: 400 });
|
||||
}
|
||||
};
|
||||
|
||||
export default function AdminSettingsDanger() {
|
||||
const { t } = useTranslation();
|
||||
useLoaderData<LoaderData>();
|
||||
const actionData = useActionData<ActionData>();
|
||||
const rootData = useRootData();
|
||||
|
||||
useEffect(() => {
|
||||
if (actionData?.error) {
|
||||
toast.error(actionData?.error);
|
||||
} else if (actionData?.success) {
|
||||
toast.success(actionData?.success);
|
||||
}
|
||||
}, [actionData]);
|
||||
return (
|
||||
<EditPageLayout title={<BackButtonWithTitle href={adminPath("settings", { mode: "host-aware" })}>{t("settings.admin.danger.title")}</BackButtonWithTitle>}>
|
||||
<Form method="post" className="divide-y-gray-200 mt-6 space-y-8 divide-y">
|
||||
{rootData.csrf && <input hidden readOnly name="csrf" value={rootData.csrf} />}
|
||||
<input name="action" value="delete" hidden readOnly />
|
||||
<div className="grid grid-cols-1 gap-y-6 sm:grid-cols-6 sm:gap-x-6">
|
||||
<div className="sm:col-span-6">
|
||||
<h2 className="text-foreground text-xl font-medium">{t("settings.admin.danger.resetTitle")}</h2>
|
||||
<p className="text-muted-foreground mt-1 text-sm">{t("settings.admin.danger.resetDescription")}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end pt-8">
|
||||
<ButtonPrimary destructive type="submit">
|
||||
{t("settings.reset")}
|
||||
</ButtonPrimary>
|
||||
</div>
|
||||
</Form>
|
||||
</EditPageLayout>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user