@mantajs/core 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.medusa/server/src/admin/index.js +139 -17
- package/.medusa/server/src/admin/index.mjs +143 -21
- package/.medusa/server/src/api/admin/employees/middlewares.js +15 -0
- package/.medusa/server/src/api/admin/employees/route.js +21 -0
- package/.medusa/server/src/api/middlewares.js +3 -2
- package/package.json +1 -1
|
@@ -9,16 +9,6 @@ const Medusa = require("@medusajs/js-sdk");
|
|
|
9
9
|
const _interopDefault = (e2) => e2 && e2.__esModule ? e2 : { default: e2 };
|
|
10
10
|
const React__default = /* @__PURE__ */ _interopDefault(React);
|
|
11
11
|
const Medusa__default = /* @__PURE__ */ _interopDefault(Medusa);
|
|
12
|
-
const EmployeesPage = () => {
|
|
13
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "divide-y p-0", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-6 py-4", children: [
|
|
14
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Employees" }),
|
|
15
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: "Manage employees and their company assignments." })
|
|
16
|
-
] }) });
|
|
17
|
-
};
|
|
18
|
-
adminSdk.defineRouteConfig({
|
|
19
|
-
label: "Employees",
|
|
20
|
-
nested: "/companies"
|
|
21
|
-
});
|
|
22
12
|
var isCheckBoxInput = (element) => element.type === "checkbox";
|
|
23
13
|
var isDateObject = (value) => value instanceof Date;
|
|
24
14
|
var isNullOrUndefined = (value) => value == null;
|
|
@@ -5326,29 +5316,161 @@ const CompaniesPage = () => {
|
|
|
5326
5316
|
] }) })
|
|
5327
5317
|
] });
|
|
5328
5318
|
};
|
|
5329
|
-
const config = adminSdk.defineRouteConfig({
|
|
5319
|
+
const config$1 = adminSdk.defineRouteConfig({
|
|
5330
5320
|
label: "Companies",
|
|
5331
|
-
icon: icons.BuildingStorefront
|
|
5321
|
+
icon: icons.BuildingStorefront,
|
|
5322
|
+
rank: 4
|
|
5323
|
+
});
|
|
5324
|
+
const EmployeesPage = () => {
|
|
5325
|
+
const [searchQuery, setSearchQuery] = React.useState("");
|
|
5326
|
+
const [companyFilter, setCompanyFilter] = React.useState("all");
|
|
5327
|
+
const [roleFilter, setRoleFilter] = React.useState("all");
|
|
5328
|
+
const { data, isLoading, isError, error } = reactQuery.useQuery({
|
|
5329
|
+
queryFn: () => sdk.client.fetch(`/admin/employees`, {
|
|
5330
|
+
query: {
|
|
5331
|
+
limit: 100,
|
|
5332
|
+
offset: 0
|
|
5333
|
+
}
|
|
5334
|
+
}),
|
|
5335
|
+
queryKey: ["employees", "list"]
|
|
5336
|
+
});
|
|
5337
|
+
const employees = (data == null ? void 0 : data.employees) || [];
|
|
5338
|
+
const companies = React.useMemo(() => {
|
|
5339
|
+
const uniqueCompanies = /* @__PURE__ */ new Map();
|
|
5340
|
+
employees.forEach((emp) => {
|
|
5341
|
+
if (emp.company) {
|
|
5342
|
+
uniqueCompanies.set(emp.company.id, emp.company);
|
|
5343
|
+
}
|
|
5344
|
+
});
|
|
5345
|
+
return Array.from(uniqueCompanies.values()).sort(
|
|
5346
|
+
(a2, b) => a2.name.localeCompare(b.name)
|
|
5347
|
+
);
|
|
5348
|
+
}, [employees]);
|
|
5349
|
+
const filteredEmployees = React.useMemo(() => {
|
|
5350
|
+
return employees.filter((employee) => {
|
|
5351
|
+
var _a, _b, _c;
|
|
5352
|
+
if (searchQuery) {
|
|
5353
|
+
const query = searchQuery.toLowerCase();
|
|
5354
|
+
const companyName = ((_b = (_a = employee.company) == null ? void 0 : _a.name) == null ? void 0 : _b.toLowerCase()) || "";
|
|
5355
|
+
if (!companyName.includes(query)) {
|
|
5356
|
+
return false;
|
|
5357
|
+
}
|
|
5358
|
+
}
|
|
5359
|
+
if (companyFilter !== "all" && ((_c = employee.company) == null ? void 0 : _c.id) !== companyFilter) {
|
|
5360
|
+
return false;
|
|
5361
|
+
}
|
|
5362
|
+
if (roleFilter === "admin" && !employee.is_admin) {
|
|
5363
|
+
return false;
|
|
5364
|
+
}
|
|
5365
|
+
if (roleFilter === "buyer" && employee.is_admin) {
|
|
5366
|
+
return false;
|
|
5367
|
+
}
|
|
5368
|
+
return true;
|
|
5369
|
+
});
|
|
5370
|
+
}, [employees, searchQuery, companyFilter, roleFilter]);
|
|
5371
|
+
const formatCurrency = (amount) => {
|
|
5372
|
+
if (amount === 0) return "Unlimited";
|
|
5373
|
+
return new Intl.NumberFormat("fr-FR", {
|
|
5374
|
+
style: "currency",
|
|
5375
|
+
currency: "EUR"
|
|
5376
|
+
}).format(amount / 100);
|
|
5377
|
+
};
|
|
5378
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
5379
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
5380
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Employees" }),
|
|
5381
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: "Manage B2B company employees and their permissions." })
|
|
5382
|
+
] }) }),
|
|
5383
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-4 px-6 py-4", children: [
|
|
5384
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex-1 max-w-sm", children: [
|
|
5385
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.MagnifyingGlass, { className: "absolute left-3 top-1/2 -translate-y-1/2 text-ui-fg-muted" }),
|
|
5386
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5387
|
+
ui.Input,
|
|
5388
|
+
{
|
|
5389
|
+
placeholder: "Search by company name...",
|
|
5390
|
+
value: searchQuery,
|
|
5391
|
+
onChange: (e2) => setSearchQuery(e2.target.value),
|
|
5392
|
+
className: "pl-10"
|
|
5393
|
+
}
|
|
5394
|
+
)
|
|
5395
|
+
] }),
|
|
5396
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { value: companyFilter, onValueChange: setCompanyFilter, children: [
|
|
5397
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { className: "w-[200px]", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "All companies" }) }),
|
|
5398
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Content, { children: [
|
|
5399
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "all", children: "All companies" }),
|
|
5400
|
+
companies.map((company) => /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: company.id, children: company.name }, company.id))
|
|
5401
|
+
] })
|
|
5402
|
+
] }),
|
|
5403
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { value: roleFilter, onValueChange: setRoleFilter, children: [
|
|
5404
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { className: "w-[150px]", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "All roles" }) }),
|
|
5405
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Content, { children: [
|
|
5406
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "all", children: "All roles" }),
|
|
5407
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "admin", children: "Admin" }),
|
|
5408
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "buyer", children: "Buyer" })
|
|
5409
|
+
] })
|
|
5410
|
+
] }),
|
|
5411
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "text-ui-fg-muted text-sm", children: [
|
|
5412
|
+
filteredEmployees.length,
|
|
5413
|
+
" employee",
|
|
5414
|
+
filteredEmployees.length !== 1 ? "s" : ""
|
|
5415
|
+
] })
|
|
5416
|
+
] }),
|
|
5417
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center py-8", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Spinner, { className: "animate-spin" }) }) : isError ? /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "text-ui-fg-error py-8 text-center", children: [
|
|
5418
|
+
"Error: ",
|
|
5419
|
+
error instanceof Error ? error.message : "Unknown error"
|
|
5420
|
+
] }) : filteredEmployees.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle py-8 text-center", children: employees.length === 0 ? "No employees yet." : "No employees match your filters." }) : /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { children: [
|
|
5421
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { children: [
|
|
5422
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "ID" }),
|
|
5423
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Company" }),
|
|
5424
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Location" }),
|
|
5425
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Role" }),
|
|
5426
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Spending Limit" }),
|
|
5427
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Created" })
|
|
5428
|
+
] }) }),
|
|
5429
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Body, { children: filteredEmployees.map((employee) => {
|
|
5430
|
+
var _a, _b, _c, _d, _e;
|
|
5431
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { children: [
|
|
5432
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { className: "font-mono text-sm", children: employee.id.slice(-8) }),
|
|
5433
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { className: "font-medium", children: ((_a = employee.company) == null ? void 0 : _a.name) || "-" }),
|
|
5434
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: ((_b = employee.company) == null ? void 0 : _b.city) && ((_c = employee.company) == null ? void 0 : _c.country) ? `${employee.company.city}, ${employee.company.country}` : ((_d = employee.company) == null ? void 0 : _d.city) || ((_e = employee.company) == null ? void 0 : _e.country) || "-" }),
|
|
5435
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: employee.is_admin ? "purple" : "grey", children: employee.is_admin ? "Admin" : "Buyer" }) }),
|
|
5436
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: formatCurrency(employee.spending_limit) }),
|
|
5437
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: new Date(employee.created_at).toLocaleDateString() })
|
|
5438
|
+
] }, employee.id);
|
|
5439
|
+
}) })
|
|
5440
|
+
] }) })
|
|
5441
|
+
] });
|
|
5442
|
+
};
|
|
5443
|
+
const config = adminSdk.defineRouteConfig({
|
|
5444
|
+
label: "Employees",
|
|
5445
|
+
icon: icons.Users
|
|
5332
5446
|
});
|
|
5333
5447
|
const widgetModule = { widgets: [] };
|
|
5334
5448
|
const routeModule = {
|
|
5335
5449
|
routes: [
|
|
5336
|
-
{
|
|
5337
|
-
Component: EmployeesPage,
|
|
5338
|
-
path: "/employees"
|
|
5339
|
-
},
|
|
5340
5450
|
{
|
|
5341
5451
|
Component: CompaniesPage,
|
|
5342
5452
|
path: "/companies"
|
|
5453
|
+
},
|
|
5454
|
+
{
|
|
5455
|
+
Component: EmployeesPage,
|
|
5456
|
+
path: "/employees"
|
|
5343
5457
|
}
|
|
5344
5458
|
]
|
|
5345
5459
|
};
|
|
5346
5460
|
const menuItemModule = {
|
|
5347
5461
|
menuItems: [
|
|
5462
|
+
{
|
|
5463
|
+
label: config$1.label,
|
|
5464
|
+
icon: config$1.icon,
|
|
5465
|
+
path: "/companies",
|
|
5466
|
+
nested: void 0,
|
|
5467
|
+
rank: 4,
|
|
5468
|
+
translationNs: void 0
|
|
5469
|
+
},
|
|
5348
5470
|
{
|
|
5349
5471
|
label: config.label,
|
|
5350
5472
|
icon: config.icon,
|
|
5351
|
-
path: "/
|
|
5473
|
+
path: "/employees",
|
|
5352
5474
|
nested: void 0,
|
|
5353
5475
|
rank: void 0,
|
|
5354
5476
|
translationNs: void 0
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { defineRouteConfig } from "@medusajs/admin-sdk";
|
|
3
|
-
import { Container, Heading, Text,
|
|
4
|
-
import { BuildingStorefront, Plus, Spinner } from "@medusajs/icons";
|
|
3
|
+
import { toast, Container, Heading, Text, Button, Table, FocusModal, Label, Input, Select, Badge } from "@medusajs/ui";
|
|
4
|
+
import { BuildingStorefront, Plus, Spinner, Users, MagnifyingGlass } from "@medusajs/icons";
|
|
5
5
|
import { useQueryClient, useQuery, useMutation } from "@tanstack/react-query";
|
|
6
|
-
import React, { useState } from "react";
|
|
6
|
+
import React, { useState, useMemo } from "react";
|
|
7
7
|
import Medusa from "@medusajs/js-sdk";
|
|
8
|
-
const EmployeesPage = () => {
|
|
9
|
-
return /* @__PURE__ */ jsx(Container, { className: "divide-y p-0", children: /* @__PURE__ */ jsxs("div", { className: "px-6 py-4", children: [
|
|
10
|
-
/* @__PURE__ */ jsx(Heading, { level: "h1", children: "Employees" }),
|
|
11
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Manage employees and their company assignments." })
|
|
12
|
-
] }) });
|
|
13
|
-
};
|
|
14
|
-
defineRouteConfig({
|
|
15
|
-
label: "Employees",
|
|
16
|
-
nested: "/companies"
|
|
17
|
-
});
|
|
18
8
|
var isCheckBoxInput = (element) => element.type === "checkbox";
|
|
19
9
|
var isDateObject = (value) => value instanceof Date;
|
|
20
10
|
var isNullOrUndefined = (value) => value == null;
|
|
@@ -5322,29 +5312,161 @@ const CompaniesPage = () => {
|
|
|
5322
5312
|
] }) })
|
|
5323
5313
|
] });
|
|
5324
5314
|
};
|
|
5325
|
-
const config = defineRouteConfig({
|
|
5315
|
+
const config$1 = defineRouteConfig({
|
|
5326
5316
|
label: "Companies",
|
|
5327
|
-
icon: BuildingStorefront
|
|
5317
|
+
icon: BuildingStorefront,
|
|
5318
|
+
rank: 4
|
|
5319
|
+
});
|
|
5320
|
+
const EmployeesPage = () => {
|
|
5321
|
+
const [searchQuery, setSearchQuery] = useState("");
|
|
5322
|
+
const [companyFilter, setCompanyFilter] = useState("all");
|
|
5323
|
+
const [roleFilter, setRoleFilter] = useState("all");
|
|
5324
|
+
const { data, isLoading, isError, error } = useQuery({
|
|
5325
|
+
queryFn: () => sdk.client.fetch(`/admin/employees`, {
|
|
5326
|
+
query: {
|
|
5327
|
+
limit: 100,
|
|
5328
|
+
offset: 0
|
|
5329
|
+
}
|
|
5330
|
+
}),
|
|
5331
|
+
queryKey: ["employees", "list"]
|
|
5332
|
+
});
|
|
5333
|
+
const employees = (data == null ? void 0 : data.employees) || [];
|
|
5334
|
+
const companies = useMemo(() => {
|
|
5335
|
+
const uniqueCompanies = /* @__PURE__ */ new Map();
|
|
5336
|
+
employees.forEach((emp) => {
|
|
5337
|
+
if (emp.company) {
|
|
5338
|
+
uniqueCompanies.set(emp.company.id, emp.company);
|
|
5339
|
+
}
|
|
5340
|
+
});
|
|
5341
|
+
return Array.from(uniqueCompanies.values()).sort(
|
|
5342
|
+
(a2, b) => a2.name.localeCompare(b.name)
|
|
5343
|
+
);
|
|
5344
|
+
}, [employees]);
|
|
5345
|
+
const filteredEmployees = useMemo(() => {
|
|
5346
|
+
return employees.filter((employee) => {
|
|
5347
|
+
var _a, _b, _c;
|
|
5348
|
+
if (searchQuery) {
|
|
5349
|
+
const query = searchQuery.toLowerCase();
|
|
5350
|
+
const companyName = ((_b = (_a = employee.company) == null ? void 0 : _a.name) == null ? void 0 : _b.toLowerCase()) || "";
|
|
5351
|
+
if (!companyName.includes(query)) {
|
|
5352
|
+
return false;
|
|
5353
|
+
}
|
|
5354
|
+
}
|
|
5355
|
+
if (companyFilter !== "all" && ((_c = employee.company) == null ? void 0 : _c.id) !== companyFilter) {
|
|
5356
|
+
return false;
|
|
5357
|
+
}
|
|
5358
|
+
if (roleFilter === "admin" && !employee.is_admin) {
|
|
5359
|
+
return false;
|
|
5360
|
+
}
|
|
5361
|
+
if (roleFilter === "buyer" && employee.is_admin) {
|
|
5362
|
+
return false;
|
|
5363
|
+
}
|
|
5364
|
+
return true;
|
|
5365
|
+
});
|
|
5366
|
+
}, [employees, searchQuery, companyFilter, roleFilter]);
|
|
5367
|
+
const formatCurrency = (amount) => {
|
|
5368
|
+
if (amount === 0) return "Unlimited";
|
|
5369
|
+
return new Intl.NumberFormat("fr-FR", {
|
|
5370
|
+
style: "currency",
|
|
5371
|
+
currency: "EUR"
|
|
5372
|
+
}).format(amount / 100);
|
|
5373
|
+
};
|
|
5374
|
+
return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
|
|
5375
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsxs("div", { children: [
|
|
5376
|
+
/* @__PURE__ */ jsx(Heading, { level: "h1", children: "Employees" }),
|
|
5377
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Manage B2B company employees and their permissions." })
|
|
5378
|
+
] }) }),
|
|
5379
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4 px-6 py-4", children: [
|
|
5380
|
+
/* @__PURE__ */ jsxs("div", { className: "relative flex-1 max-w-sm", children: [
|
|
5381
|
+
/* @__PURE__ */ jsx(MagnifyingGlass, { className: "absolute left-3 top-1/2 -translate-y-1/2 text-ui-fg-muted" }),
|
|
5382
|
+
/* @__PURE__ */ jsx(
|
|
5383
|
+
Input,
|
|
5384
|
+
{
|
|
5385
|
+
placeholder: "Search by company name...",
|
|
5386
|
+
value: searchQuery,
|
|
5387
|
+
onChange: (e2) => setSearchQuery(e2.target.value),
|
|
5388
|
+
className: "pl-10"
|
|
5389
|
+
}
|
|
5390
|
+
)
|
|
5391
|
+
] }),
|
|
5392
|
+
/* @__PURE__ */ jsxs(Select, { value: companyFilter, onValueChange: setCompanyFilter, children: [
|
|
5393
|
+
/* @__PURE__ */ jsx(Select.Trigger, { className: "w-[200px]", children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "All companies" }) }),
|
|
5394
|
+
/* @__PURE__ */ jsxs(Select.Content, { children: [
|
|
5395
|
+
/* @__PURE__ */ jsx(Select.Item, { value: "all", children: "All companies" }),
|
|
5396
|
+
companies.map((company) => /* @__PURE__ */ jsx(Select.Item, { value: company.id, children: company.name }, company.id))
|
|
5397
|
+
] })
|
|
5398
|
+
] }),
|
|
5399
|
+
/* @__PURE__ */ jsxs(Select, { value: roleFilter, onValueChange: setRoleFilter, children: [
|
|
5400
|
+
/* @__PURE__ */ jsx(Select.Trigger, { className: "w-[150px]", children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "All roles" }) }),
|
|
5401
|
+
/* @__PURE__ */ jsxs(Select.Content, { children: [
|
|
5402
|
+
/* @__PURE__ */ jsx(Select.Item, { value: "all", children: "All roles" }),
|
|
5403
|
+
/* @__PURE__ */ jsx(Select.Item, { value: "admin", children: "Admin" }),
|
|
5404
|
+
/* @__PURE__ */ jsx(Select.Item, { value: "buyer", children: "Buyer" })
|
|
5405
|
+
] })
|
|
5406
|
+
] }),
|
|
5407
|
+
/* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-muted text-sm", children: [
|
|
5408
|
+
filteredEmployees.length,
|
|
5409
|
+
" employee",
|
|
5410
|
+
filteredEmployees.length !== 1 ? "s" : ""
|
|
5411
|
+
] })
|
|
5412
|
+
] }),
|
|
5413
|
+
/* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: isLoading ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-8", children: /* @__PURE__ */ jsx(Spinner, { className: "animate-spin" }) }) : isError ? /* @__PURE__ */ jsxs(Text, { className: "text-ui-fg-error py-8 text-center", children: [
|
|
5414
|
+
"Error: ",
|
|
5415
|
+
error instanceof Error ? error.message : "Unknown error"
|
|
5416
|
+
] }) : filteredEmployees.length === 0 ? /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle py-8 text-center", children: employees.length === 0 ? "No employees yet." : "No employees match your filters." }) : /* @__PURE__ */ jsxs(Table, { children: [
|
|
5417
|
+
/* @__PURE__ */ jsx(Table.Header, { children: /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
5418
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "ID" }),
|
|
5419
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Company" }),
|
|
5420
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Location" }),
|
|
5421
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Role" }),
|
|
5422
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Spending Limit" }),
|
|
5423
|
+
/* @__PURE__ */ jsx(Table.HeaderCell, { children: "Created" })
|
|
5424
|
+
] }) }),
|
|
5425
|
+
/* @__PURE__ */ jsx(Table.Body, { children: filteredEmployees.map((employee) => {
|
|
5426
|
+
var _a, _b, _c, _d, _e;
|
|
5427
|
+
return /* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
5428
|
+
/* @__PURE__ */ jsx(Table.Cell, { className: "font-mono text-sm", children: employee.id.slice(-8) }),
|
|
5429
|
+
/* @__PURE__ */ jsx(Table.Cell, { className: "font-medium", children: ((_a = employee.company) == null ? void 0 : _a.name) || "-" }),
|
|
5430
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: ((_b = employee.company) == null ? void 0 : _b.city) && ((_c = employee.company) == null ? void 0 : _c.country) ? `${employee.company.city}, ${employee.company.country}` : ((_d = employee.company) == null ? void 0 : _d.city) || ((_e = employee.company) == null ? void 0 : _e.country) || "-" }),
|
|
5431
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Badge, { color: employee.is_admin ? "purple" : "grey", children: employee.is_admin ? "Admin" : "Buyer" }) }),
|
|
5432
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: formatCurrency(employee.spending_limit) }),
|
|
5433
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: new Date(employee.created_at).toLocaleDateString() })
|
|
5434
|
+
] }, employee.id);
|
|
5435
|
+
}) })
|
|
5436
|
+
] }) })
|
|
5437
|
+
] });
|
|
5438
|
+
};
|
|
5439
|
+
const config = defineRouteConfig({
|
|
5440
|
+
label: "Employees",
|
|
5441
|
+
icon: Users
|
|
5328
5442
|
});
|
|
5329
5443
|
const widgetModule = { widgets: [] };
|
|
5330
5444
|
const routeModule = {
|
|
5331
5445
|
routes: [
|
|
5332
|
-
{
|
|
5333
|
-
Component: EmployeesPage,
|
|
5334
|
-
path: "/employees"
|
|
5335
|
-
},
|
|
5336
5446
|
{
|
|
5337
5447
|
Component: CompaniesPage,
|
|
5338
5448
|
path: "/companies"
|
|
5449
|
+
},
|
|
5450
|
+
{
|
|
5451
|
+
Component: EmployeesPage,
|
|
5452
|
+
path: "/employees"
|
|
5339
5453
|
}
|
|
5340
5454
|
]
|
|
5341
5455
|
};
|
|
5342
5456
|
const menuItemModule = {
|
|
5343
5457
|
menuItems: [
|
|
5458
|
+
{
|
|
5459
|
+
label: config$1.label,
|
|
5460
|
+
icon: config$1.icon,
|
|
5461
|
+
path: "/companies",
|
|
5462
|
+
nested: void 0,
|
|
5463
|
+
rank: 4,
|
|
5464
|
+
translationNs: void 0
|
|
5465
|
+
},
|
|
5344
5466
|
{
|
|
5345
5467
|
label: config.label,
|
|
5346
5468
|
icon: config.icon,
|
|
5347
|
-
path: "/
|
|
5469
|
+
path: "/employees",
|
|
5348
5470
|
nested: void 0,
|
|
5349
5471
|
rank: void 0,
|
|
5350
5472
|
translationNs: void 0
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.employeesMiddlewares = void 0;
|
|
4
|
+
const http_1 = require("@medusajs/framework/http");
|
|
5
|
+
exports.employeesMiddlewares = [
|
|
6
|
+
{
|
|
7
|
+
matcher: "/admin/employees",
|
|
8
|
+
middlewares: [(0, http_1.authenticate)("user", ["bearer", "session", "api-key"])],
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
matcher: "/admin/employees/:id",
|
|
12
|
+
middlewares: [(0, http_1.authenticate)("user", ["bearer", "session", "api-key"])],
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWlkZGxld2FyZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvYXBpL2FkbWluL2VtcGxveWVlcy9taWRkbGV3YXJlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxtREFBd0U7QUFFM0QsUUFBQSxvQkFBb0IsR0FBc0I7SUFDckQ7UUFDRSxPQUFPLEVBQUUsa0JBQWtCO1FBQzNCLFdBQVcsRUFBRSxDQUFDLElBQUEsbUJBQVksRUFBQyxNQUFNLEVBQUUsQ0FBQyxRQUFRLEVBQUUsU0FBUyxFQUFFLFNBQVMsQ0FBQyxDQUFDLENBQUM7S0FDdEU7SUFDRDtRQUNFLE9BQU8sRUFBRSxzQkFBc0I7UUFDL0IsV0FBVyxFQUFFLENBQUMsSUFBQSxtQkFBWSxFQUFDLE1BQU0sRUFBRSxDQUFDLFFBQVEsRUFBRSxTQUFTLEVBQUUsU0FBUyxDQUFDLENBQUMsQ0FBQztLQUN0RTtDQUNGLENBQUEifQ==
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GET = GET;
|
|
4
|
+
async function GET(req, res) {
|
|
5
|
+
const query = req.scope.resolve("query");
|
|
6
|
+
const queryConfig = {
|
|
7
|
+
...req.queryConfig,
|
|
8
|
+
fields: req.queryConfig?.fields || ["id", "spending_limit", "is_admin", "created_at", "updated_at", "company.*"],
|
|
9
|
+
};
|
|
10
|
+
const { data: employees, metadata } = await query.graph({
|
|
11
|
+
entity: "employee",
|
|
12
|
+
...queryConfig,
|
|
13
|
+
});
|
|
14
|
+
return res.json({
|
|
15
|
+
employees,
|
|
16
|
+
count: metadata?.count ?? employees.length,
|
|
17
|
+
limit: req.queryConfig?.pagination?.take ?? 50,
|
|
18
|
+
offset: req.queryConfig?.pagination?.skip ?? 0,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvYXBpL2FkbWluL2VtcGxveWVlcy9yb3V0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVBLGtCQW1CQztBQW5CTSxLQUFLLFVBQVUsR0FBRyxDQUFDLEdBQWtCLEVBQUUsR0FBbUI7SUFDL0QsTUFBTSxLQUFLLEdBQUcsR0FBRyxDQUFDLEtBQUssQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUE7SUFFeEMsTUFBTSxXQUFXLEdBQUc7UUFDbEIsR0FBRyxHQUFHLENBQUMsV0FBVztRQUNsQixNQUFNLEVBQUUsR0FBRyxDQUFDLFdBQVcsRUFBRSxNQUFNLElBQUksQ0FBQyxJQUFJLEVBQUUsZ0JBQWdCLEVBQUUsVUFBVSxFQUFFLFlBQVksRUFBRSxZQUFZLEVBQUUsV0FBVyxDQUFDO0tBQ2pILENBQUE7SUFFRCxNQUFNLEVBQUUsSUFBSSxFQUFFLFNBQVMsRUFBRSxRQUFRLEVBQUUsR0FBRyxNQUFNLEtBQUssQ0FBQyxLQUFLLENBQUM7UUFDdEQsTUFBTSxFQUFFLFVBQVU7UUFDbEIsR0FBRyxXQUFXO0tBQ2YsQ0FBQyxDQUFBO0lBRUYsT0FBTyxHQUFHLENBQUMsSUFBSSxDQUFDO1FBQ2QsU0FBUztRQUNULEtBQUssRUFBRSxRQUFRLEVBQUUsS0FBSyxJQUFJLFNBQVMsQ0FBQyxNQUFNO1FBQzFDLEtBQUssRUFBRSxHQUFHLENBQUMsV0FBVyxFQUFFLFVBQVUsRUFBRSxJQUFJLElBQUksRUFBRTtRQUM5QyxNQUFNLEVBQUUsR0FBRyxDQUFDLFdBQVcsRUFBRSxVQUFVLEVBQUUsSUFBSSxJQUFJLENBQUM7S0FDL0MsQ0FBQyxDQUFBO0FBQ0osQ0FBQyJ9
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const http_1 = require("@medusajs/framework/http");
|
|
4
4
|
const middlewares_1 = require("./admin/companies/middlewares");
|
|
5
|
+
const middlewares_2 = require("./admin/employees/middlewares");
|
|
5
6
|
exports.default = (0, http_1.defineMiddlewares)({
|
|
6
|
-
routes: [...middlewares_1.companiesMiddlewares],
|
|
7
|
+
routes: [...middlewares_1.companiesMiddlewares, ...middlewares_2.employeesMiddlewares],
|
|
7
8
|
});
|
|
8
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWlkZGxld2FyZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvYXBpL21pZGRsZXdhcmVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsbURBQTREO0FBQzVELCtEQUFvRTtBQUNwRSwrREFBb0U7QUFFcEUsa0JBQWUsSUFBQSx3QkFBaUIsRUFBQztJQUMvQixNQUFNLEVBQUUsQ0FBQyxHQUFHLGtDQUFvQixFQUFFLEdBQUcsa0NBQW9CLENBQUM7Q0FDM0QsQ0FBQyxDQUFBIn0=
|