diff --git a/src/components/Common/Export.tsx b/src/components/Common/Export.tsx index 2a0b0593051..bd5a4a69ccf 100644 --- a/src/components/Common/Export.tsx +++ b/src/components/Common/Export.tsx @@ -1,20 +1,23 @@ import CareIcon from "@/CAREUI/icons/CareIcon"; import { Button } from "@/components/ui/button"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; -import ButtonV2 from "@/components/Common/ButtonV2"; -import DropdownMenu, { - DropdownItem, - DropdownItemProps, -} from "@/components/Common/Menu"; +import { ShadcnMenuDropdownItemProps } from "@/components/Common/Menu"; import useExport from "@/hooks/useExport"; +import { useIsAuthorized } from "@/hooks/useIsAuthorized"; import request from "@/Utils/request/request"; import { Route } from "@/Utils/request/types"; interface ExportItem { - options?: DropdownItemProps; + options?: ShadcnMenuDropdownItemProps; type?: "csv" | "json"; filePrefix?: string; label: string; @@ -69,7 +72,7 @@ export const ExportMenu = ({ variant="outline_primary" className="py-2.5" > - + {isExporting ? "Exporting..." : label} ); @@ -77,32 +80,49 @@ export const ExportMenu = ({ return (
- } - className="border border-primary-700 text-primary-700 bg-white shadow-sm hover:bg-primary-700 hover:text-white h-9 px-4 py-2dark:border-primary-700 dark:bg-primary-700 dark:text-white" - > - {exportItems.map((item) => ( - { - let action = item.action; - if (item.route) { - action = async () => { - const { data } = await request(item.route!); - return data ?? null; - }; - } - if (action) { - exportFile(action, item.filePrefix, item.type, item.parse); - } - }} - {...item.options} + + + + + + {exportItems.map((item) => ( + { + let action = item.action; + if (item.route) { + action = async () => { + const { data } = await request(item.route!); + return data ?? null; + }; + } + if (action) { + exportFile(action, item.filePrefix, item.type, item.parse); + } + }} + disabled={ + item.options?.disabled || + (item.options?.authorizeFor && + !useIsAuthorized(item.options.authorizeFor)) + } + id={item.options?.id} + className={item.options?.className} + > +
+ {item.options?.icon} + {item.label} +
+
+ ))} +
); @@ -118,7 +138,7 @@ export const ExportButton = ({ return ( <> - { let action = props.action; @@ -132,10 +152,8 @@ export const ExportButton = ({ exportFile(action, props.filenamePrefix, type, parse); } }} - className="tooltip mx-2 p-4 text-lg text-secondary-800 bg-red disabled:bg-transparent disabled:text-secondary-500" - variant="secondary" - ghost - circle + variant="outline_primary" + size="default" > {isExporting ? ( @@ -145,7 +163,7 @@ export const ExportButton = ({ {props.tooltip || "Export"} - + ); }; diff --git a/src/components/Common/Menu.tsx b/src/components/Common/Menu.tsx index aa647a3dedb..7777b8b41ae 100644 --- a/src/components/Common/Menu.tsx +++ b/src/components/Common/Menu.tsx @@ -76,6 +76,15 @@ export type DropdownItemProps = RawDivProps & disabled?: boolean | undefined; }; +export type ShadcnMenuDropdownItemProps = RawDivProps & + AuthorizedElementProps & { + onClick?: () => void; + disabled?: boolean; + icon?: ReactNode | undefined; + className?: string; + children?: ReactNode; + }; + export function DropdownItem({ authorizeFor = Anyone, variant = "primary",