@mesob/auth-react 0.3.5 → 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.
- package/dist/components/auth/forgot-password.js +5 -1
- package/dist/components/auth/forgot-password.js.map +1 -1
- package/dist/components/auth/reset-password-form.js +5 -1
- package/dist/components/auth/reset-password-form.js.map +1 -1
- package/dist/components/auth/set-password.d.ts +9 -0
- package/dist/components/auth/set-password.js +527 -0
- package/dist/components/auth/set-password.js.map +1 -0
- package/dist/components/auth/sign-in.js +22 -1
- package/dist/components/auth/sign-in.js.map +1 -1
- package/dist/components/auth/sign-up.js +7 -5
- package/dist/components/auth/sign-up.js.map +1 -1
- package/dist/components/auth/verify-email.js +5 -1
- package/dist/components/auth/verify-email.js.map +1 -1
- package/dist/components/auth/verify-phone.js +5 -1
- package/dist/components/auth/verify-phone.js.map +1 -1
- package/dist/components/authorization/deny.d.ts +11 -0
- package/dist/components/authorization/deny.js +52 -0
- package/dist/components/authorization/deny.js.map +1 -0
- package/dist/components/authorization/grant.d.ts +12 -0
- package/dist/components/authorization/grant.js +57 -0
- package/dist/components/authorization/grant.js.map +1 -0
- package/dist/components/error-boundary.d.ts +2 -2
- package/dist/components/iam/permission-selector.d.ts +19 -0
- package/dist/components/iam/permission-selector.js +122 -0
- package/dist/components/iam/permission-selector.js.map +1 -0
- package/dist/components/iam/permissions.js +12 -31
- package/dist/components/iam/permissions.js.map +1 -1
- package/dist/components/iam/role-detail-layout.d.ts +11 -0
- package/dist/components/iam/role-detail-layout.js +137 -0
- package/dist/components/iam/role-detail-layout.js.map +1 -0
- package/dist/components/iam/role-detail-page.d.ts +9 -0
- package/dist/components/iam/role-detail-page.js +229 -0
- package/dist/components/iam/role-detail-page.js.map +1 -0
- package/dist/components/iam/role-permissions-page.d.ts +8 -0
- package/dist/components/iam/role-permissions-page.js +397 -0
- package/dist/components/iam/role-permissions-page.js.map +1 -0
- package/dist/components/iam/roles.js +11 -8
- package/dist/components/iam/roles.js.map +1 -1
- package/dist/components/iam/users.js +1 -7
- package/dist/components/iam/users.js.map +1 -1
- package/dist/components/profile/account.js +110 -19
- package/dist/components/profile/account.js.map +1 -1
- package/dist/components/profile/change-profile.d.ts +2 -1
- package/dist/components/profile/change-profile.js +16 -8
- package/dist/components/profile/change-profile.js.map +1 -1
- package/dist/components/profile/security.js +51 -17
- package/dist/components/profile/security.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +1813 -725
- package/dist/index.js.map +1 -1
- package/dist/pages/auth/forgot-password.d.ts +7 -0
- package/dist/pages/auth/forgot-password.js +784 -0
- package/dist/pages/auth/forgot-password.js.map +1 -0
- package/dist/pages/auth/layout.d.ts +8 -0
- package/dist/pages/auth/layout.js +562 -0
- package/dist/pages/auth/layout.js.map +1 -0
- package/dist/pages/auth/reset-password.d.ts +10 -0
- package/dist/pages/auth/reset-password.js +913 -0
- package/dist/pages/auth/reset-password.js.map +1 -0
- package/dist/pages/auth/set-password.d.ts +10 -0
- package/dist/pages/auth/set-password.js +946 -0
- package/dist/pages/auth/set-password.js.map +1 -0
- package/dist/pages/auth/sign-in.d.ts +10 -0
- package/dist/pages/auth/sign-in.js +984 -0
- package/dist/pages/auth/sign-in.js.map +1 -0
- package/dist/pages/auth/sign-up.d.ts +10 -0
- package/dist/pages/auth/sign-up.js +940 -0
- package/dist/pages/auth/sign-up.js.map +1 -0
- package/dist/pages/auth/verify-email.d.ts +10 -0
- package/dist/pages/auth/verify-email.js +950 -0
- package/dist/pages/auth/verify-email.js.map +1 -0
- package/dist/pages/auth/verify-phone.d.ts +10 -0
- package/dist/pages/auth/verify-phone.js +964 -0
- package/dist/pages/auth/verify-phone.js.map +1 -0
- package/dist/pages/iam/permissions.d.ts +5 -0
- package/dist/pages/iam/permissions.js +308 -0
- package/dist/pages/iam/permissions.js.map +1 -0
- package/dist/pages/iam/role-detail-layout.d.ts +12 -0
- package/dist/pages/iam/role-detail-layout.js +145 -0
- package/dist/pages/iam/role-detail-layout.js.map +1 -0
- package/dist/pages/iam/role-detail.d.ts +12 -0
- package/dist/pages/iam/role-detail.js +241 -0
- package/dist/pages/iam/role-detail.js.map +1 -0
- package/dist/pages/iam/role-permissions.d.ts +12 -0
- package/dist/pages/iam/role-permissions.js +409 -0
- package/dist/pages/iam/role-permissions.js.map +1 -0
- package/dist/pages/iam/role-users.d.ts +12 -0
- package/dist/pages/iam/role-users.js +825 -0
- package/dist/pages/iam/role-users.js.map +1 -0
- package/dist/pages/iam/roles.d.ts +5 -0
- package/dist/pages/iam/roles.js +684 -0
- package/dist/pages/iam/roles.js.map +1 -0
- package/dist/pages/iam/sessions.d.ts +5 -0
- package/dist/pages/iam/sessions.js +315 -0
- package/dist/pages/iam/sessions.js.map +1 -0
- package/dist/pages/iam/tenant-detail.d.ts +10 -0
- package/dist/pages/iam/tenant-detail.js +186 -0
- package/dist/pages/iam/tenant-detail.js.map +1 -0
- package/dist/pages/iam/tenants.d.ts +5 -0
- package/dist/pages/iam/tenants.js +610 -0
- package/dist/pages/iam/tenants.js.map +1 -0
- package/dist/pages/iam/user-activity.d.ts +10 -0
- package/dist/pages/iam/user-activity.js +850 -0
- package/dist/pages/iam/user-activity.js.map +1 -0
- package/dist/pages/iam/user-detail-layout.d.ts +12 -0
- package/dist/pages/iam/user-detail-layout.js +106 -0
- package/dist/pages/iam/user-detail-layout.js.map +1 -0
- package/dist/pages/iam/user-detail.d.ts +10 -0
- package/dist/pages/iam/user-detail.js +102 -0
- package/dist/pages/iam/user-detail.js.map +1 -0
- package/dist/pages/iam/users.d.ts +5 -0
- package/dist/pages/iam/users.js +1275 -0
- package/dist/pages/iam/users.js.map +1 -0
- package/dist/pages/profile/account.d.ts +5 -0
- package/dist/pages/profile/account.js +182 -0
- package/dist/pages/profile/account.js.map +1 -0
- package/dist/pages/profile/layout.d.ts +8 -0
- package/dist/pages/profile/layout.js +133 -0
- package/dist/pages/profile/layout.js.map +1 -0
- package/dist/pages/profile/security.d.ts +5 -0
- package/dist/pages/profile/security.js +1539 -0
- package/dist/pages/profile/security.js.map +1 -0
- package/dist/{types-vcfvnAzQ.d.ts → types-g9QcNRxT.d.ts} +13 -7
- package/package.json +102 -3
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/iam/role-detail-page.tsx
|
|
4
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
5
|
+
import {
|
|
6
|
+
EntityFormActions,
|
|
7
|
+
Form,
|
|
8
|
+
FormControl,
|
|
9
|
+
FormField,
|
|
10
|
+
FormItem,
|
|
11
|
+
FormLabel,
|
|
12
|
+
FormMessage,
|
|
13
|
+
Input,
|
|
14
|
+
LocaleInputText,
|
|
15
|
+
LocaleInputTextarea,
|
|
16
|
+
Section,
|
|
17
|
+
Skeleton
|
|
18
|
+
} from "@mesob/ui/components";
|
|
19
|
+
import { useLocaleSchemas } from "@mesob/ui/providers";
|
|
20
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
21
|
+
import { useEffect, useMemo as useMemo2 } from "react";
|
|
22
|
+
import { useForm } from "react-hook-form";
|
|
23
|
+
import { toast } from "sonner";
|
|
24
|
+
import { z } from "zod";
|
|
25
|
+
|
|
26
|
+
// src/provider.tsx
|
|
27
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
28
|
+
import { deepmerge } from "deepmerge-ts";
|
|
29
|
+
import createFetchClient from "openapi-fetch";
|
|
30
|
+
import createClient from "openapi-react-query";
|
|
31
|
+
import { createContext, useContext, useMemo, useState } from "react";
|
|
32
|
+
|
|
33
|
+
// src/utils/cookie.ts
|
|
34
|
+
var isProduction = typeof process !== "undefined" && process.env.NODE_ENV === "production";
|
|
35
|
+
|
|
36
|
+
// src/provider.tsx
|
|
37
|
+
import { jsx } from "react/jsx-runtime";
|
|
38
|
+
var SessionContext = createContext(null);
|
|
39
|
+
var ApiContext = createContext(null);
|
|
40
|
+
var ConfigContext = createContext(null);
|
|
41
|
+
var queryClient = new QueryClient({
|
|
42
|
+
defaultOptions: {
|
|
43
|
+
queries: {
|
|
44
|
+
refetchOnWindowFocus: false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
function useApi() {
|
|
49
|
+
const context = useContext(ApiContext);
|
|
50
|
+
if (!context) {
|
|
51
|
+
throw new Error("useApi must be used within MesobAuthProvider");
|
|
52
|
+
}
|
|
53
|
+
return context;
|
|
54
|
+
}
|
|
55
|
+
function useConfig() {
|
|
56
|
+
const context = useContext(ConfigContext);
|
|
57
|
+
if (!context) {
|
|
58
|
+
throw new Error("useConfig must be used within MesobAuthProvider");
|
|
59
|
+
}
|
|
60
|
+
return context;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// src/components/iam/role-detail-page.tsx
|
|
64
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
65
|
+
function RoleDetailPage({
|
|
66
|
+
roleId,
|
|
67
|
+
basePath = "/iam/roles"
|
|
68
|
+
}) {
|
|
69
|
+
const { hooks } = useApi();
|
|
70
|
+
const { config } = useConfig();
|
|
71
|
+
const qc = useQueryClient();
|
|
72
|
+
const { localeInputDefault, requiredSchema, optionalSchema } = useLocaleSchemas();
|
|
73
|
+
const schema = useMemo2(
|
|
74
|
+
() => z.object({
|
|
75
|
+
name: requiredSchema,
|
|
76
|
+
code: z.string().min(1, "Code is required"),
|
|
77
|
+
description: optionalSchema
|
|
78
|
+
}),
|
|
79
|
+
[requiredSchema, optionalSchema]
|
|
80
|
+
);
|
|
81
|
+
const defaults = useMemo2(
|
|
82
|
+
() => ({
|
|
83
|
+
name: { ...localeInputDefault },
|
|
84
|
+
code: "",
|
|
85
|
+
description: { ...localeInputDefault }
|
|
86
|
+
}),
|
|
87
|
+
[localeInputDefault]
|
|
88
|
+
);
|
|
89
|
+
const { data, isLoading } = hooks.useQuery(
|
|
90
|
+
"get",
|
|
91
|
+
"/roles/{id}",
|
|
92
|
+
{ params: { path: { id: roleId } } },
|
|
93
|
+
{ enabled: !!roleId }
|
|
94
|
+
);
|
|
95
|
+
const update = hooks.useMutation("put", "/roles/{id}", {
|
|
96
|
+
onSuccess: () => {
|
|
97
|
+
qc.invalidateQueries({ queryKey: ["get", "/roles"] });
|
|
98
|
+
qc.invalidateQueries({ queryKey: ["get", "/roles/{id}"] });
|
|
99
|
+
toast.success("Role updated");
|
|
100
|
+
},
|
|
101
|
+
onError: () => {
|
|
102
|
+
toast.error("Failed to update role");
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const remove = hooks.useMutation("delete", "/roles/{id}", {
|
|
106
|
+
onSuccess: () => {
|
|
107
|
+
qc.invalidateQueries({ queryKey: ["get", "/roles"] });
|
|
108
|
+
toast.success("Role deleted");
|
|
109
|
+
config.navigation?.onNavigate?.(basePath);
|
|
110
|
+
},
|
|
111
|
+
onError: () => {
|
|
112
|
+
toast.error("Failed to delete role");
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
const form = useForm({
|
|
116
|
+
resolver: zodResolver(schema),
|
|
117
|
+
defaultValues: defaults
|
|
118
|
+
});
|
|
119
|
+
const { reset, formState, control, register } = form;
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (!data?.role) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const r = data.role;
|
|
125
|
+
reset({
|
|
126
|
+
name: r.name ?? {},
|
|
127
|
+
code: r.code,
|
|
128
|
+
description: r.description ?? {}
|
|
129
|
+
});
|
|
130
|
+
}, [data?.role, reset]);
|
|
131
|
+
if (!roleId) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const role = data?.role;
|
|
135
|
+
const editable = role?.isEditable !== false;
|
|
136
|
+
const deletable = role?.isDeletable !== false;
|
|
137
|
+
const onSubmit = form.handleSubmit(async (d) => {
|
|
138
|
+
await update.mutateAsync({
|
|
139
|
+
params: { path: { id: roleId } },
|
|
140
|
+
body: {
|
|
141
|
+
name: d.name,
|
|
142
|
+
code: d.code,
|
|
143
|
+
description: d.description ?? void 0
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
const footer = role ? /* @__PURE__ */ jsx2(
|
|
148
|
+
EntityFormActions,
|
|
149
|
+
{
|
|
150
|
+
mode: "edit",
|
|
151
|
+
onSubmit,
|
|
152
|
+
onDelete: deletable ? () => remove.mutate({
|
|
153
|
+
params: { path: { id: roleId } }
|
|
154
|
+
}) : void 0,
|
|
155
|
+
isSubmitting: update.isPending,
|
|
156
|
+
isDeleting: remove.isPending,
|
|
157
|
+
disabled: !editable,
|
|
158
|
+
itemName: "role"
|
|
159
|
+
}
|
|
160
|
+
) : null;
|
|
161
|
+
return /* @__PURE__ */ jsx2(Section, { title: "Role details", footer, defaultOpen: true, children: isLoading || !role ? /* @__PURE__ */ jsx2(RoleDetailSkeleton, {}) : /* @__PURE__ */ jsx2(Form, { ...form, children: /* @__PURE__ */ jsxs("form", { onSubmit, className: "space-y-4", children: [
|
|
162
|
+
/* @__PURE__ */ jsx2(
|
|
163
|
+
LocaleInputText,
|
|
164
|
+
{
|
|
165
|
+
label: "Name",
|
|
166
|
+
field: "name",
|
|
167
|
+
required: true,
|
|
168
|
+
register,
|
|
169
|
+
errors: formState.errors,
|
|
170
|
+
placeholder: "e.g. Administrator",
|
|
171
|
+
disabled: !editable
|
|
172
|
+
}
|
|
173
|
+
),
|
|
174
|
+
/* @__PURE__ */ jsx2(
|
|
175
|
+
FormField,
|
|
176
|
+
{
|
|
177
|
+
control,
|
|
178
|
+
name: "code",
|
|
179
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
|
|
180
|
+
/* @__PURE__ */ jsxs(FormLabel, { children: [
|
|
181
|
+
"Code ",
|
|
182
|
+
/* @__PURE__ */ jsx2("span", { className: "text-destructive", children: "*" })
|
|
183
|
+
] }),
|
|
184
|
+
/* @__PURE__ */ jsx2(FormControl, { children: /* @__PURE__ */ jsx2(
|
|
185
|
+
Input,
|
|
186
|
+
{
|
|
187
|
+
placeholder: "e.g. admin",
|
|
188
|
+
disabled: !editable,
|
|
189
|
+
...field
|
|
190
|
+
}
|
|
191
|
+
) }),
|
|
192
|
+
/* @__PURE__ */ jsx2(FormMessage, {})
|
|
193
|
+
] })
|
|
194
|
+
}
|
|
195
|
+
),
|
|
196
|
+
/* @__PURE__ */ jsx2(
|
|
197
|
+
LocaleInputTextarea,
|
|
198
|
+
{
|
|
199
|
+
label: "Description",
|
|
200
|
+
field: "description",
|
|
201
|
+
register,
|
|
202
|
+
errors: formState.errors,
|
|
203
|
+
placeholder: "Description",
|
|
204
|
+
rows: 3,
|
|
205
|
+
disabled: !editable
|
|
206
|
+
}
|
|
207
|
+
)
|
|
208
|
+
] }) }) });
|
|
209
|
+
}
|
|
210
|
+
function RoleDetailSkeleton() {
|
|
211
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
212
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
213
|
+
/* @__PURE__ */ jsx2(Skeleton, { className: "h-4 w-16" }),
|
|
214
|
+
/* @__PURE__ */ jsx2(Skeleton, { className: "h-10 w-full" })
|
|
215
|
+
] }),
|
|
216
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
217
|
+
/* @__PURE__ */ jsx2(Skeleton, { className: "h-4 w-14" }),
|
|
218
|
+
/* @__PURE__ */ jsx2(Skeleton, { className: "h-10 w-full" })
|
|
219
|
+
] }),
|
|
220
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
221
|
+
/* @__PURE__ */ jsx2(Skeleton, { className: "h-4 w-24" }),
|
|
222
|
+
/* @__PURE__ */ jsx2(Skeleton, { className: "h-20 w-full" })
|
|
223
|
+
] })
|
|
224
|
+
] });
|
|
225
|
+
}
|
|
226
|
+
export {
|
|
227
|
+
RoleDetailPage
|
|
228
|
+
};
|
|
229
|
+
//# sourceMappingURL=role-detail-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/iam/role-detail-page.tsx","../../../src/provider.tsx","../../../src/utils/cookie.ts"],"sourcesContent":["'use client';\n\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport {\n EntityFormActions,\n Form,\n FormControl,\n FormField,\n FormItem,\n FormLabel,\n FormMessage,\n Input,\n LocaleInputText,\n LocaleInputTextarea,\n Section,\n Skeleton,\n} from '@mesob/ui/components';\nimport { useLocaleSchemas } from '@mesob/ui/providers';\nimport { useQueryClient } from '@tanstack/react-query';\nimport { useEffect, useMemo } from 'react';\nimport type { Resolver } from 'react-hook-form';\nimport { useForm } from 'react-hook-form';\nimport { toast } from 'sonner';\nimport { z } from 'zod';\nimport { useApi, useConfig } from '../../provider';\n\ntype RoleFormData = {\n name: Record<string, string>;\n code: string;\n description: Record<string, string>;\n};\n\ntype RoleDetailPageProps = {\n roleId: string;\n basePath?: string;\n};\n\nexport function RoleDetailPage({\n roleId,\n basePath = '/iam/roles',\n}: RoleDetailPageProps) {\n const { hooks } = useApi();\n const { config } = useConfig();\n const qc = useQueryClient();\n const { localeInputDefault, requiredSchema, optionalSchema } =\n useLocaleSchemas();\n const schema = useMemo(\n () =>\n z.object({\n name: requiredSchema,\n code: z.string().min(1, 'Code is required'),\n description: optionalSchema,\n }),\n [requiredSchema, optionalSchema],\n );\n const defaults: RoleFormData = useMemo(\n () => ({\n name: { ...localeInputDefault },\n code: '',\n description: { ...localeInputDefault },\n }),\n [localeInputDefault],\n );\n\n const { data, isLoading } = hooks.useQuery(\n 'get',\n '/roles/{id}',\n { params: { path: { id: roleId } } },\n { enabled: !!roleId },\n );\n\n const update = hooks.useMutation('put', '/roles/{id}', {\n onSuccess: () => {\n qc.invalidateQueries({ queryKey: ['get', '/roles'] });\n qc.invalidateQueries({ queryKey: ['get', '/roles/{id}'] });\n toast.success('Role updated');\n },\n onError: () => {\n toast.error('Failed to update role');\n },\n });\n const remove = hooks.useMutation('delete', '/roles/{id}', {\n onSuccess: () => {\n qc.invalidateQueries({ queryKey: ['get', '/roles'] });\n toast.success('Role deleted');\n config.navigation?.onNavigate?.(basePath);\n },\n onError: () => {\n toast.error('Failed to delete role');\n },\n });\n\n const form = useForm<RoleFormData>({\n resolver: zodResolver(schema) as Resolver<RoleFormData>,\n defaultValues: defaults,\n });\n\n const { reset, formState, control, register } = form;\n\n useEffect(() => {\n if (!data?.role) {\n return;\n }\n const r = data.role;\n reset({\n name: (r.name ?? {}) as RoleFormData['name'],\n code: r.code,\n description: (r.description ?? {}) as RoleFormData['description'],\n });\n }, [data?.role, reset]);\n\n if (!roleId) {\n return null;\n }\n\n const role = data?.role;\n const editable = role?.isEditable !== false;\n const deletable = role?.isDeletable !== false;\n const onSubmit = form.handleSubmit(async (d) => {\n await update.mutateAsync({\n params: { path: { id: roleId } },\n body: {\n name: d.name,\n code: d.code,\n description: d.description ?? undefined,\n },\n });\n });\n\n const footer = role ? (\n <EntityFormActions\n mode=\"edit\"\n onSubmit={onSubmit}\n onDelete={\n deletable\n ? () =>\n remove.mutate({\n params: { path: { id: roleId } },\n })\n : undefined\n }\n isSubmitting={update.isPending}\n isDeleting={remove.isPending}\n disabled={!editable}\n itemName=\"role\"\n />\n ) : null;\n\n return (\n <Section title=\"Role details\" footer={footer} defaultOpen>\n {isLoading || !role ? (\n <RoleDetailSkeleton />\n ) : (\n <Form {...form}>\n <form onSubmit={onSubmit} className=\"space-y-4\">\n <LocaleInputText\n label=\"Name\"\n field=\"name\"\n required\n register={register}\n errors={formState.errors}\n placeholder=\"e.g. Administrator\"\n disabled={!editable}\n />\n <FormField\n control={control}\n name=\"code\"\n render={({ field }) => (\n <FormItem>\n <FormLabel>\n Code <span className=\"text-destructive\">*</span>\n </FormLabel>\n <FormControl>\n <Input\n placeholder=\"e.g. admin\"\n disabled={!editable}\n {...field}\n />\n </FormControl>\n <FormMessage />\n </FormItem>\n )}\n />\n <LocaleInputTextarea\n label=\"Description\"\n field=\"description\"\n register={register}\n errors={formState.errors}\n placeholder=\"Description\"\n rows={3}\n disabled={!editable}\n />\n </form>\n </Form>\n )}\n </Section>\n );\n}\n\nfunction RoleDetailSkeleton() {\n return (\n <div className=\"space-y-4\">\n <div className=\"space-y-2\">\n <Skeleton className=\"h-4 w-16\" />\n <Skeleton className=\"h-10 w-full\" />\n </div>\n <div className=\"space-y-2\">\n <Skeleton className=\"h-4 w-14\" />\n <Skeleton className=\"h-10 w-full\" />\n </div>\n <div className=\"space-y-2\">\n <Skeleton className=\"h-4 w-24\" />\n <Skeleton className=\"h-20 w-full\" />\n </div>\n </div>\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"],"mappings":";;;AAEA,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B,SAAS,WAAW,WAAAA,gBAAe;AAEnC,SAAS,eAAe;AACxB,SAAS,aAAa;AACtB,SAAS,SAAS;;;ACrBlB,SAAS,aAAa,2BAA2B;AACjD,SAAS,iBAAiB;AAC1B,OAAO,uBAAuB;AAC9B,OAAO,kBAAkB;AAEzB,SAAS,eAAe,YAAY,SAAS,gBAAgB;;;ACL7D,IAAM,eACJ,OAAO,YAAY,eAAe,QAAQ,IAAI,aAAa;;;AD4JvD;AA1FN,IAAM,iBAAiB,cAA0C,IAAI;AACrE,IAAM,aAAa,cAAsC,IAAI;AAC7D,IAAM,gBAAgB,cAAyC,IAAI;AAEnE,IAAM,cAAc,IAAI,YAAY;AAAA,EAClC,gBAAgB;AAAA,IACd,SAAS;AAAA,MACP,sBAAsB;AAAA,IACxB;AAAA,EACF;AACF,CAAC;AAkBM,SAAS,SAA0B;AACxC,QAAM,UAAU,WAAW,UAAU;AACrC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AACA,SAAO;AACT;AAEO,SAAS,YAAgC;AAC9C,QAAM,UAAU,WAAW,aAAa;AACxC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,iDAAiD;AAAA,EACnE;AACA,SAAO;AACT;;;ADmBI,gBAAAC,MAuCc,YAvCd;AA7FG,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA,WAAW;AACb,GAAwB;AACtB,QAAM,EAAE,MAAM,IAAI,O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sBAAAA,KAAC,YAAS,WAAU,YAAW;AAAA,MAC/B,gBAAAA,KAAC,YAAS,WAAU,eAAc;AAAA,OACpC;AAAA,KACF;AAEJ;","names":["useMemo","jsx","useMemo"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
type RolePermissionsPageProps = {
|
|
4
|
+
roleId: string;
|
|
5
|
+
};
|
|
6
|
+
declare function RolePermissionsPage({ roleId }: RolePermissionsPageProps): react_jsx_runtime.JSX.Element | null;
|
|
7
|
+
|
|
8
|
+
export { RolePermissionsPage };
|
|
@@ -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
|