@tsc_tech/medusa-plugin-notification-template
Version:
89 lines (88 loc) • 2.79 kB
JavaScript
import { jsx, jsxs } from "react/jsx-runtime";
import { createDataTableColumnHelper, useDataTable, Container, DataTable, Heading, Button } from "@medusajs/ui";
import { Link } from "react-router-dom";
import { useMemo } from "react";
import { useQuery } from "@tanstack/react-query";
import { NotificationTemplateRowActions } from "../notification-template-row-actions.js";
import { sdk } from "../../utils/sdk.js";
const columnHelper = createDataTableColumnHelper();
const columns = [
columnHelper.accessor("event_name", {
header: "Event Name"
}),
columnHelper.accessor("template", {
header: "Template",
maxSize: 200
}),
columnHelper.accessor("created_at", {
header: "Created At"
}),
columnHelper.accessor("updated_at", {
header: "Updated At"
}),
columnHelper.accessor("actions", {
header: "Actions",
cell: ({ row }) => {
return /* @__PURE__ */ jsx("div", { className: "mx-4", children: /* @__PURE__ */ jsx(
NotificationTemplateRowActions,
{
notificationTemplate: row.original
}
) });
}
})
];
function DataTableComponent({}) {
const { data, isLoading } = useQuery({
queryFn: () => sdk.client.fetch(`/admin/notification-template`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}),
queryKey: ["notification-templates"],
refetchOnMount: "always"
});
const notificationTemplatesArray = useMemo(() => {
return (data == null ? void 0 : data.data) || [];
}, [data == null ? void 0 : data.data]);
const table = useDataTable({
data: notificationTemplatesArray,
columns,
rowCount: notificationTemplatesArray == null ? void 0 : notificationTemplatesArray.length,
// sorting: {
// state: sorting,
// onSortingChange: setSorting,
// },
isLoading,
pagination: {
onPaginationChange: () => {
},
state: {
pageIndex: 0,
pageSize: 50
}
}
});
return /* @__PURE__ */ jsx(Container, { className: "p-0", children: /* @__PURE__ */ jsxs(DataTable, { instance: table, children: [
/* @__PURE__ */ jsxs(DataTable.Toolbar, { className: "flex justify-between items-center", children: [
/* @__PURE__ */ jsx(Heading, { children: "Notification Templates" }),
/* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", asChild: true, children: /* @__PURE__ */ jsx(Link, { to: "create", children: "Create" }) })
] }),
/* @__PURE__ */ jsx(
DataTable.Table,
{
emptyState: {
empty: {
heading: "No Data",
description: "No Notification Templates found"
}
}
}
),
/* @__PURE__ */ jsx(DataTable.Pagination, {})
] }) });
}
export {
DataTableComponent
};