1 import { ExclamationCircle, PlusMini } from "@medusajs/icons";
2 import { Button, clx, Text } from "@medusajs/ui";
3 import { Link } from "react-router-dom";
4
5 type ActionProps = {
6 action?: {
7 to: string;
8 label: string;
9 };
10 };
11
12 type NoRecordsProps = {
13 title?: string;
14 message?: string;
15 className?: string;
16 buttonVariant?: string;
17 icon?: React.ReactNode;
18 } & ActionProps;
19
20 const DefaultButton = ({ action }: ActionProps) =>
21 action && (
22 <Link to={action.to}>
23 <Button variant="secondary" size="small">
24 {action.label}
25 </Button>
26 </Link>
27 );
28
29 const TransparentIconLeftButton = ({ action }: ActionProps) =>
30 action && (
31 <Link to={action.to}>
32 <Button variant="transparent" className="text-ui-fg-interactive">
33 <PlusMini /> {action.label}
34 </Button>
35 </Link>
36 );
37
38 export const NoRecords = ({
39 title,
40 message,
41 action,
42 className,
43 buttonVariant = "default",
44 icon = <ExclamationCircle className="text-ui-fg-subtle" />,
45 }: NoRecordsProps) => {
46 return (
47 <div
48 className={clx(
49 "flex h-[100px] w-full flex-col items-center justify-center gap-y-4",
50 className
51 )}
52 >
53 <div className="flex flex-col items-center gap-y-3">
54 {icon}
55
56 <div className="flex flex-col items-center gap-y-1">
57 <Text size="small" leading="compact" weight="plus">
58 {title ?? "No records"}
59 </Text>
60
61 <Text size="small" className="text-ui-fg-muted text-center">
62 {message ?? "There are no records to show"}
63 </Text>
64 </div>
65 </div>
66
67 {buttonVariant === "default" && <DefaultButton action={action} />}
68 {buttonVariant === "transparentIconLeft" && (
69 <TransparentIconLeftButton action={action} />
70 )}
71 </div>
72 );
73 };