- {authorizedForImportExport && (
-
-
- ),
- onClick: () => setImportAssetModalOpen(true),
- },
- },
- {
- label: "Export Assets (JSON)",
- action: async () => {
- const { data } = await request(routes.listAssets, {
- query: { ...qParams, json: true, limit: totalCount },
- });
- return data ?? null;
- },
- type: "json",
- filePrefix: `assets_${facility?.name ?? "all"}`,
- options: {
- icon: ,
- disabled: totalCount === 0 || !authorizedForImportExport,
- id: "export-json-option",
- },
- },
- {
- label: "Export Assets (CSV)",
- action: async () => {
- const { data } = await request(routes.listAssets, {
- query: { ...qParams, csv: true, limit: totalCount },
- });
- return data ?? null;
- },
- type: "csv",
- filePrefix: `assets_${facility?.name ?? "all"}`,
- options: {
- icon: ,
- disabled: totalCount === 0 || !authorizedForImportExport,
- id: "export-csv-option",
- },
- },
- ]}
- />
-
- )}
- >
- }
- >
-
-
-
- updateQuery({ [e.name]: e.value })}
- placeholder="Search by name/serial no./QR code ID"
- />
-
-
-
-
-
advancedFilter.setShow(true)}
- />
-
-
setIsScannerActive(true)}
- >
- Scan Asset
- QR
-
-
+
- {
if (qParams.facility) {
navigate(`/facility/${qParams.facility}/assets/new`);
@@ -423,9 +374,103 @@ const AssetsList = () => {
>
{t("create_asset")}
-
+
+
+
+
advancedFilter.setShow(true)}
+ />
+
+
+
+
+ {authorizedForImportExport && (
+
+ ),
+ onClick: () => setImportAssetModalOpen(true),
+ },
+ },
+ {
+ label: "Export Assets (JSON)",
+ action: async () => {
+ const { data } = await request(routes.listAssets, {
+ query: { ...qParams, json: true, limit: totalCount },
+ });
+ return data ?? null;
+ },
+ type: "json",
+ filePrefix: `assets_${facility?.name ?? "all"}`,
+ options: {
+ icon: ,
+ disabled:
+ totalCount === 0 || !authorizedForImportExport,
+ id: "export-json-option",
+ },
+ },
+ {
+ label: "Export Assets (CSV)",
+ action: async () => {
+ const { data } = await request(routes.listAssets, {
+ query: { ...qParams, csv: true, limit: totalCount },
+ });
+ return data ?? null;
+ },
+ type: "csv",
+ filePrefix: `assets_${facility?.name ?? "all"}`,
+ options: {
+ icon: ,
+ disabled:
+ totalCount === 0 || !authorizedForImportExport,
+ id: "export-csv-option",
+ },
+ },
+ ]}
+ />
+ )}
+
+ }
+ >
+
+
+
+ updateQuery({ search: value })}
+ clearSearch={clearSearch}
+ className="w-full"
+ />
{isLoading ? (
diff --git a/src/components/Common/Export.tsx b/src/components/Common/Export.tsx
index 6cd786977ed..2c5f7849057 100644
--- a/src/components/Common/Export.tsx
+++ b/src/components/Common/Export.tsx
@@ -1,15 +1,24 @@
+import { cn } from "@/lib/utils";
+
import CareIcon from "@/CAREUI/icons/CareIcon";
-import ButtonV2 from "@/components/Common/ButtonV2";
-import DropdownMenu, {
- DropdownItem,
- DropdownItemProps,
-} from "@/components/Common/Menu";
+import { DropdownItemProps } from "@/components/Common/Menu";
import useExport from "@/hooks/useExport";
+import { useIsAuthorized } from "@/hooks/useIsAuthorized";
+import { Anyone, AuthorizedForCB } from "@/Utils/AuthorizeFor";
import request from "@/Utils/request/request";
import { Route } from "@/Utils/request/types";
+import { classNames } from "@/Utils/utils";
+
+import { Button } from "../ui/button";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from "../ui/dropdown-menu";
interface ExportItem {
options?: DropdownItemProps;
@@ -22,9 +31,11 @@ interface ExportItem {
}
interface ExportMenuProps {
+ variant?: string;
disabled?: boolean | undefined;
label?: string;
exportItems: ExportItem[];
+ authorizeFor?: AuthorizedForCB | undefined;
}
interface ExportButtonProps {
@@ -42,14 +53,17 @@ export const ExportMenu = ({
label = "Export",
disabled,
exportItems,
+ authorizeFor = Anyone,
}: ExportMenuProps) => {
const { isExporting, exportFile } = useExport();
+ const isAuthorized = useIsAuthorized(authorizeFor);
if (exportItems.length === 1) {
const item = exportItems[0];
return (
-
{
let action = item.action;
@@ -63,44 +77,68 @@ export const ExportMenu = ({
exportFile(action, item.filePrefix, item.type, item.parse);
}
}}
- border
- ghost
className="py-2.5"
>
{isExporting ? "Exporting..." : label}
-
+
);
}
return (
-