- Added Zod schemas for dashboard queries, entries, summaries, and companies. - Created dashboard API functions for fetching summary, work, attention, activity, and companies data. - Developed dashboard components including BlockState, DashboardDetailsDialog, and DashboardPage for rendering dashboard information. - Implemented quick create functionality for companies, tickets, interventions, assets, and resources. - Introduced a new ResourceDashboardReader for querying resource-related data. - Added a StatisticCard component for displaying key performance indicators in the dashboard.
82 lines
2.3 KiB
TypeScript
82 lines
2.3 KiB
TypeScript
import { AssetInventoryPage, WorkstationsPage } from "@metis/assets/client";
|
|
import { FormDialog } from "@repo/shadcn-ui/components/form-dialog";
|
|
import { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import type { CompanyDTO } from "../../common";
|
|
|
|
import { PersonForm } from "./person-form";
|
|
import { SiteForm } from "./site-form";
|
|
export function CompanyInventory({
|
|
company,
|
|
csrfToken,
|
|
workstations = false,
|
|
initialId,
|
|
initialCreate,
|
|
}: {
|
|
company: CompanyDTO;
|
|
csrfToken: string;
|
|
workstations?: boolean;
|
|
initialId?: string | undefined;
|
|
initialCreate?: boolean | undefined;
|
|
}) {
|
|
const { t } = useTranslation("companies");
|
|
const { t: assetTranslation } = useTranslation("assets");
|
|
const [quick, setQuick] = useState<{
|
|
kind: "site" | "person";
|
|
onCreated: (id: string) => void;
|
|
}>();
|
|
const Page = workstations ? WorkstationsPage : AssetInventoryPage;
|
|
return (
|
|
<>
|
|
<Page
|
|
{...(workstations ? {} : { initialId, initialCreate })}
|
|
companyId={company.id}
|
|
csrfToken={csrfToken}
|
|
lookups={{
|
|
sites: company.sites,
|
|
people: company.people,
|
|
onCreateSite: (onCreated) => setQuick({ kind: "site", onCreated }),
|
|
onCreatePerson: (onCreated) => setQuick({ kind: "person", onCreated }),
|
|
}}
|
|
/>
|
|
{quick && (
|
|
<FormDialog
|
|
cancelLabel={t("cancel")}
|
|
formActions
|
|
onOpenChange={(open) => {
|
|
if (!open) {
|
|
setQuick(undefined);
|
|
}
|
|
}}
|
|
open
|
|
title={t(quick.kind === "site" ? "newSite" : "newPerson")}
|
|
>
|
|
<p className="text-sm text-muted-foreground">{assetTranslation("relatedNotice")}</p>
|
|
{quick.kind === "site" ? (
|
|
<SiteForm
|
|
companyId={company.id}
|
|
csrfToken={csrfToken}
|
|
onSaved={(id) => {
|
|
quick.onCreated(id);
|
|
setQuick(undefined);
|
|
}}
|
|
showTitle={false}
|
|
/>
|
|
) : (
|
|
<PersonForm
|
|
companyId={company.id}
|
|
csrfToken={csrfToken}
|
|
onSaved={(id) => {
|
|
quick.onCreated(id);
|
|
setQuick(undefined);
|
|
}}
|
|
requireActive
|
|
/>
|
|
)}
|
|
</FormDialog>
|
|
)}
|
|
</>
|
|
);
|
|
}
|