PageSourceSearch

https://www.hamienet.com/assets/RegionManager-CnhTdhVc.js

js hamienet.com collected 2026-09-24 19:00:42 UTC 11,815 bytes, 207 lines download raw bytes

1import { r as reactExports, j as jsxRuntimeExports, R as React } from "./vendor-react-Bay9Y7Lb.js";
2import { a as api } from "./index-D0Bmh-UX.js";
3import { a as DataTable, b as Drawer, D as DevDebugInfo } from "./AdminShared-P_hor2hS.js";
4import { bn as Globe, fW as Ban, bv as CircleCheckBig, ce as Plus, cc as Save } from "./vendor-dVNaLJx_.js";
5import "./vendor-i18n-R-bMoYp_.js";
6const RegionFormDrawer = ({ region, onClose, onRefresh, activeRole }) => {
7  const [form, setForm] = reactExports.useState({
8    code: "",
9    name: "",
10    currencyCode: "USD",
11    currencySymbol: "$",
12    locale: "en-US",
13    flag: "",
14    isBlocked: false
15  });
16  const isEdit = !!(region == null ? void 0 : region.code);
17  React.useEffect(() => {
18    if (region) setForm(region);
19    else setForm({ code: "", name: "", currencyCode: "USD", currencySymbol: "$", locale: "en-US", flag: "", isBlocked: false });
20  }, [region]);
21  const handleSave = async () => {
22    if (!form.code || !form.name) return alert("Code and Name are required");
23    const regionData = { ...form, id: form.code };
24    if (isEdit) {
25      await api.updateRegion(form.code, regionData);
26    } else {
27      await api.createRegion(regionData);
28    }
29    onRefresh();
30    onClose();
31  };
32  if (!region && region !== null) return null;
33  return /* @__PURE__ */ jsxRuntimeExports.jsx(Drawer, { isOpen: !!region || region === null, onClose, title: isEdit ? `Edit Region: ${form.name}` : "New Region", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [
34    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
35      /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-xs font-bold text-zinc-500 uppercase mb-1", children: "ISO Code (ID)" }),
36      /* @__PURE__ */ jsxRuntimeExports.jsx(
37        "input",
38        {
39          value: form.code,
40          onChange: (e) => setForm({ ...form, code: e.target.value.toUpperCase() }),
41          disabled: isEdit,
42          maxLength: 2,
43          className: `w-full bg-zinc-50 dark:bg-zinc-950 border border-zinc-300 dark:border-zinc-800 rounded p-2 text-sm outline-none focus:border-indigo-500 text-zinc-900 dark:text-white font-mono ${isEdit ? "opacity-50 cursor-not-allowed" : ""}`,
44          placeholder: "US"
45        }
46      )
47    ] }),
48    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
49      /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-xs font-bold text-zinc-500 uppercase mb-1", children: "Region Name" }),
50      /* @__PURE__ */ jsxRuntimeExports.jsx(
51        "input",
52        {
53          value: form.name,
54          onChange: (e) => setForm({ ...form, name: e.target.value }),
55          className: "w-full bg-zinc-50 dark:bg-zinc-950 border border-zinc-300 dark:border-zinc-800 rounded p-2 text-sm outline-none focus:border-indigo-500 text-zinc-900 dark:text-white",
56          placeholder: "United States"
57        }
58      )
59    ] }),
60    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
61      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
62        /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-xs font-bold text-zinc-500 uppercase mb-1", children: "Currency Code" }),
63        /* @__PURE__ */ jsxRuntimeExports.jsx(
64          "input",
65          {
66            value: form.currencyCode,
67            onChange: (e) => setForm({ ...form, currencyCode: e.target.value.toUpperCase() }),
68            className: "w-full bg-zinc-50 dark:bg-zinc-950 border border-zinc-300 dark:border-zinc-800 rounded p-2 text-sm outline-none focus:border-indigo-500 text-zinc-900 dark:text-white font-mono",
69            placeholder: "USD"
70          }
71        )
72      ] }),
73      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
74        /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-xs font-bold text-zinc-500 uppercase mb-1", children: "Symbol" }),
75        /* @__PURE__ */ jsxRuntimeExports.jsx(
76          "input",
77          {
78            value: form.currencySymbol,
79            onChange: (e) => setForm({ ...form, currencySymbol: e.target.value }),
80            className: "w-full bg-zinc-50 dark:bg-zinc-950 border border-zinc-300 dark:border-zinc-800 rounded p-2 text-sm outline-none focus:border-indigo-500 text-zinc-900 dark:text-white",
81            placeholder: "$"
82          }
83        )
84      ] })
85    ] }),
86    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
87      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
88        /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-xs font-bold text-zinc-500 uppercase mb-1", children: "Locale (Format)" }),
89        /* @__PURE__ */ jsxRuntimeExports.jsx(
90          "input",
91          {
92            value: form.locale,
93            onChange: (e) => setForm({ ...form, locale: e.target.value }),
94            className: "w-full bg-zinc-50 dark:bg-zinc-950 border border-zinc-300 dark:border-zinc-800 rounded p-2 text-sm outline-none focus:border-indigo-500 text-zinc-900 dark:text-white font-mono",
95            placeholder: "en-US"
96          }
97        )
98      ] }),
99      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
100        /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "block text-xs font-bold text-zinc-500 uppercase mb-1", children: "Flag Emoji" }),
101        /* @__PURE__ */ jsxRuntimeExports.jsx(
102          "input",
103          {
104            value: form.flag,
105            onChange: (e) => setForm({ ...form, flag: e.target.value }),
106            className: "w-full bg-zinc-50 dark:bg-zinc-950 border border-zinc-300 dark:border-zinc-800 rounded p-2 text-sm outline-none focus:border-indigo-500 text-zinc-900 dark:text-white text-center text-xl",
107            placeholder: "🇺🇸"
108          }
109        )
110      ] })
111    ] }),
112    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-4 bg-zinc-100 dark:bg-zinc-800 rounded-lg flex items-center justify-between border border-zinc-200 dark:border-zinc-700", children: [
113      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
114        /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: "font-bold text-sm text-zinc-900 dark:text-white", children: "Geo-Blocking" }),
115        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-zinc-500", children: "Prevent access to content from this region." })
116      ] }),
117      /* @__PURE__ */ jsxRuntimeExports.jsx(
118        "button",
119        {
120          onClick: () => setForm({ ...form, isBlocked: !form.isBlocked }),
121          className: `relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${form.isBlocked ? "bg-red-500" : "bg-zinc-300 dark:bg-zinc-600"}`,
122          children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `inline-block h-4 w-4 transform rounded-full bg-white transition duration-200 ease-in-out ${form.isBlocked ? "translate-x-6" : "translate-x-1"}` })
123        }
124      )
125    ] }),
126    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex gap-2 pt-4", children: [
127      /* @__PURE__ */ jsxRuntimeExports.jsx("button", { onClick: onClose, className: "flex-1 px-4 py-2 rounded-lg border border-zinc-300 dark:border-zinc-700 font-bold text-zinc-600 dark:text-zinc-400 hover:bg-zinc-50 dark:hover:bg-zinc-800", children: "Cancel" }),
128      /* @__PURE__ */ jsxRuntimeExports.jsxs("button", { onClick: handleSave, className: "flex-1 px-4 py-2 rounded-lg bg-indigo-600 hover:bg-indigo-700 text-white font-bold flex items-center justify-center gap-2", children: [
129        /* @__PURE__ */ jsxRuntimeExports.jsx(Save, { size: 16 }),
130        " Save"
131      ] })
132    ] }),
133    isEdit && /* @__PURE__ */ jsxRuntimeExports.jsx(DevDebugInfo, { table: "RegionConfig", keyName: form.code, value: form, isSuperAdmin: activeRole == null ? void 0 : activeRole.isSuperAdmin })
134  ] }) });
135};
136const RegionManager = ({ activeRole }) => {
137  const [localRefresh, setLocalRefresh] = reactExports.useState(0);
138  const [editingRegion, setEditingRegion] = reactExports.useState(void 0);
139  const refresh = () => setLocalRefresh((p) => p + 1);
140  const fetcher = reactExports.useCallback(async (params) => {
141    const regions = await api.getAdminRegions(params);
142    return { data: regions, total: regions.length };
143  }, []);
144  const actions = /* @__PURE__ */ jsxRuntimeExports.jsxs(
145    "button",
146    {
147      onClick: () => setEditingRegion(null),
148      className: "flex items-center gap-2 px-3 py-1.5 rounded-lg bg-indigo-600 text-white hover:bg-indigo-700 text-xs font-bold",
149      children: [
150        /* @__PURE__ */ jsxRuntimeExports.jsx(Plus, { size: 14 }),
151        " Add Region"
152      ]
153    }
154  );
155  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
156    /* @__PURE__ */ jsxRuntimeExports.jsx(
157      DataTable,
158      {
159        title: "Region Settings",
160        icon: Globe,
161        placeholder: "Search countries...",
162        filters: [],
163        onFetch: fetcher,
164        reloadTrigger: localRefresh,
165        onRowClick: (r) => setEditingRegion(r),
166        actions,
167        columnHeaders: ["Country", "Currency", "Locale", "Access"],
168        columns: (region) => /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
169          /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [
170            /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-2xl", children: region.flag }),
171            /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
172              /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-bold text-zinc-900 dark:text-white", children: region.name }),
173              /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-zinc-500 font-mono", children: region.code })
174            ] })
175          ] }) }),
176          /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col", children: [
177            /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm font-bold text-zinc-800 dark:text-zinc-200", children: region.currencyCode }),
178            /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-xs text-zinc-500", children: [
179              "Symbol: ",
180              region.currencySymbol
181            ] })
182          ] }) }),
183          /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: "px-6 py-4 font-mono text-xs text-zinc-600 dark:text-zinc-400", children: region.locale }),
184          /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: "px-6 py-4", children: region.isBlocked ? /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "inline-flex items-center gap-1 px-2 py-1 rounded-full bg-red-100 text-red-700 text-[10px] font-bold uppercase tracking-wide border border-red-200", children: [
185            /* @__PURE__ */ jsxRuntimeExports.jsx(Ban, { size: 10 }),
186            " Blocked"
187          ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "inline-flex items-center gap-1 px-2 py-1 rounded-full bg-emerald-100 text-emerald-700 text-[10px] font-bold uppercase tracking-wide border border-emerald-200", children: [
188            /* @__PURE__ */ jsxRuntimeExports.jsx(CircleCheckBig, { size: 10 }),
189            " Allowed"
190          ] }) })
191        ] })
192      }
193    ),
194    editingRegion !== void 0 && /* @__PURE__ */ jsxRuntimeExports.jsx(
195      RegionFormDrawer,
196      {
197        region: editingRegion,
198        onClose: () => setEditingRegion(void 0),
199        onRefresh: refresh,
200        activeRole
201      }
202    )
203  ] });
204};
205export {
206  RegionManager as default
207};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.