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,59 @@
|
||||
import { LoaderFunctionArgs } from "react-router";
|
||||
import { Link } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
type LoaderData = {};
|
||||
export const loader = async ({ params }: LoaderFunctionArgs) => {
|
||||
const data: LoaderData = {};
|
||||
return data;
|
||||
};
|
||||
|
||||
type CreateTemplateType = {
|
||||
titleKey: string;
|
||||
descriptionKey: string;
|
||||
href: string;
|
||||
enterprise?: boolean;
|
||||
underConstruction?: boolean;
|
||||
};
|
||||
|
||||
const types: CreateTemplateType[] = [
|
||||
{
|
||||
titleKey: "models.entityTemplate.manual",
|
||||
descriptionKey: "models.entityTemplate.uploadJsonConfiguration",
|
||||
href: "manual",
|
||||
},
|
||||
];
|
||||
|
||||
export default function AdminEntityNoCodeRoute() {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className="mx-auto w-full max-w-5xl space-y-3 px-4 py-2 pb-6 sm:px-6 sm:pt-3 lg:px-8 xl:max-w-full">
|
||||
<div className="md:border-border md:border-b md:py-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-foreground text-lg font-medium leading-6">{t("models.entityTemplate.plural")}</h3>
|
||||
{/* <div className="flex items-center space-x-2">
|
||||
<InputFilters withSearch={false} filters={data.filterableProperties} />
|
||||
</div> */}
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid gap-2 md:grid-cols-2 lg:grid-cols-3">
|
||||
{types.map((item) => {
|
||||
return (
|
||||
<Link
|
||||
key={item.titleKey}
|
||||
to={item.href}
|
||||
className="border-border focus:bg-background hover:border-border relative flex w-full flex-col justify-center space-y-2 rounded-lg border-2 border-dashed p-3 text-center focus:border-2 focus:border-gray-600 focus:outline-hidden"
|
||||
>
|
||||
<div className="text-foreground block text-sm font-medium">
|
||||
{t(item.titleKey)} {item.enterprise && <span className="text-xs font-extrabold">({t("shared.pro")})</span>}
|
||||
</div>
|
||||
<div className="text-muted-foreground block text-xs">{t(item.descriptionKey)}</div>
|
||||
{item.underConstruction && <div className="text-muted-foreground text-xs">{t("shared.underConstruction")}</div>}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
import { ActionFunction, useActionData } from "react-router";
|
||||
import { Form, Link } from "react-router";
|
||||
import { useState } from "react";
|
||||
import PreviewEntitiesTemplate from "~/components/entities/templates/PreviewEntitiesTemplate";
|
||||
import ButtonPrimary from "~/components/ui/buttons/ButtonPrimary";
|
||||
import ServerError from "~/components/ui/errors/ServerError";
|
||||
import InputText from "~/components/ui/input/InputText";
|
||||
import EditPageLayout from "~/components/ui/layouts/EditPageLayout";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import * as DefaultEntityTemplates from "~/modules/templates/defaultEntityTemplates";
|
||||
import { EntitiesTemplateDto } from "~/modules/templates/EntityTemplateDto";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import { importEntitiesFromTemplate, validateEntitiesFromTemplate } from "~/utils/services/.server/entitiesTemplatesService";
|
||||
import { getUserInfo, validateCSRFToken } from "~/utils/session.server";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export const loader = async () => {
|
||||
return Response.json({});
|
||||
};
|
||||
|
||||
type ActionData = {
|
||||
previewTemplate?: EntitiesTemplateDto;
|
||||
success?: string;
|
||||
error?: string;
|
||||
};
|
||||
const success = (data: ActionData) => Response.json(data, { status: 200 });
|
||||
const badRequest = (data: ActionData) => Response.json(data, { status: 400 });
|
||||
export const action: ActionFunction = async ({ request }) => {
|
||||
await verifyUserHasPermission(request, "admin.entities.create");
|
||||
const { t } = await getTranslations(request);
|
||||
const userInfo = await getUserInfo(request);
|
||||
await validateCSRFToken(request);
|
||||
const form = await request.formData();
|
||||
const action = form.get("action");
|
||||
if (action === "preview") {
|
||||
try {
|
||||
const previewTemplate = JSON.parse(form.get("configuration")?.toString() ?? "{}") as EntitiesTemplateDto;
|
||||
await validateEntitiesFromTemplate(previewTemplate);
|
||||
const data: ActionData = {
|
||||
previewTemplate,
|
||||
};
|
||||
return success(data);
|
||||
} catch (error: any) {
|
||||
return badRequest({ error: error.message });
|
||||
}
|
||||
} else if (action === "create") {
|
||||
try {
|
||||
const template = JSON.parse(form.get("configuration")?.toString() ?? "{}") as EntitiesTemplateDto;
|
||||
const entities = await importEntitiesFromTemplate({
|
||||
template,
|
||||
createdByUserId: userInfo.userId,
|
||||
});
|
||||
return success({
|
||||
success: t("models.entityTemplate.actions.createdEntities", { entities: entities.map((e) => t(e.titlePlural)).join(", ") }),
|
||||
});
|
||||
} catch (error: any) {
|
||||
return badRequest({ error: error.message });
|
||||
}
|
||||
} else {
|
||||
return badRequest({ error: t("shared.invalidForm") });
|
||||
}
|
||||
};
|
||||
|
||||
const defaultTemplates: { titleKey: string; template: EntitiesTemplateDto }[] = [
|
||||
{ titleKey: "models.entityTemplate.defaultTemplates.crm", template: DefaultEntityTemplates.CRM_ENTITIES_TEMPLATE },
|
||||
{ titleKey: "models.entityTemplate.defaultTemplates.tenantSettings", template: DefaultEntityTemplates.TENANT_SETTINGS_ENTITIES_TEMPLATE },
|
||||
{ titleKey: "models.entityTemplate.defaultTemplates.employee", template: DefaultEntityTemplates.EMPLOYEES_ENTITIES_TEMPLATE },
|
||||
{ titleKey: "models.entityTemplate.defaultTemplates.contracts", template: DefaultEntityTemplates.CONTRACTS_ENTITIES_TEMPLATE },
|
||||
{ titleKey: "models.entityTemplate.defaultTemplates.allPropertyTypes", template: DefaultEntityTemplates.ALL_PROPERTY_TYPES_ENTITY_TEMPLATE },
|
||||
];
|
||||
|
||||
export default function AdminEntityTemplatesManual() {
|
||||
const { t } = useTranslation();
|
||||
const actionData = useActionData<ActionData>();
|
||||
const [configuration, setConfiguration] = useState<string>("");
|
||||
|
||||
return (
|
||||
<EditPageLayout
|
||||
title={t("models.entityTemplate.uploadJsonConfiguration")}
|
||||
withHome={false}
|
||||
menu={[
|
||||
{
|
||||
title: t("models.entityTemplate.plural"),
|
||||
routePath: adminPath("entities/templates", { mode: "host-aware" }),
|
||||
},
|
||||
{
|
||||
title: t("models.entityTemplate.manual"),
|
||||
routePath: adminPath("entities/templates/manual", { mode: "host-aware" }),
|
||||
},
|
||||
]}
|
||||
>
|
||||
<div className="md:border-border md:border-t md:py-2">
|
||||
{actionData?.error ? (
|
||||
<>
|
||||
<p id="form-error-message" className="py-2 text-sm text-rose-500" role="alert">
|
||||
{actionData.error}
|
||||
</p>
|
||||
</>
|
||||
) : actionData?.success ? (
|
||||
<>
|
||||
<p id="form-success-message" className="text-text-500 py-2 text-sm" role="alert">
|
||||
{actionData.success}
|
||||
</p>
|
||||
<Link to={adminPath("entities", { mode: "host-aware" })} className="text-theme-600 hover:text-theme-500 text-sm font-medium underline">
|
||||
{t("models.entity.actions.goToEntities")}
|
||||
</Link>
|
||||
</>
|
||||
) : actionData?.previewTemplate === undefined ? (
|
||||
<>
|
||||
<Form method="post">
|
||||
<input type="hidden" name="action" value="preview" hidden readOnly />
|
||||
<div className="space-y-3">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{defaultTemplates.map((templateOption) => (
|
||||
<button
|
||||
key={templateOption.titleKey}
|
||||
type="button"
|
||||
onClick={() => setConfiguration(JSON.stringify(templateOption.template, null, "\t"))}
|
||||
className="bg-theme-100 text-theme-700 hover:bg-theme-200 focus:ring-ring inline-flex items-center rounded border border-transparent px-2.5 py-1.5 text-xs font-medium focus:outline-hidden focus:ring-2 focus:ring-offset-2"
|
||||
>
|
||||
{t(templateOption.titleKey)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div>
|
||||
<InputText
|
||||
name="configuration"
|
||||
title={t("models.entityTemplate.configuration")}
|
||||
editor="monaco"
|
||||
editorLanguage="json"
|
||||
value={configuration}
|
||||
setValue={setConfiguration}
|
||||
editorSize="lg"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-end">
|
||||
<ButtonPrimary type="submit">{t("shared.preview")}</ButtonPrimary>
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</>
|
||||
) : (
|
||||
actionData?.previewTemplate !== undefined && (
|
||||
<>
|
||||
<div className="md:border-border md:border-b md:py-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-foreground text-lg font-medium leading-6">{t("models.entityTemplate.previewEntities")}</h3>
|
||||
</div>
|
||||
</div>
|
||||
<Form method="post">
|
||||
<input type="hidden" name="action" value="create" hidden readOnly />
|
||||
<input type="hidden" name="configuration" value={configuration} hidden readOnly />
|
||||
<div className="space-y-2">
|
||||
<PreviewEntitiesTemplate template={actionData.previewTemplate} />
|
||||
<div className="flex justify-end space-x-2">
|
||||
<ButtonPrimary type="submit">
|
||||
{actionData.previewTemplate.entities.length === 1 ? (
|
||||
<span>{t("models.entityTemplate.actions.createEntities", { count: 1 })}</span>
|
||||
) : (
|
||||
<span>{t("models.entityTemplate.actions.createEntities", { count: actionData.previewTemplate.entities.length })}</span>
|
||||
)}
|
||||
</ButtonPrimary>
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</EditPageLayout>
|
||||
);
|
||||
}
|
||||
|
||||
export function ErrorBoundary() {
|
||||
return <ServerError />;
|
||||
}
|
||||
Reference in new issue
Block a user