@mesob/auth-react 0.3.4 → 0.4.0

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.
Files changed (142) hide show
  1. package/dist/components/auth/auth-layout.d.ts +1 -1
  2. package/dist/components/auth/auth-layout.js +10 -2
  3. package/dist/components/auth/auth-layout.js.map +1 -1
  4. package/dist/components/auth/countdown.js +8 -6
  5. package/dist/components/auth/countdown.js.map +1 -1
  6. package/dist/components/auth/forgot-password.js +21 -19
  7. package/dist/components/auth/forgot-password.js.map +1 -1
  8. package/dist/components/auth/reset-password-form.js +22 -21
  9. package/dist/components/auth/reset-password-form.js.map +1 -1
  10. package/dist/components/auth/set-password.d.ts +9 -0
  11. package/dist/components/auth/set-password.js +527 -0
  12. package/dist/components/auth/set-password.js.map +1 -0
  13. package/dist/components/auth/sign-in.js +45 -26
  14. package/dist/components/auth/sign-in.js.map +1 -1
  15. package/dist/components/auth/sign-up.js +25 -29
  16. package/dist/components/auth/sign-up.js.map +1 -1
  17. package/dist/components/auth/verification-form.js +24 -27
  18. package/dist/components/auth/verification-form.js.map +1 -1
  19. package/dist/components/auth/verify-email.js +40 -31
  20. package/dist/components/auth/verify-email.js.map +1 -1
  21. package/dist/components/auth/verify-phone.js +40 -31
  22. package/dist/components/auth/verify-phone.js.map +1 -1
  23. package/dist/components/authorization/deny.d.ts +11 -0
  24. package/dist/components/authorization/deny.js +52 -0
  25. package/dist/components/authorization/deny.js.map +1 -0
  26. package/dist/components/authorization/grant.d.ts +12 -0
  27. package/dist/components/authorization/grant.js +57 -0
  28. package/dist/components/authorization/grant.js.map +1 -0
  29. package/dist/components/iam/permission-selector.d.ts +19 -0
  30. package/dist/components/iam/permission-selector.js +122 -0
  31. package/dist/components/iam/permission-selector.js.map +1 -0
  32. package/dist/components/iam/permissions.js +21 -33
  33. package/dist/components/iam/permissions.js.map +1 -1
  34. package/dist/components/iam/role-detail-layout.d.ts +11 -0
  35. package/dist/components/iam/role-detail-layout.js +137 -0
  36. package/dist/components/iam/role-detail-layout.js.map +1 -0
  37. package/dist/components/iam/role-detail-page.d.ts +9 -0
  38. package/dist/components/iam/role-detail-page.js +229 -0
  39. package/dist/components/iam/role-detail-page.js.map +1 -0
  40. package/dist/components/iam/role-permissions-page.d.ts +8 -0
  41. package/dist/components/iam/role-permissions-page.js +397 -0
  42. package/dist/components/iam/role-permissions-page.js.map +1 -0
  43. package/dist/components/iam/roles.js +20 -10
  44. package/dist/components/iam/roles.js.map +1 -1
  45. package/dist/components/iam/tenants.js +9 -2
  46. package/dist/components/iam/tenants.js.map +1 -1
  47. package/dist/components/iam/users.js +10 -9
  48. package/dist/components/iam/users.js.map +1 -1
  49. package/dist/components/profile/account.js +110 -19
  50. package/dist/components/profile/account.js.map +1 -1
  51. package/dist/components/profile/change-email-form.js +26 -29
  52. package/dist/components/profile/change-email-form.js.map +1 -1
  53. package/dist/components/profile/change-phone-form.js +26 -29
  54. package/dist/components/profile/change-phone-form.js.map +1 -1
  55. package/dist/components/profile/change-profile.d.ts +2 -1
  56. package/dist/components/profile/change-profile.js +16 -8
  57. package/dist/components/profile/change-profile.js.map +1 -1
  58. package/dist/components/profile/otp-verification-modal.js +24 -27
  59. package/dist/components/profile/otp-verification-modal.js.map +1 -1
  60. package/dist/components/profile/security.js +88 -57
  61. package/dist/components/profile/security.js.map +1 -1
  62. package/dist/components/profile/verify-change-email-form.js +24 -27
  63. package/dist/components/profile/verify-change-email-form.js.map +1 -1
  64. package/dist/components/profile/verify-change-phone-form.js +24 -27
  65. package/dist/components/profile/verify-change-phone-form.js.map +1 -1
  66. package/dist/index.d.ts +9 -1
  67. package/dist/index.js +1897 -821
  68. package/dist/index.js.map +1 -1
  69. package/dist/pages/auth/forgot-password.d.ts +7 -0
  70. package/dist/pages/auth/forgot-password.js +784 -0
  71. package/dist/pages/auth/forgot-password.js.map +1 -0
  72. package/dist/pages/auth/layout.d.ts +8 -0
  73. package/dist/pages/auth/layout.js +562 -0
  74. package/dist/pages/auth/layout.js.map +1 -0
  75. package/dist/pages/auth/reset-password.d.ts +10 -0
  76. package/dist/pages/auth/reset-password.js +913 -0
  77. package/dist/pages/auth/reset-password.js.map +1 -0
  78. package/dist/pages/auth/set-password.d.ts +10 -0
  79. package/dist/pages/auth/set-password.js +946 -0
  80. package/dist/pages/auth/set-password.js.map +1 -0
  81. package/dist/pages/auth/sign-in.d.ts +10 -0
  82. package/dist/pages/auth/sign-in.js +984 -0
  83. package/dist/pages/auth/sign-in.js.map +1 -0
  84. package/dist/pages/auth/sign-up.d.ts +10 -0
  85. package/dist/pages/auth/sign-up.js +940 -0
  86. package/dist/pages/auth/sign-up.js.map +1 -0
  87. package/dist/pages/auth/verify-email.d.ts +10 -0
  88. package/dist/pages/auth/verify-email.js +950 -0
  89. package/dist/pages/auth/verify-email.js.map +1 -0
  90. package/dist/pages/auth/verify-phone.d.ts +10 -0
  91. package/dist/pages/auth/verify-phone.js +964 -0
  92. package/dist/pages/auth/verify-phone.js.map +1 -0
  93. package/dist/pages/iam/permissions.d.ts +5 -0
  94. package/dist/pages/iam/permissions.js +308 -0
  95. package/dist/pages/iam/permissions.js.map +1 -0
  96. package/dist/pages/iam/role-detail-layout.d.ts +12 -0
  97. package/dist/pages/iam/role-detail-layout.js +145 -0
  98. package/dist/pages/iam/role-detail-layout.js.map +1 -0
  99. package/dist/pages/iam/role-detail.d.ts +12 -0
  100. package/dist/pages/iam/role-detail.js +241 -0
  101. package/dist/pages/iam/role-detail.js.map +1 -0
  102. package/dist/pages/iam/role-permissions.d.ts +12 -0
  103. package/dist/pages/iam/role-permissions.js +409 -0
  104. package/dist/pages/iam/role-permissions.js.map +1 -0
  105. package/dist/pages/iam/role-users.d.ts +12 -0
  106. package/dist/pages/iam/role-users.js +825 -0
  107. package/dist/pages/iam/role-users.js.map +1 -0
  108. package/dist/pages/iam/roles.d.ts +5 -0
  109. package/dist/pages/iam/roles.js +684 -0
  110. package/dist/pages/iam/roles.js.map +1 -0
  111. package/dist/pages/iam/sessions.d.ts +5 -0
  112. package/dist/pages/iam/sessions.js +315 -0
  113. package/dist/pages/iam/sessions.js.map +1 -0
  114. package/dist/pages/iam/tenant-detail.d.ts +10 -0
  115. package/dist/pages/iam/tenant-detail.js +186 -0
  116. package/dist/pages/iam/tenant-detail.js.map +1 -0
  117. package/dist/pages/iam/tenants.d.ts +5 -0
  118. package/dist/pages/iam/tenants.js +610 -0
  119. package/dist/pages/iam/tenants.js.map +1 -0
  120. package/dist/pages/iam/user-activity.d.ts +10 -0
  121. package/dist/pages/iam/user-activity.js +850 -0
  122. package/dist/pages/iam/user-activity.js.map +1 -0
  123. package/dist/pages/iam/user-detail-layout.d.ts +12 -0
  124. package/dist/pages/iam/user-detail-layout.js +106 -0
  125. package/dist/pages/iam/user-detail-layout.js.map +1 -0
  126. package/dist/pages/iam/user-detail.d.ts +10 -0
  127. package/dist/pages/iam/user-detail.js +102 -0
  128. package/dist/pages/iam/user-detail.js.map +1 -0
  129. package/dist/pages/iam/users.d.ts +5 -0
  130. package/dist/pages/iam/users.js +1275 -0
  131. package/dist/pages/iam/users.js.map +1 -0
  132. package/dist/pages/profile/account.d.ts +5 -0
  133. package/dist/pages/profile/account.js +182 -0
  134. package/dist/pages/profile/account.js.map +1 -0
  135. package/dist/pages/profile/layout.d.ts +8 -0
  136. package/dist/pages/profile/layout.js +133 -0
  137. package/dist/pages/profile/layout.js.map +1 -0
  138. package/dist/pages/profile/security.d.ts +5 -0
  139. package/dist/pages/profile/security.js +1539 -0
  140. package/dist/pages/profile/security.js.map +1 -0
  141. package/dist/{types-vcfvnAzQ.d.ts → types-g9QcNRxT.d.ts} +13 -7
  142. package/package.json +102 -3
