@open-kingdom/shared-frontend-feature-user-management 0.0.2-9
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/.babelrc +12 -0
- package/README.md +7 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +538 -0
- package/dist/lib/components/invitations/AcceptInvitation.component.d.ts +7 -0
- package/dist/lib/components/invitations/AcceptInvitation.component.d.ts.map +1 -0
- package/dist/lib/components/invitations/InviteUserModal.component.d.ts +7 -0
- package/dist/lib/components/invitations/InviteUserModal.component.d.ts.map +1 -0
- package/dist/lib/components/invitations/index.d.ts +3 -0
- package/dist/lib/components/invitations/index.d.ts.map +1 -0
- package/dist/lib/components/shared/ConfirmDialog.component.d.ts +12 -0
- package/dist/lib/components/shared/ConfirmDialog.component.d.ts.map +1 -0
- package/dist/lib/components/shared/FormField.component.d.ts +10 -0
- package/dist/lib/components/shared/FormField.component.d.ts.map +1 -0
- package/dist/lib/components/shared/ModalOverlay.component.d.ts +9 -0
- package/dist/lib/components/shared/ModalOverlay.component.d.ts.map +1 -0
- package/dist/lib/components/shared/RoleBadge.component.d.ts +7 -0
- package/dist/lib/components/shared/RoleBadge.component.d.ts.map +1 -0
- package/dist/lib/components/shared/StatusCard.component.d.ts +10 -0
- package/dist/lib/components/shared/StatusCard.component.d.ts.map +1 -0
- package/dist/lib/components/users/UserList.component.d.ts +6 -0
- package/dist/lib/components/users/UserList.component.d.ts.map +1 -0
- package/dist/lib/styles.d.ts +8 -0
- package/dist/lib/styles.d.ts.map +1 -0
- package/dist/lib/types.d.ts +9 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/jest.config.cts +14 -0
- package/package.json +27 -0
- package/src/index.ts +4 -0
- package/src/lib/components/invitations/AcceptInvitation.component.spec.tsx +154 -0
- package/src/lib/components/invitations/AcceptInvitation.component.tsx +197 -0
- package/src/lib/components/invitations/InviteUserModal.component.spec.tsx +79 -0
- package/src/lib/components/invitations/InviteUserModal.component.tsx +121 -0
- package/src/lib/components/invitations/index.ts +2 -0
- package/src/lib/components/shared/ConfirmDialog.component.spec.tsx +45 -0
- package/src/lib/components/shared/ConfirmDialog.component.tsx +58 -0
- package/src/lib/components/shared/FormField.component.spec.tsx +50 -0
- package/src/lib/components/shared/FormField.component.tsx +34 -0
- package/src/lib/components/shared/ModalOverlay.component.spec.tsx +81 -0
- package/src/lib/components/shared/ModalOverlay.component.tsx +45 -0
- package/src/lib/components/shared/RoleBadge.component.spec.tsx +20 -0
- package/src/lib/components/shared/RoleBadge.component.tsx +25 -0
- package/src/lib/components/shared/StatusCard.component.spec.tsx +44 -0
- package/src/lib/components/shared/StatusCard.component.tsx +47 -0
- package/src/lib/components/users/UserList.component.spec.tsx +216 -0
- package/src/lib/components/users/UserList.component.tsx +153 -0
- package/src/lib/styles.ts +19 -0
- package/src/lib/types.ts +9 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lib.json +47 -0
- package/tsconfig.spec.json +27 -0
- package/vite.config.mts +58 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { useState, useMemo, useCallback } from 'react';
|
|
2
|
+
import { useDispatch } from 'react-redux';
|
|
3
|
+
import type { ColDef, ICellRendererParams } from 'ag-grid-community';
|
|
4
|
+
import {
|
|
5
|
+
useUsersControllerFindAllQuery,
|
|
6
|
+
useUsersControllerDeleteMutation,
|
|
7
|
+
} from '@open-kingdom/shared-frontend-data-access-api-client';
|
|
8
|
+
import { showSuccessNotification } from '@open-kingdom/shared-frontend-data-access-notifications';
|
|
9
|
+
import {
|
|
10
|
+
DataGrid,
|
|
11
|
+
type DataGridTheme,
|
|
12
|
+
} from '@open-kingdom/shared-frontend-ui-datagrid';
|
|
13
|
+
import { useTheme } from '@open-kingdom/shared-frontend-ui-theme';
|
|
14
|
+
import { ConfirmDialog } from '../shared/ConfirmDialog.component';
|
|
15
|
+
import { RoleBadge } from '../shared/RoleBadge.component';
|
|
16
|
+
import { InviteUserModal } from '../invitations';
|
|
17
|
+
import { buttonPrimaryStyles } from '../../styles';
|
|
18
|
+
import type { User } from '../../types';
|
|
19
|
+
|
|
20
|
+
interface UserListProps {
|
|
21
|
+
currentUserId?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function UserList({ currentUserId }: UserListProps) {
|
|
25
|
+
const dispatch = useDispatch();
|
|
26
|
+
const { theme, mode } = useTheme();
|
|
27
|
+
const { data, isLoading, error, refetch } = useUsersControllerFindAllQuery();
|
|
28
|
+
const [deleteUser, { isLoading: isDeleting }] =
|
|
29
|
+
useUsersControllerDeleteMutation();
|
|
30
|
+
|
|
31
|
+
const [showInviteModal, setShowInviteModal] = useState(false);
|
|
32
|
+
const [userToDelete, setUserToDelete] = useState<User | null>(null);
|
|
33
|
+
|
|
34
|
+
const users = (data as User[] | undefined) ?? [];
|
|
35
|
+
|
|
36
|
+
const handleDeleteConfirm = useCallback(async () => {
|
|
37
|
+
if (!userToDelete) return;
|
|
38
|
+
try {
|
|
39
|
+
await deleteUser({ id: userToDelete.id }).unwrap();
|
|
40
|
+
dispatch(showSuccessNotification('User deleted successfully'));
|
|
41
|
+
} catch {
|
|
42
|
+
// Error notification handled by RTK error middleware
|
|
43
|
+
} finally {
|
|
44
|
+
setUserToDelete(null);
|
|
45
|
+
}
|
|
46
|
+
}, [userToDelete, deleteUser, dispatch]);
|
|
47
|
+
|
|
48
|
+
const columnDefs = useMemo<ColDef<User>[]>(
|
|
49
|
+
() => [
|
|
50
|
+
{ field: 'email', headerName: 'Email', flex: 2 },
|
|
51
|
+
{
|
|
52
|
+
headerName: 'Name',
|
|
53
|
+
flex: 2,
|
|
54
|
+
valueGetter: (params) => {
|
|
55
|
+
const { firstName, lastName } = params.data ?? {};
|
|
56
|
+
return [firstName, lastName].filter(Boolean).join(' ') || '—';
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
field: 'role',
|
|
61
|
+
headerName: 'Role',
|
|
62
|
+
flex: 1,
|
|
63
|
+
cellRenderer: (params: ICellRendererParams<User>) =>
|
|
64
|
+
params.data ? <RoleBadge role={params.data.role} /> : null,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
headerName: 'Actions',
|
|
68
|
+
flex: 1,
|
|
69
|
+
sortable: false,
|
|
70
|
+
filter: false,
|
|
71
|
+
cellRenderer: (params: ICellRendererParams<User>) => {
|
|
72
|
+
if (!params.data) return null;
|
|
73
|
+
const isSelf = params.data.id === currentUserId;
|
|
74
|
+
return (
|
|
75
|
+
<button
|
|
76
|
+
onClick={() => params.data && setUserToDelete(params.data)}
|
|
77
|
+
disabled={isSelf}
|
|
78
|
+
title={isSelf ? 'Cannot delete your own account' : 'Delete user'}
|
|
79
|
+
className="rounded px-2 py-1 text-xs font-medium text-error-600 transition-colors hover:bg-error-50 disabled:cursor-not-allowed disabled:opacity-40 dark:text-error-400 dark:hover:bg-error-900/20"
|
|
80
|
+
>
|
|
81
|
+
Delete
|
|
82
|
+
</button>
|
|
83
|
+
);
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
[currentUserId]
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
if (error) {
|
|
91
|
+
return (
|
|
92
|
+
<div
|
|
93
|
+
data-testid="users-error"
|
|
94
|
+
className="rounded-lg bg-error-50 p-6 text-center dark:bg-error-900/20"
|
|
95
|
+
role="alert"
|
|
96
|
+
>
|
|
97
|
+
<p className="text-error-700 dark:text-error-300">
|
|
98
|
+
Failed to load users.
|
|
99
|
+
</p>
|
|
100
|
+
<button
|
|
101
|
+
data-testid="users-retry-btn"
|
|
102
|
+
onClick={refetch}
|
|
103
|
+
className="mt-2 text-sm font-medium text-primary-600 hover:underline dark:text-primary-400"
|
|
104
|
+
>
|
|
105
|
+
Try again
|
|
106
|
+
</button>
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<div>
|
|
113
|
+
<div className="mb-4 flex items-center justify-between">
|
|
114
|
+
<h2
|
|
115
|
+
data-testid="users-heading"
|
|
116
|
+
className="text-xl font-semibold text-neutral-900 dark:text-neutral-100"
|
|
117
|
+
>
|
|
118
|
+
Users
|
|
119
|
+
</h2>
|
|
120
|
+
<button
|
|
121
|
+
data-testid="invite-user-btn"
|
|
122
|
+
onClick={() => setShowInviteModal(true)}
|
|
123
|
+
className={buttonPrimaryStyles}
|
|
124
|
+
>
|
|
125
|
+
Invite User
|
|
126
|
+
</button>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<DataGrid
|
|
130
|
+
rowData={users}
|
|
131
|
+
columnDefs={columnDefs}
|
|
132
|
+
mode={mode}
|
|
133
|
+
theme={theme as DataGridTheme}
|
|
134
|
+
loading={isLoading}
|
|
135
|
+
/>
|
|
136
|
+
|
|
137
|
+
<InviteUserModal
|
|
138
|
+
isOpen={showInviteModal}
|
|
139
|
+
onClose={() => setShowInviteModal(false)}
|
|
140
|
+
/>
|
|
141
|
+
|
|
142
|
+
<ConfirmDialog
|
|
143
|
+
isOpen={!!userToDelete}
|
|
144
|
+
title="Delete User"
|
|
145
|
+
message={`Are you sure you want to delete ${userToDelete?.email}? This action cannot be undone.`}
|
|
146
|
+
confirmLabel={isDeleting ? 'Deleting...' : 'Delete'}
|
|
147
|
+
onConfirm={handleDeleteConfirm}
|
|
148
|
+
onCancel={() => setUserToDelete(null)}
|
|
149
|
+
isLoading={isDeleting}
|
|
150
|
+
/>
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const inputStyles =
|
|
2
|
+
'w-full px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-md bg-white dark:bg-neutral-700 text-neutral-900 dark:text-neutral-100';
|
|
3
|
+
|
|
4
|
+
export const labelStyles =
|
|
5
|
+
'block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1';
|
|
6
|
+
|
|
7
|
+
export const cardStyles =
|
|
8
|
+
'max-w-md mx-auto mt-8 p-6 bg-white dark:bg-neutral-800 rounded-lg shadow-lg';
|
|
9
|
+
|
|
10
|
+
export const bodyTextStyles = 'text-neutral-600 dark:text-neutral-400';
|
|
11
|
+
|
|
12
|
+
const buttonBaseStyles =
|
|
13
|
+
'rounded-md px-4 py-2 text-sm font-medium transition-colors';
|
|
14
|
+
|
|
15
|
+
export const buttonPrimaryStyles = `${buttonBaseStyles} bg-primary-500 text-white hover:bg-primary-600 disabled:opacity-50`;
|
|
16
|
+
|
|
17
|
+
export const buttonSecondaryStyles = `${buttonBaseStyles} border border-neutral-300 text-neutral-700 hover:bg-neutral-50 dark:border-neutral-600 dark:text-neutral-300 dark:hover:bg-neutral-700`;
|
|
18
|
+
|
|
19
|
+
export const buttonDangerStyles = `${buttonBaseStyles} bg-error-500 text-white hover:bg-error-600 disabled:opacity-50`;
|
package/src/lib/types.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"types": [
|
|
6
|
+
"node",
|
|
7
|
+
"@nx/react/typings/cssmodule.d.ts",
|
|
8
|
+
"@nx/react/typings/image.d.ts",
|
|
9
|
+
"vite/client"
|
|
10
|
+
],
|
|
11
|
+
"rootDir": "src",
|
|
12
|
+
"jsx": "react-jsx",
|
|
13
|
+
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
|
|
14
|
+
"lib": ["dom", "dom.iterable", "es2022"]
|
|
15
|
+
},
|
|
16
|
+
"exclude": [
|
|
17
|
+
"out-tsc",
|
|
18
|
+
"dist",
|
|
19
|
+
"**/*.spec.ts",
|
|
20
|
+
"**/*.test.ts",
|
|
21
|
+
"**/*.spec.tsx",
|
|
22
|
+
"**/*.test.tsx",
|
|
23
|
+
"**/*.spec.js",
|
|
24
|
+
"**/*.test.js",
|
|
25
|
+
"**/*.spec.jsx",
|
|
26
|
+
"**/*.test.jsx",
|
|
27
|
+
"jest.config.ts",
|
|
28
|
+
"jest.config.cts",
|
|
29
|
+
"src/**/*.spec.ts",
|
|
30
|
+
"src/**/*.test.ts"
|
|
31
|
+
],
|
|
32
|
+
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"],
|
|
33
|
+
"references": [
|
|
34
|
+
{
|
|
35
|
+
"path": "../ui-theme/tsconfig.lib.json"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"path": "../ui-datagrid/tsconfig.lib.json"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"path": "../data-access-notifications/tsconfig.lib.json"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"path": "../data-access-api-client/tsconfig.lib.json"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./out-tsc/jest",
|
|
5
|
+
"lib": ["es2022", "dom"],
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"types": ["jest", "node"]
|
|
8
|
+
},
|
|
9
|
+
"include": [
|
|
10
|
+
"jest.config.ts",
|
|
11
|
+
"jest.config.cts",
|
|
12
|
+
"src/**/*.test.ts",
|
|
13
|
+
"src/**/*.spec.ts",
|
|
14
|
+
"src/**/*.test.tsx",
|
|
15
|
+
"src/**/*.spec.tsx",
|
|
16
|
+
"src/**/*.test.js",
|
|
17
|
+
"src/**/*.spec.js",
|
|
18
|
+
"src/**/*.test.jsx",
|
|
19
|
+
"src/**/*.spec.jsx",
|
|
20
|
+
"src/**/*.d.ts"
|
|
21
|
+
],
|
|
22
|
+
"references": [
|
|
23
|
+
{
|
|
24
|
+
"path": "./tsconfig.lib.json"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
package/vite.config.mts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/// <reference types='vitest' />
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
import react from '@vitejs/plugin-react';
|
|
4
|
+
import dts from 'vite-plugin-dts';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
|
|
7
|
+
export default defineConfig(() => ({
|
|
8
|
+
root: import.meta.dirname,
|
|
9
|
+
cacheDir:
|
|
10
|
+
'../../../../node_modules/.vite/libs/shared/frontend/feature-user-management',
|
|
11
|
+
plugins: [
|
|
12
|
+
react(),
|
|
13
|
+
dts({
|
|
14
|
+
entryRoot: 'src',
|
|
15
|
+
tsconfigPath: path.join(import.meta.dirname, 'tsconfig.lib.json'),
|
|
16
|
+
}),
|
|
17
|
+
],
|
|
18
|
+
// Uncomment this if you are using workers.
|
|
19
|
+
// worker: {
|
|
20
|
+
// plugins: [],
|
|
21
|
+
// },
|
|
22
|
+
// Configuration for building your library.
|
|
23
|
+
// See: https://vite.dev/guide/build.html#library-mode
|
|
24
|
+
build: {
|
|
25
|
+
outDir: './dist',
|
|
26
|
+
emptyOutDir: true,
|
|
27
|
+
reportCompressedSize: true,
|
|
28
|
+
commonjsOptions: {
|
|
29
|
+
transformMixedEsModules: true,
|
|
30
|
+
},
|
|
31
|
+
lib: {
|
|
32
|
+
// Could also be a dictionary or array of multiple entry points.
|
|
33
|
+
entry: 'src/index.ts',
|
|
34
|
+
name: '@open-kingdom/feature-user-management',
|
|
35
|
+
fileName: 'index',
|
|
36
|
+
// Change this to the formats you want to support.
|
|
37
|
+
// Don't forget to update your package.json as well.
|
|
38
|
+
formats: ['es' as const],
|
|
39
|
+
},
|
|
40
|
+
rollupOptions: {
|
|
41
|
+
// External packages that should not be bundled into your library.
|
|
42
|
+
external: [
|
|
43
|
+
'react',
|
|
44
|
+
'react-dom',
|
|
45
|
+
'react/jsx-runtime',
|
|
46
|
+
'react-redux',
|
|
47
|
+
'@reduxjs/toolkit',
|
|
48
|
+
'react-hook-form',
|
|
49
|
+
/^@hookform\/resolvers\/.*/,
|
|
50
|
+
'zod',
|
|
51
|
+
'ag-grid-community',
|
|
52
|
+
/^ag-grid-community\/.*/,
|
|
53
|
+
'@react-hookz/web',
|
|
54
|
+
/^@open-kingdom\/.*/,
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
}));
|