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,96 @@
|
||||
import { ActionFunctionArgs, LoaderFunctionArgs, MetaFunction } from "react-router";
|
||||
import { Form, useActionData, useSubmit } from "react-router";
|
||||
import { FormEvent, useRef } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import ButtonPrimary from "~/components/ui/buttons/ButtonPrimary";
|
||||
import ActionResultModal from "~/components/ui/modals/ActionResultModal";
|
||||
import ConfirmModal, { RefConfirmModal } from "~/components/ui/modals/ConfirmModal";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import { validateCSRFToken } from "~/utils/session.server";
|
||||
import { appendCSRFToken } from "~/utils/csrf";
|
||||
|
||||
type LoaderData = {
|
||||
title: string;
|
||||
};
|
||||
|
||||
export const loader = async ({ request }: LoaderFunctionArgs): Promise<LoaderData> => {
|
||||
await verifyUserHasPermission(request, "admin.kb.view");
|
||||
const { t } = await getTranslations(request);
|
||||
return { title: t("knowledgeBase.adminDanger.metaTitle") };
|
||||
};
|
||||
|
||||
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
|
||||
|
||||
type ActionData = {
|
||||
error?: string;
|
||||
success?: string;
|
||||
};
|
||||
export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
await verifyUserHasPermission(request, "admin.kb.view");
|
||||
await validateCSRFToken(request);
|
||||
const { t } = await getTranslations(request);
|
||||
const form = await request.formData();
|
||||
const action = form.get("action")?.toString();
|
||||
if (action === "reset-all-data") {
|
||||
await verifyUserHasPermission(request, "admin.kb.delete");
|
||||
await db.knowledgeBaseCategory.deleteMany({});
|
||||
await db.knowledgeBaseArticle.deleteMany({});
|
||||
await db.knowledgeBase.deleteMany({});
|
||||
return Response.json({ success: t("knowledgeBase.admin.success.resetSuccessful") });
|
||||
} else {
|
||||
return Response.json({ error: t("knowledgeBase.admin.errors.invalidForm") }, { status: 400 });
|
||||
}
|
||||
};
|
||||
|
||||
export default function () {
|
||||
const { t } = useTranslation();
|
||||
const actionData = useActionData<ActionData>();
|
||||
|
||||
const submit = useSubmit();
|
||||
|
||||
const confirmDelete = useRef<RefConfirmModal>(null);
|
||||
|
||||
function handleSubmit(e: FormEvent) {
|
||||
e.preventDefault();
|
||||
onDelete();
|
||||
}
|
||||
function onDelete() {
|
||||
confirmDelete.current?.show(t("knowledgeBase.adminDanger.confirmReset"));
|
||||
}
|
||||
|
||||
function onConfirmedDelete() {
|
||||
const form = new FormData();
|
||||
appendCSRFToken(form);
|
||||
form.set("action", "reset-all-data");
|
||||
submit(form, {
|
||||
method: "post",
|
||||
});
|
||||
}
|
||||
return (
|
||||
<div className="flex-1 overflow-x-auto xl:overflow-y-auto">
|
||||
<div className="mx-auto max-w-5xl px-4 py-4 sm:px-6 lg:px-8 lg:py-12">
|
||||
<h1 className="text-foreground text-3xl font-bold tracking-tight">{t("knowledgeBase.adminDanger.metaTitle")}</h1>
|
||||
|
||||
<Form onSubmit={handleSubmit} method="post" className="divide-y-gray-200 mt-6 space-y-8 divide-y">
|
||||
<input name="action" value="reset-all-data" 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("knowledgeBase.adminDanger.resetAllData")}</h2>
|
||||
<p className="text-muted-foreground mt-1 text-sm">{t("knowledgeBase.adminDanger.resetAllDataDescription")}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end pt-8">
|
||||
<ButtonPrimary destructive type="submit">
|
||||
{t("knowledgeBase.adminDanger.resetAllData")}
|
||||
</ButtonPrimary>
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
<ActionResultModal actionData={actionData} showSuccess={false} />
|
||||
<ConfirmModal ref={confirmDelete} onYes={onConfirmedDelete} destructive />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user