@@ -0,0 +1,397 @@
1
+ "use client";
2
+
3
+ // src/components/iam/role-permissions-page.tsx
4
+ import {
5
+ Badge as Badge2,
6
+ Button,
7
+ DataTablePagination,
8
+ DeleteConfirmButton,
9
+ DisplayTable,
10
+ EntityEmptyState,
11
+ EntityFilter,
12
+ EntityHeader,
13
+ EntityLoadingState,
14
+ EntitySearch,
15
+ EntitySort,
16
+ EntityViewToggle,
17
+ PageBody,
18
+ Tbody,
19
+ Td,
20
+ Th,
21
+ Thead,
22
+ Tr,
23
+ useEntityPagination,
24
+ useEntityParams
25
+ } from "@mesob/ui/components";
26
+ import { IconKey as IconKey2, IconPlus, IconTrash } from "@tabler/icons-react";
27
+ import { useQueryClient } from "@tanstack/react-query";
28
+ import { useMemo as useMemo2 } from "react";
29
+ import { toast } from "sonner";
30
+
31
+ // src/provider.tsx
32
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
33
+ import { deepmerge } from "deepmerge-ts";
34
+ import createFetchClient from "openapi-fetch";
35
+ import createClient from "openapi-react-query";
36
+ import { createContext, useContext, useMemo, useState } from "react";
37
+
38
+ // src/utils/cookie.ts
39
+ var isProduction = typeof process !== "undefined" && process.env.NODE_ENV === "production";
40
+
41
+ // src/provider.tsx
42
+ import { jsx } from "react/jsx-runtime";
43
+ var SessionContext = createContext(null);
44
+ var ApiContext = createContext(null);
45
+ var ConfigContext = createContext(null);
46
+ var queryClient = new QueryClient({
47
+ defaultOptions: {
48
+ queries: {
49
+ refetchOnWindowFocus: false
50
+ }
51
+ }
52
+ });
53
+ function useApi() {
54
+ const context = useContext(ApiContext);
55
+ if (!context) {
56
+ throw new Error("useApi must be used within MesobAuthProvider");
57
+ }
58
+ return context;
59
+ }
60
+
61
+ // src/components/iam/permission-selector.tsx
62
+ import {
63
+ Badge,
64
+ EntitySelector,
65
+ useEntitySectionState
66
+ } from "@mesob/ui/components";
67
+ import { IconKey } from "@tabler/icons-react";
68
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
69
+ var permissionColumns = [
70
+ {
71
+ key: "permission",
72
+ header: "Permission",
73
+ cell: (permission) => /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
74
+ /* @__PURE__ */ jsx2("p", { className: "font-medium", children: permission.activity }),
75
+ /* @__PURE__ */ jsx2("p", { className: "font-mono text-xs text-muted-foreground", children: permission.id })
76
+ ] })
77
+ },
78
+ {
79
+ key: "scope",
80
+ header: "Scope",
81
+ cell: (permission) => /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", children: [
82
+ /* @__PURE__ */ jsx2(Badge, { variant: "secondary", children: permission.application }),
83
+ /* @__PURE__ */ jsx2(Badge, { variant: "outline", children: permission.feature })
84
+ ] })
85
+ }
86
+ ];
87
+ function PermissionSelector({
88
+ trigger,
89
+ multiple = true,
90
+ onSelect,
91
+ excludeIds = []
92
+ }) {
93
+ const { hooks } = useApi();
94
+ const state = useEntitySectionState({
95
+ defaultSort: "id",
96
+ defaultOrder: "asc",
97
+ defaultPageSize: 10,
98
+ searchParamName: "search"
99
+ });
100
+ const permissionsQuery = state.queryConfig;
101
+ const { data, isPending, isFetching } = hooks.useQuery(
102
+ "get",
103
+ "/permissions",
104
+ permissionsQuery
105
+ );
106
+ const items = (data?.permissions ?? []).filter(
107
+ (permission) => !excludeIds.includes(permission.id)
108
+ );
109
+ const config = {
110
+ title: "Select permission(s)",
111
+ multiple,
112
+ entityName: "permission",
113
+ entityIcon: IconKey,
114
+ columns: permissionColumns,
115
+ getItemLabel: (permission) => permission.id,
116
+ searchPlaceholder: "Search permissions...",
117
+ filterOptions: [
118
+ { label: "All", value: "" },
119
+ { label: "Application", value: "application" },
120
+ { label: "Feature", value: "feature" },
121
+ { label: "Activity", value: "activity" }
122
+ ],
123
+ sortOptions: [
124
+ { label: "ID", value: "id" },
125
+ { label: "Application", value: "application" },
126
+ { label: "Feature", value: "feature" },
127
+ { label: "Activity", value: "activity" }
128
+ ],
129
+ showViewToggle: false,
130
+ wrapHeaderInCard: false
131
+ };
132
+ return /* @__PURE__ */ jsx2(
133
+ EntitySelector,
134
+ {
135
+ trigger,
136
+ config,
137
+ onSelect,
138
+ items,
139
+ total: items.length,
140
+ isLoading: isPending || isFetching,
141
+ state
142
+ }
143
+ );
144
+ }
145
+
146
+ // src/components/iam/role-permissions-page.tsx
147
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
148
+ var TABLE_COLUMN_COUNT = 4;
149
+ function RolePermissionsPage({ roleId }) {
150
+ const { hooks } = useApi();
151
+ const qc = useQueryClient();
152
+ const { queryConfig, params, setParams } = useEntityParams({
153
+ searchKey: "search",
154
+ defaultSort: "application",
155
+ defaultOrder: "asc"
156
+ });
157
+ const permissionsQuery = useMemo2(
158
+ () => ({
159
+ params: {
160
+ path: { id: roleId },
161
+ query: queryConfig.params.query
162
+ }
163
+ }),
164
+ [queryConfig, roleId]
165
+ );
166
+ const { data, isPending, isFetching } = hooks.useQuery(
167
+ "get",
168
+ "/roles/{id}/permissions",
169
+ permissionsQuery,
170
+ { enabled: !!roleId }
171
+ );
172
+ const assignPermissions = hooks.useMutation(
173
+ "post",
174
+ "/roles/{id}/permissions",
175
+ {
176
+ onSuccess: (result) => {
177
+ qc.invalidateQueries({ queryKey: ["get", "/roles"] });
178
+ qc.invalidateQueries({ queryKey: ["get", "/roles/{id}"] });
179
+ qc.invalidateQueries({ queryKey: ["get", "/roles/{id}/permissions"] });
180
+ toast.success(
181
+ result?.created ? `${result.created} permission(s) added` : "No changes"
182
+ );
183
+ },
184
+ onError: () => {
185
+ toast.error("Failed to assign permissions");
186
+ }
187
+ }
188
+ );
189
+ const revokePermission = hooks.useMutation(
190
+ "delete",
191
+ "/roles/{id}/permissions/{permissionId}",
192
+ {
193
+ onSuccess: () => {
194
+ qc.invalidateQueries({ queryKey: ["get", "/roles"] });
195
+ qc.invalidateQueries({ queryKey: ["get", "/roles/{id}"] });
196
+ qc.invalidateQueries({
197
+ queryKey: ["get", "/roles/{id}/permissions"]
198
+ });
199
+ toast.success("Permission removed");
200
+ },
201
+ onError: () => {
202
+ toast.error("Failed to remove permission");
203
+ }
204
+ }
205
+ );
206
+ const permissions = data?.permissions ?? [];
207
+ const { total, pageCount } = useEntityPagination({
208
+ items: permissions,
209
+ total: data?.total,
210
+ pageSize: params.pageSize
211
+ });
212
+ const isLoading = isPending || isFetching;
213
+ const currentView = params.view || "table";
214
+ if (!roleId) {
215
+ return null;
216
+ }
217
+ let content;
218
+ if (isLoading) {
219
+ content = /* @__PURE__ */ jsx3(
220
+ EntityLoadingState,
221
+ {
222
+ view: currentView,
223
+ rowCount: params.pageSize,
224
+ columnCount: TABLE_COLUMN_COUNT,
225
+ cardCount: params.pageSize
226
+ }
227
+ );
228
+ } else if (total === 0) {
229
+ content = /* @__PURE__ */ jsx3(
230
+ EntityEmptyState,
231
+ {
232
+ icon: IconKey2,
233
+ entityName: "permission",
234
+ title: "No permissions assigned",
235
+ description: "Assign permissions from the selector to grant access to this role."
236
+ }
237
+ );
238
+ } else if (currentView === "table") {
239
+ content = /* @__PURE__ */ jsxs2("div", { className: "space-y-4", children: [
240
+ /* @__PURE__ */ jsxs2(DisplayTable, { withTableBorder: true, children: [
241
+ /* @__PURE__ */ jsx3(Thead, { children: /* @__PURE__ */ jsxs2(Tr, { children: [
242
+ /* @__PURE__ */ jsx3(Th, { children: "Permission" }),
243
+ /* @__PURE__ */ jsx3(Th, { children: "Application" }),
244
+ /* @__PURE__ */ jsx3(Th, { children: "Feature" }),
245
+ /* @__PURE__ */ jsx3(Th, { className: "w-[60px]" })
246
+ ] }) }),
247
+ /* @__PURE__ */ jsx3(Tbody, { children: permissions.map((permission) => /* @__PURE__ */ jsxs2(Tr, { children: [
248
+ /* @__PURE__ */ jsx3(Td, { children: /* @__PURE__ */ jsxs2("div", { className: "space-y-1", children: [
249
+ /* @__PURE__ */ jsx3("p", { className: "font-medium", children: permission.activity }),
250
+ /* @__PURE__ */ jsx3("p", { className: "font-mono text-xs text-muted-foreground", children: permission.id })
251
+ ] }) }),
252
+ /* @__PURE__ */ jsx3(Td, { children: /* @__PURE__ */ jsx3(Badge2, { variant: "secondary", children: permission.application }) }),
253
+ /* @__PURE__ */ jsx3(Td, { children: /* @__PURE__ */ jsx3(Badge2, { variant: "outline", children: permission.feature }) }),
254
+ /* @__PURE__ */ jsx3(Td, { children: /* @__PURE__ */ jsx3(
255
+ DeleteConfirmButton,
256
+ {
257
+ entityName: "permission",
258
+ onConfirm: () => revokePermission.mutate({
259
+ params: {
260
+ path: { id: roleId, permissionId: permission.id }
261
+ }
262
+ }),
263
+ triggerClassName: "size-8 text-destructive hover:text-destructive"
264
+ }
265
+ ) })
266
+ ] }, permission.id)) })
267
+ ] }),
268
+ /* @__PURE__ */ jsx3(
269
+ DataTablePagination,
270
+ {
271
+ pageIndex: params.page - 1,
272
+ pageSize: params.pageSize,
273
+ pageCount,
274
+ totalRows: total,
275
+ onPageChange: (page) => setParams({ page: page + 1 }),
276
+ onPageSizeChange: (pageSize) => setParams({ pageSize, page: 1 })
277
+ }
278
+ )
279
+ ] });
280
+ } else {
281
+ content = /* @__PURE__ */ jsxs2("div", { className: "space-y-4", children: [
282
+ /* @__PURE__ */ jsx3("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3", children: permissions.map((permission) => /* @__PURE__ */ jsx3(
283
+ "div",
284
+ {
285
+ className: "rounded-xl border border-border/60 bg-card p-4 shadow-sm",
286
+ children: /* @__PURE__ */ jsxs2("div", { className: "flex items-start justify-between gap-3", children: [
287
+ /* @__PURE__ */ jsxs2("div", { className: "space-y-2", children: [
288
+ /* @__PURE__ */ jsx3("p", { className: "font-semibold", children: permission.activity }),
289
+ /* @__PURE__ */ jsxs2("div", { className: "flex flex-wrap gap-2", children: [
290
+ /* @__PURE__ */ jsx3(Badge2, { variant: "secondary", children: permission.application }),
291
+ /* @__PURE__ */ jsx3(Badge2, { variant: "outline", children: permission.feature })
292
+ ] }),
293
+ /* @__PURE__ */ jsx3("p", { className: "font-mono text-xs text-muted-foreground", children: permission.id })
294
+ ] }),
295
+ /* @__PURE__ */ jsx3(
296
+ Button,
297
+ {
298
+ type: "button",
299
+ variant: "ghost",
300
+ size: "icon",
301
+ onClick: () => revokePermission.mutate({
302
+ params: {
303
+ path: { id: roleId, permissionId: permission.id }
304
+ }
305
+ }),
306
+ disabled: revokePermission.isPending,
307
+ children: /* @__PURE__ */ jsx3(IconTrash, { className: "h-4 w-4" })
308
+ }
309
+ )
310
+ ] })
311
+ },
312
+ permission.id
313
+ )) }),
314
+ /* @__PURE__ */ jsx3(
315
+ DataTablePagination,
316
+ {
317
+ pageIndex: params.page - 1,
318
+ pageSize: params.pageSize,
319
+ pageCount,
320
+ totalRows: total,
321
+ onPageChange: (page) => setParams({ page: page + 1 }),
322
+ onPageSizeChange: (pageSize) => setParams({ pageSize, page: 1 })
323
+ }
324
+ )
325
+ ] });
326
+ }
327
+ return /* @__PURE__ */ jsxs2(PageBody, { className: "px-0 pb-6", children: [
328
+ /* @__PURE__ */ jsx3(
329
+ EntityHeader,
330
+ {
331
+ icon: /* @__PURE__ */ jsx3(IconKey2, { className: "h-5 w-5" }),
332
+ title: "Role permissions",
333
+ actions: /* @__PURE__ */ jsx3(
334
+ PermissionSelector,
335
+ {
336
+ trigger: /* @__PURE__ */ jsxs2(Button, { size: "sm", loading: assignPermissions.isPending, children: [
337
+ /* @__PURE__ */ jsx3(IconPlus, { className: "h-4 w-4" }),
338
+ "Add permissions"
339
+ ] }),
340
+ onSelect: (selectedPermissions) => {
341
+ if (!selectedPermissions.length) {
342
+ return;
343
+ }
344
+ assignPermissions.mutate({
345
+ params: { path: { id: roleId } },
346
+ body: {
347
+ permissionIds: selectedPermissions.map(
348
+ (permission) => permission.id
349
+ )
350
+ }
351
+ });
352
+ },
353
+ excludeIds: permissions.map((permission) => permission.id)
354
+ }
355
+ ),
356
+ search: /* @__PURE__ */ jsx3(
357
+ EntitySearch,
358
+ {
359
+ paramKey: "search",
360
+ placeholder: "Search assigned permissions..."
361
+ }
362
+ ),
363
+ filter: /* @__PURE__ */ jsx3(
364
+ EntityFilter,
365
+ {
366
+ options: [
367
+ { label: "All", value: "" },
368
+ { label: "Application", value: "application" },
369
+ { label: "Feature", value: "feature" },
370
+ { label: "Activity", value: "activity" }
371
+ ],
372
+ placeholder: "Search field"
373
+ }
374
+ ),
375
+ sort: /* @__PURE__ */ jsx3(
376
+ EntitySort,
377
+ {
378
+ defaultSort: "application",
379
+ defaultOrder: "asc",
380
+ options: [
381
+ { label: "ID", value: "id" },
382
+ { label: "Application", value: "application" },
383
+ { label: "Feature", value: "feature" },
384
+ { label: "Activity", value: "activity" }
385
+ ]
386
+ }
387
+ ),
388
+ view: /* @__PURE__ */ jsx3(EntityViewToggle, { views: ["table", "card"] })
389
+ }
390
+ ),
391
+ content
392
+ ] });
393
+ }
394
+ export {
395
+ RolePermissionsPage
396
+ };
397
+ //# sourceMappingURL=role-permissions-page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/iam/role-permissions-page.tsx","../../../src/provider.tsx","../../../src/utils/cookie.ts","../../../src/components/iam/permission-selector.tsx"],"sourcesContent":["'use client';\n\nimport {\n Badge,\n Button,\n DataTablePagination,\n DeleteConfirmButton,\n DisplayTable,\n EntityEmptyState,\n EntityFilter,\n EntityHeader,\n EntityLoadingState,\n EntitySearch,\n EntitySort,\n EntityViewToggle,\n PageBody,\n Tbody,\n Td,\n Th,\n Thead,\n Tr,\n useEntityPagination,\n useEntityParams,\n} from '@mesob/ui/components';\nimport { IconKey, IconPlus, IconTrash } from '@tabler/icons-react';\nimport { useQueryClient } from '@tanstack/react-query';\nimport type { ReactNode } from 'react';\nimport { useMemo } from 'react';\nimport { toast } from 'sonner';\nimport type { paths } from '../../data/openapi';\nimport { useApi } from '../../provider';\nimport { PermissionSelector } from './permission-selector';\n\ntype Permission = {\n id: string;\n description?: unknown;\n activity: string;\n application: string;\n feature: string;\n};\n\ntype RolePermissionsPageProps = {\n roleId: string;\n};\n\nconst TABLE_COLUMN_COUNT = 4;\n\nexport function RolePermissionsPage({ roleId }: RolePermissionsPageProps) {\n const { hooks } = useApi();\n const qc = useQueryClient();\n const { queryConfig, params, setParams } = useEntityParams({\n searchKey: 'search',\n defaultSort: 'application',\n defaultOrder: 'asc',\n });\n const permissionsQuery = useMemo(\n () =>\n ({\n params: {\n path: { id: roleId },\n query: queryConfig.params.query,\n },\n }) as {\n params: {\n path: { id: string };\n query: NonNullable<\n paths['/roles/{id}/permissions']['get']['parameters']['query']\n >;\n };\n },\n [queryConfig, roleId],\n );\n\n const { data, isPending, isFetching } = hooks.useQuery(\n 'get',\n '/roles/{id}/permissions',\n permissionsQuery,\n { enabled: !!roleId },\n );\n const assignPermissions = hooks.useMutation(\n 'post',\n '/roles/{id}/permissions',\n {\n onSuccess: (result: { created?: number } | undefined) => {\n qc.invalidateQueries({ queryKey: ['get', '/roles'] });\n qc.invalidateQueries({ queryKey: ['get', '/roles/{id}'] });\n qc.invalidateQueries({ queryKey: ['get', '/roles/{id}/permissions'] });\n toast.success(\n result?.created\n ? `${result.created} permission(s) added`\n : 'No changes',\n );\n },\n onError: () => {\n toast.error('Failed to assign permissions');\n },\n },\n );\n const revokePermission = hooks.useMutation(\n 'delete',\n '/roles/{id}/permissions/{permissionId}',\n {\n onSuccess: () => {\n qc.invalidateQueries({ queryKey: ['get', '/roles'] });\n qc.invalidateQueries({ queryKey: ['get', '/roles/{id}'] });\n qc.invalidateQueries({\n queryKey: ['get', '/roles/{id}/permissions'],\n });\n toast.success('Permission removed');\n },\n onError: () => {\n toast.error('Failed to remove permission');\n },\n },\n );\n\n const permissions = (data?.permissions ?? []) as Permission[];\n const { total, pageCount } = useEntityPagination({\n items: permissions,\n total: data?.total,\n pageSize: params.pageSize,\n });\n const isLoading = isPending || isFetching;\n const currentView = (params.view || 'table') as 'table' | 'card';\n\n if (!roleId) {\n return null;\n }\n\n let content: ReactNode;\n if (isLoading) {\n content = (\n <EntityLoadingState\n view={currentView}\n rowCount={params.pageSize}\n columnCount={TABLE_COLUMN_COUNT}\n cardCount={params.pageSize}\n />\n );\n } else if (total === 0) {\n content = (\n <EntityEmptyState\n icon={IconKey}\n entityName=\"permission\"\n title=\"No permissions assigned\"\n description=\"Assign permissions from the selector to grant access to this role.\"\n />\n );\n } else if (currentView === 'table') {\n content = (\n <div className=\"space-y-4\">\n <DisplayTable withTableBorder>\n <Thead>\n <Tr>\n <Th>Permission</Th>\n <Th>Application</Th>\n <Th>Feature</Th>\n <Th className=\"w-[60px]\" />\n </Tr>\n </Thead>\n <Tbody>\n {permissions.map((permission) => (\n <Tr key={permission.id}>\n <Td>\n <div className=\"space-y-1\">\n <p className=\"font-medium\">{permission.activity}</p>\n <p className=\"font-mono text-xs text-muted-foreground\">\n {permission.id}\n </p>\n </div>\n </Td>\n <Td>\n <Badge variant=\"secondary\">{permission.application}</Badge>\n </Td>\n <Td>\n <Badge variant=\"outline\">{permission.feature}</Badge>\n </Td>\n <Td>\n <DeleteConfirmButton\n entityName=\"permission\"\n onConfirm={() =>\n revokePermission.mutate({\n params: {\n path: { id: roleId, permissionId: permission.id },\n },\n })\n }\n triggerClassName=\"size-8 text-destructive hover:text-destructive\"\n />\n </Td>\n </Tr>\n ))}\n </Tbody>\n </DisplayTable>\n <DataTablePagination\n pageIndex={params.page - 1}\n pageSize={params.pageSize}\n pageCount={pageCount}\n totalRows={total}\n onPageChange={(page) => setParams({ page: page + 1 })}\n onPageSizeChange={(pageSize) => setParams({ pageSize, page: 1 })}\n />\n </div>\n );\n } else {\n content = (\n <div className=\"space-y-4\">\n <div className=\"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3\">\n {permissions.map((permission) => (\n <div\n key={permission.id}\n className=\"rounded-xl border border-border/60 bg-card p-4 shadow-sm\"\n >\n <div className=\"flex items-start justify-between gap-3\">\n <div className=\"space-y-2\">\n <p className=\"font-semibold\">{permission.activity}</p>\n <div className=\"flex flex-wrap gap-2\">\n <Badge variant=\"secondary\">{permission.application}</Badge>\n <Badge variant=\"outline\">{permission.feature}</Badge>\n </div>\n <p className=\"font-mono text-xs text-muted-foreground\">\n {permission.id}\n </p>\n </div>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n onClick={() =>\n revokePermission.mutate({\n params: {\n path: { id: roleId, permissionId: permission.id },\n },\n })\n }\n disabled={revokePermission.isPending}\n >\n <IconTrash className=\"h-4 w-4\" />\n </Button>\n </div>\n </div>\n ))}\n </div>\n <DataTablePagination\n pageIndex={params.page - 1}\n pageSize={params.pageSize}\n pageCount={pageCount}\n totalRows={total}\n onPageChange={(page) => setParams({ page: page + 1 })}\n onPageSizeChange={(pageSize) => setParams({ pageSize, page: 1 })}\n />\n </div>\n );\n }\n\n return (\n <PageBody className=\"px-0 pb-6\">\n <EntityHeader\n icon={<IconKey className=\"h-5 w-5\" />}\n title=\"Role permissions\"\n actions={\n <PermissionSelector\n trigger={\n <Button size=\"sm\" loading={assignPermissions.isPending}>\n <IconPlus className=\"h-4 w-4\" />\n Add permissions\n </Button>\n }\n onSelect={(selectedPermissions) => {\n if (!selectedPermissions.length) {\n return;\n }\n\n assignPermissions.mutate({\n params: { path: { id: roleId } },\n body: {\n permissionIds: selectedPermissions.map(\n (permission) => permission.id,\n ),\n },\n });\n }}\n excludeIds={permissions.map((permission) => permission.id)}\n />\n }\n search={\n <EntitySearch\n paramKey=\"search\"\n placeholder=\"Search assigned permissions...\"\n />\n }\n filter={\n <EntityFilter\n options={[\n { label: 'All', value: '' },\n { label: 'Application', value: 'application' },\n { label: 'Feature', value: 'feature' },\n { label: 'Activity', value: 'activity' },\n ]}\n placeholder=\"Search field\"\n />\n }\n sort={\n <EntitySort\n defaultSort=\"application\"\n defaultOrder=\"asc\"\n options={[\n { label: 'ID', value: 'id' },\n { label: 'Application', value: 'application' },\n { label: 'Feature', value: 'feature' },\n { label: 'Activity', value: 'activity' },\n ]}\n />\n }\n view={<EntityViewToggle views={['table', 'card']} />}\n />\n {content}\n </PageBody>\n );\n}\n","'use client';\n\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { deepmerge } from 'deepmerge-ts';\nimport createFetchClient from 'openapi-fetch';\nimport createClient from 'openapi-react-query';\nimport type { ReactNode } from 'react';\nimport { createContext, useContext, useMemo, useState } from 'react';\nimport type { paths } from './data/openapi';\nimport { createTranslator } from './lib/translations';\nimport {\n type AuthClientConfig,\n type AuthResponse,\n defaultAuthClientConfig,\n type Session,\n type User,\n} from './types';\nimport { getSessionCookieName } from './utils/cookie';\nimport { createCustomFetch } from './utils/custom-fetch';\n\n// biome-ignore lint/suspicious/noExplicitAny: OpenAPI hooks type\ntype OpenApiHooks = any;\n\n// --- Utility: Check if running on server ---\nfunction isServer(): boolean {\n return typeof document === 'undefined';\n}\n\n/**\n * @deprecated Cookie is httpOnly and cannot be read client-side.\n * Use `useSession().isAuthenticated` instead.\n * This function always returns false on client.\n */\nexport function hasAuthCookie(_cookieName: string): boolean {\n // Cookie is httpOnly, can't check client-side\n // Always return false - use useSession() for auth status\n return false;\n}\n\n// --- Types ---\nexport type AuthStatus = 'loading' | 'authenticated' | 'unauthenticated';\n\ntype AuthState = {\n user: User | null;\n session: Session | null;\n status: AuthStatus;\n error: Error | null;\n};\n\ntype SessionContextValue = AuthState & {\n isLoading: boolean;\n isAuthenticated: boolean;\n refresh: () => Promise<void>;\n signOut: () => Promise<void>;\n};\n\ntype ApiContextValue = {\n hooks: OpenApiHooks;\n setAuth: (auth: AuthResponse) => void;\n clearAuth: () => void;\n refresh: () => Promise<void>;\n};\n\ntype ConfigContextValue = {\n config: AuthClientConfig;\n cookieName: string;\n t: (key: string, params?: Record<string, string | number>) => string;\n};\n\nconst SessionContext = createContext<SessionContextValue | null>(null);\nconst ApiContext = createContext<ApiContextValue | null>(null);\nconst ConfigContext = createContext<ConfigContextValue | null>(null);\n\nconst queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n refetchOnWindowFocus: false,\n },\n },\n});\n\n// --- Hooks ---\n\n/**\n * Get session state including user, session, and auth status.\n * - `status`: 'loading' | 'authenticated' | 'unauthenticated'\n * - `isLoading`: true while fetching session\n * - `isAuthenticated`: true if user and session exist\n */\nexport function useSession(): SessionContextValue {\n const context = useContext(SessionContext);\n if (!context) {\n throw new Error('useSession must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useApi(): ApiContextValue {\n const context = useContext(ApiContext);\n if (!context) {\n throw new Error('useApi must be used within MesobAuthProvider');\n }\n return context;\n}\n\nexport function useConfig(): ConfigContextValue {\n const context = useContext(ConfigContext);\n if (!context) {\n throw new Error('useConfig must be used within MesobAuthProvider');\n }\n return context;\n}\n\n/**\n * @deprecated Cookie is httpOnly, can't be checked client-side.\n * Use `useSession().isAuthenticated` instead.\n */\nexport function useHasAuthCookie(): boolean {\n const { status } = useSession();\n return status === 'authenticated' || status === 'loading';\n}\n\n// --- Provider ---\n\ntype MesobAuthProviderProps = {\n config: AuthClientConfig;\n children: ReactNode;\n};\n\nexport function MesobAuthProvider({\n config,\n children,\n}: MesobAuthProviderProps) {\n const mergedConfig = useMemo(\n () =>\n deepmerge(\n { ...defaultAuthClientConfig } as Partial<AuthClientConfig>,\n config,\n ) as AuthClientConfig,\n [config],\n );\n\n const api = useMemo(\n () =>\n createFetchClient<paths>({\n baseUrl: mergedConfig.baseURL,\n fetch: createCustomFetch(mergedConfig),\n }),\n [mergedConfig],\n );\n\n const hooks = useMemo(() => createClient(api), [api]);\n const cookieName = useMemo(\n () => getSessionCookieName(mergedConfig),\n [mergedConfig],\n );\n\n return (\n <QueryClientProvider client={queryClient}>\n <AuthStateProvider\n config={mergedConfig}\n hooks={hooks}\n cookieName={cookieName}\n >\n {children}\n </AuthStateProvider>\n </QueryClientProvider>\n );\n}\n\ntype AuthStateProviderProps = {\n config: AuthClientConfig;\n hooks: OpenApiHooks;\n cookieName: string;\n children: ReactNode;\n};\n\nfunction AuthStateProvider({\n config,\n hooks,\n cookieName,\n children,\n}: AuthStateProviderProps) {\n // Manual override for sign-out / sign-in\n const [override, setOverride] = useState<AuthState | null>(null);\n\n // Always fetch session - cookie is httpOnly, can't check client-side\n // Server will read the cookie and return user/session if valid\n const {\n data: sessionData,\n isLoading,\n isFetched,\n error: sessionError,\n refetch,\n } = hooks.useQuery(\n 'get',\n '/session',\n {},\n {\n enabled: !(override || isServer()),\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n retry: false,\n gcTime: 0,\n staleTime: 0,\n },\n );\n\n // Derive state directly - no useEffect\n const user = override?.user ?? sessionData?.user ?? null;\n const session = override?.session ?? sessionData?.session ?? null;\n const error = override?.error ?? (sessionError as Error | null);\n\n // Check error status code\n const errorStatus = (() => {\n if (!sessionError) {\n return null;\n }\n const err = sessionError as { status?: number };\n return err.status ?? null;\n })();\n\n // Check if error is a network/connection error\n const isNetworkError = (() => {\n if (!sessionError) {\n return false;\n }\n const error = sessionError as Error & { cause?: unknown; data?: unknown };\n const errorMessage =\n error.message || String(error) || JSON.stringify(error);\n // Network errors: TypeError, DOMException, or fetch failures\n if (\n error instanceof TypeError ||\n error instanceof DOMException ||\n error.name === 'TypeError' ||\n errorMessage.includes('Failed to fetch') ||\n errorMessage.includes('ERR_CONNECTION_REFUSED') ||\n errorMessage.includes('NetworkError') ||\n errorMessage.includes('Network request failed') ||\n errorMessage.includes('fetch failed')\n ) {\n return true;\n }\n // Check error cause\n if (error.cause) {\n const causeStr = String(error.cause);\n if (\n causeStr.includes('Failed to fetch') ||\n causeStr.includes('ERR_CONNECTION_REFUSED') ||\n causeStr.includes('NetworkError')\n ) {\n return true;\n }\n }\n return false;\n })();\n\n // Compute status\n // biome-ignore lint: Status determination requires multiple checks\n const status: AuthStatus = (() => {\n if (override) {\n return override.status;\n }\n if (isServer()) {\n return 'loading';\n }\n if (user && session) {\n return 'authenticated';\n }\n // Check for network errors or auth errors first - allow auth page to show\n if (isNetworkError || errorStatus === 401) {\n return 'unauthenticated';\n }\n // If we have an error but it's not a network error, still check loading state\n if (sessionError && !isNetworkError && errorStatus !== 401) {\n if (errorStatus && errorStatus >= 500) {\n return 'authenticated';\n }\n // Other errors mean unauthenticated\n if (isFetched) {\n return 'unauthenticated';\n }\n }\n if (isLoading || !isFetched) {\n return 'loading';\n }\n if (isFetched && !user && !session) {\n return 'unauthenticated';\n }\n return 'unauthenticated';\n })();\n\n const signOutMutation = hooks.useMutation('post', '/sign-out');\n const t = createTranslator(config.messages || {});\n\n const setAuth = (auth: AuthResponse) => {\n setOverride({\n user: auth.user,\n session: auth.session,\n status: 'authenticated',\n error: null,\n });\n };\n\n const clearAuth = () => {\n setOverride({\n user: null,\n session: null,\n status: 'unauthenticated',\n error: null,\n });\n };\n\n const refresh = async () => {\n setOverride(null);\n await refetch();\n };\n\n const signOut = async () => {\n try {\n await signOutMutation.mutateAsync({});\n } finally {\n clearAuth();\n }\n };\n\n return (\n <ConfigContext.Provider value={{ config, cookieName, t }}>\n <ApiContext.Provider value={{ hooks, setAuth, clearAuth, refresh }}>\n <SessionContext.Provider\n value={{\n user,\n session,\n status,\n error,\n isLoading: status === 'loading',\n isAuthenticated: status === 'authenticated',\n refresh,\n signOut,\n }}\n >\n {children}\n </SessionContext.Provider>\n </ApiContext.Provider>\n </ConfigContext.Provider>\n );\n}\n","import type { AuthClientConfig } from '../types';\n\nconst isProduction =\n typeof process !== 'undefined' && process.env.NODE_ENV === 'production';\n\nexport const getSessionCookieName = (config: AuthClientConfig): string => {\n const prefix = config.cookiePrefix || '';\n const baseName = 'session_token';\n if (prefix) {\n return `${prefix}_${baseName}`;\n }\n return isProduction ? '__Host-session_token' : baseName;\n};\n","'use client';\n\nimport {\n Badge,\n EntitySelector,\n type EntitySelectorColumn,\n type EntitySelectorConfig,\n useEntitySectionState,\n} from '@mesob/ui/components';\nimport { IconKey } from '@tabler/icons-react';\nimport type { ReactNode } from 'react';\nimport type { paths } from '../../data/openapi';\nimport { useApi } from '../../provider';\n\ntype Permission = {\n id: string;\n description?: unknown;\n activity: string;\n application: string;\n feature: string;\n};\n\nconst permissionColumns: EntitySelectorColumn<Permission>[] = [\n {\n key: 'permission',\n header: 'Permission',\n cell: (permission) => (\n <div className=\"space-y-1\">\n <p className=\"font-medium\">{permission.activity}</p>\n <p className=\"font-mono text-xs text-muted-foreground\">\n {permission.id}\n </p>\n </div>\n ),\n },\n {\n key: 'scope',\n header: 'Scope',\n cell: (permission) => (\n <div className=\"flex flex-wrap gap-2\">\n <Badge variant=\"secondary\">{permission.application}</Badge>\n <Badge variant=\"outline\">{permission.feature}</Badge>\n </div>\n ),\n },\n];\n\ntype PermissionSelectorProps = {\n trigger: ReactNode;\n multiple?: boolean;\n onSelect: (permissions: Permission[]) => void;\n excludeIds?: string[];\n};\n\nexport function PermissionSelector({\n trigger,\n multiple = true,\n onSelect,\n excludeIds = [],\n}: PermissionSelectorProps) {\n const { hooks } = useApi();\n const state = useEntitySectionState({\n defaultSort: 'id',\n defaultOrder: 'asc',\n defaultPageSize: 10,\n searchParamName: 'search',\n });\n const permissionsQuery = state.queryConfig as {\n params: {\n query: NonNullable<paths['/permissions']['get']['parameters']['query']>;\n };\n };\n\n const { data, isPending, isFetching } = hooks.useQuery(\n 'get',\n '/permissions',\n permissionsQuery,\n );\n\n const items = ((data?.permissions ?? []) as Permission[]).filter(\n (permission) => !excludeIds.includes(permission.id),\n );\n\n const config: EntitySelectorConfig<Permission> = {\n title: 'Select permission(s)',\n multiple,\n entityName: 'permission',\n entityIcon: IconKey,\n columns: permissionColumns,\n getItemLabel: (permission) => permission.id,\n searchPlaceholder: 'Search permissions...',\n filterOptions: [\n { label: 'All', value: '' },\n { label: 'Application', value: 'application' },\n { label: 'Feature', value: 'feature' },\n { label: 'Activity', value: 'activity' },\n ],\n sortOptions: [\n { label: 'ID', value: 'id' },\n { label: 'Application', value: 'application' },\n { label: 'Feature', value: 'feature' },\n { label: 'Activity', value: 'activity' },\n ],\n showViewToggle: false,\n wrapHeaderInCard: false,\n };\n\n return (\n <EntitySelector<Permission>\n trigger={trigger}\n config={config}\n onSelect={onSelect}\n items={items}\n total={items.length}\n isLoading={isPending || isFetching}\n state={state}\n />\n );\n}\n"],"mappings":";;;AAEA;AAAA,EACE,SAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,E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A,QACF;AAAA,QAEF,MAAM,gBAAAA,KAAC,oBAAiB,OAAO,CAAC,SAAS,MAAM,GAAG;AAAA;AAAA,IACpD;AAAA,IACC;AAAA,KACH;AAEJ;","names":["Badge","IconKey","useMemo","jsx","jsx","jsxs","useMemo","IconKey","Badge"]}
@@ -152,9 +152,15 @@ function Roles() {
152
152
  ] })
