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,92 @@
|
||||
import { LoaderFunctionArgs, useLoaderData } from "react-router";
|
||||
import { FilterablePropertyDto } from "~/application/dtos/data/FilterablePropertyDto";
|
||||
import { PaginationDto } from "~/application/dtos/data/PaginationDto";
|
||||
import { ApplicationEvents, getApplicationEventNameKey } from "~/modules/events/types/ApplicationEvent";
|
||||
import EventsTable from "~/modules/events/components/EventsTable";
|
||||
import InputFilters from "~/components/ui/input/InputFilters";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { EventWithAttempts, getEvents } from "~/modules/events/db/events.db.server";
|
||||
import { adminGetAllTenantsIdsAndNames } from "~/utils/db/tenants.db.server";
|
||||
import { verifyUserHasPermission } from "~/utils/helpers/.server/PermissionsService";
|
||||
import { getFiltersFromCurrentUrl, getPaginationFromCurrentUrl } from "~/utils/helpers/RowPaginationHelper";
|
||||
import { adminGetAllUsersNames } from "~/utils/db/users.db.server";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import EditPageLayout from "~/components/ui/layouts/EditPageLayout";
|
||||
|
||||
type LoaderData = {
|
||||
title: string;
|
||||
items: EventWithAttempts[];
|
||||
pagination: PaginationDto;
|
||||
filterableProperties: FilterablePropertyDto[];
|
||||
};
|
||||
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
await verifyUserHasPermission(request, "admin.events.view");
|
||||
const { t } = await getTranslations(request);
|
||||
|
||||
const urlSearchParams = new URL(request.url).searchParams;
|
||||
const current = getPaginationFromCurrentUrl(urlSearchParams);
|
||||
const filterableProperties: FilterablePropertyDto[] = [
|
||||
{
|
||||
name: "name",
|
||||
title: "admin.events.filters.event",
|
||||
options: ApplicationEvents.map((item) => {
|
||||
return {
|
||||
value: item.value,
|
||||
name: t("admin.events.filters.eventOption", { eventValue: item.value, eventLabel: t(getApplicationEventNameKey(item.value)) }),
|
||||
};
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "data",
|
||||
title: "admin.events.filters.data",
|
||||
},
|
||||
{
|
||||
name: "tenantId",
|
||||
title: t("models.tenant.object"),
|
||||
options: [
|
||||
{ name: t("admin.events.filters.noTenant"), value: "{null}" },
|
||||
...(await adminGetAllTenantsIdsAndNames()).map((i) => {
|
||||
return { value: i.id, name: i.name };
|
||||
}),
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "userId",
|
||||
title: t("models.user.object"),
|
||||
options: (await adminGetAllUsersNames()).map((item) => {
|
||||
return {
|
||||
value: item.id,
|
||||
name: item.email,
|
||||
};
|
||||
}),
|
||||
},
|
||||
];
|
||||
const filters = getFiltersFromCurrentUrl(request, filterableProperties);
|
||||
const { items, pagination } = await getEvents({ current, filters });
|
||||
|
||||
const data: LoaderData = {
|
||||
title: `${t("models.event.plural")} | ${process.env.APP_NAME}`,
|
||||
items,
|
||||
pagination,
|
||||
filterableProperties,
|
||||
};
|
||||
return data;
|
||||
};
|
||||
|
||||
export default function AdminEventsRoute() {
|
||||
const { t } = useTranslation();
|
||||
const data = useLoaderData<LoaderData>();
|
||||
|
||||
return (
|
||||
<EditPageLayout
|
||||
title={t("models.event.plural")}
|
||||
buttons={
|
||||
<>
|
||||
<InputFilters size="sm" filters={data.filterableProperties} />
|
||||
</>
|
||||
}
|
||||
>
|
||||
<EventsTable items={data.items} pagination={data.pagination} />
|
||||
</EditPageLayout>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user