153
153
  },
154
154
  {
155
- key: "description",
156
- header: "Description",
157
- cell: (role) => /* @__PURE__ */ jsx4("p", { className: "text-sm text-muted-foreground", children: getTranslation(role.description, locale) })
155
+ key: "access",
156
+ header: "Access",
157
+ cell: (role) => /* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap gap-2", children: [
158
+ role.isSystem ? /* @__PURE__ */ jsx4(Badge, { children: "System" }) : null,
159
+ /* @__PURE__ */ jsxs3(Badge, { variant: "secondary", children: [
160
+ role.permissionCount ?? 0,
161
+ " permissions"
162
+ ] })
163
+ ] })
158
164
  },
159
165
  {
160
166
  key: "createdAt",
@@ -164,10 +170,7 @@ function Roles() {
164
170
  {
165
171
  key: "actions",
166
172
  header: "Actions",
167
- cell: (_role) => /* @__PURE__ */ jsxs3("div", { className: "flex gap-2", children: [
168
- /* @__PURE__ */ jsx4(Button, { variant: "outline", size: "sm", children: "Permissions" }),
169
- /* @__PURE__ */ jsx4(Button, { variant: "outline", size: "sm", children: "Edit" })
170
- ] })
173
+ cell: (_role) => /* @__PURE__ */ jsx4("div", { className: "flex gap-2", children: /* @__PURE__ */ jsx4(Button, { variant: "outline", size: "sm", children: "Edit" }) })
171
174
  }
172
175
  ];
173
176
  if (error) {
@@ -177,7 +180,7 @@ function Roles() {
177
180
  /* @__PURE__ */ jsxs3("div", { className: "flex justify-between items-center", children: [
178
181
  /* @__PURE__ */ jsxs3("div", { children: [
179
182
  /* @__PURE__ */ jsx4("h1", { className: "text-3xl font-bold", children: "Roles" }),
180
- /* @__PURE__ */ jsx4("p", { className: "text-muted-foreground", children: "Manage user roles" })
183
+ /* @__PURE__ */ jsx4("p", { className: "text-muted-foreground", children: "Manage roles and assigned permissions" })
181
184
  ] }),
182
185
  /* @__PURE__ */ jsx4(Button, { children: "Create Role" })
183
186
  ] }),
@@ -196,7 +199,7 @@ function Roles() {
196
199
  {
197
200
  variant: "outline",
198
201
  disabled: page === 1,
199
- onClick: () => setPage(page - 1),
202
+ onClick: () => setPage((prev) => prev - 1),
200
203
  children: "Previous"
201
204
  }
202
205
  ),
@@ -204,7 +207,14 @@ function Roles() {
204
207
  "Page ",
205
208
  page
206
209
  ] }),
207
- /* @__PURE__ */ jsx4(Button, { variant: "outline", onClick: () => setPage(page + 1), children: "Next" })
210
+ /* @__PURE__ */ jsx4(
211
+ Button,
212
+ {
213
+ variant: "outline",
214
+ onClick: () => setPage((prev) => prev + 1),
215
+ children: "Next"
216
+ }
217
+ )
208
218
  ] })
209
219
  ] });
210
220
  }