@makolabs/ripple 1.2.8 → 1.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.
|
@@ -19,33 +19,33 @@ export const table = tv({
|
|
|
19
19
|
variants: {
|
|
20
20
|
size: {
|
|
21
21
|
xs: {
|
|
22
|
-
th: 'px-2 py-1.5
|
|
22
|
+
th: 'px-2 py-1.5',
|
|
23
23
|
td: 'px-2 py-1.5 text-xs'
|
|
24
24
|
},
|
|
25
25
|
sm: {
|
|
26
|
-
th: 'px-3 py-2
|
|
26
|
+
th: 'px-3 py-2',
|
|
27
27
|
td: 'px-3 py-2 text-sm'
|
|
28
28
|
},
|
|
29
29
|
base: {
|
|
30
|
-
th: 'px-
|
|
30
|
+
th: 'px-3 py-2',
|
|
31
31
|
td: 'px-4 py-3 text-sm'
|
|
32
32
|
},
|
|
33
33
|
lg: {
|
|
34
|
-
th: 'px-
|
|
34
|
+
th: 'px-4 py-3',
|
|
35
35
|
td: 'px-6 py-4 text-base'
|
|
36
36
|
},
|
|
37
37
|
xl: {
|
|
38
|
-
th: 'px-
|
|
38
|
+
th: 'px-5 py-4',
|
|
39
39
|
td: 'px-8 py-5 text-base'
|
|
40
40
|
},
|
|
41
41
|
'2xl': {
|
|
42
|
-
th: 'px-
|
|
42
|
+
th: 'px-6 py-5',
|
|
43
43
|
td: 'px-10 py-6 text-lg'
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
color: {
|
|
47
47
|
default: {
|
|
48
|
-
th: '
|
|
48
|
+
th: 'bg-gray-50'
|
|
49
49
|
},
|
|
50
50
|
[Color.PRIMARY]: {
|
|
51
51
|
th: 'text-primary-700 bg-primary-50',
|
|
@@ -79,14 +79,38 @@
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
// Modal handlers
|
|
82
|
-
function openViewModal(user: User) {
|
|
82
|
+
async function openViewModal(user: User) {
|
|
83
83
|
selectedUser = user;
|
|
84
84
|
showViewModal = true;
|
|
85
|
+
// Fetch fresh permissions for the user
|
|
86
|
+
if (user.id) {
|
|
87
|
+
try {
|
|
88
|
+
const permissions = await adapter.getUserPermissions(user.id);
|
|
89
|
+
selectedUser = {
|
|
90
|
+
...user,
|
|
91
|
+
permissions
|
|
92
|
+
};
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error('Error fetching user permissions:', error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
85
97
|
}
|
|
86
98
|
|
|
87
|
-
function openEditModal(user: User) {
|
|
99
|
+
async function openEditModal(user: User) {
|
|
88
100
|
selectedUser = user;
|
|
89
101
|
showEditCreateModal = true;
|
|
102
|
+
// Fetch fresh permissions for the user
|
|
103
|
+
if (user.id) {
|
|
104
|
+
try {
|
|
105
|
+
const permissions = await adapter.getUserPermissions(user.id);
|
|
106
|
+
selectedUser = {
|
|
107
|
+
...user,
|
|
108
|
+
permissions
|
|
109
|
+
};
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error('Error fetching user permissions:', error);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
90
114
|
}
|
|
91
115
|
|
|
92
116
|
function openCreateModal() {
|
|
@@ -31,15 +31,69 @@
|
|
|
31
31
|
permissions: []
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
+
// Helper function to detect role from permissions
|
|
35
|
+
function detectRoleFromPermissions(userPermissions: string[]): string {
|
|
36
|
+
if (!roles || roles.length === 0 || !userPermissions || userPermissions.length === 0) {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// First, try to find an exact match (all role permissions match user permissions)
|
|
41
|
+
for (const role of roles) {
|
|
42
|
+
if (role.permissions && role.permissions.length > 0) {
|
|
43
|
+
const rolePermissions = role.permissions;
|
|
44
|
+
// Check if all role permissions are present in user permissions
|
|
45
|
+
const allPermissionsMatch = rolePermissions.every((perm) => userPermissions.includes(perm));
|
|
46
|
+
// Also check if the counts match (to avoid partial matches)
|
|
47
|
+
if (allPermissionsMatch && rolePermissions.length === userPermissions.length) {
|
|
48
|
+
return role.value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// If no exact match, try to find a role where all of its permissions are in user's permissions
|
|
54
|
+
// This handles cases where user has additional permissions beyond the role
|
|
55
|
+
for (const role of roles) {
|
|
56
|
+
if (role.permissions && role.permissions.length > 0) {
|
|
57
|
+
const allRolePermissionsInUser = role.permissions.every((perm) =>
|
|
58
|
+
userPermissions.includes(perm)
|
|
59
|
+
);
|
|
60
|
+
if (allRolePermissionsInUser) {
|
|
61
|
+
return role.value;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Last resort: find any role where at least one permission matches
|
|
67
|
+
// (for cases where permissions might be partially matching)
|
|
68
|
+
for (const role of roles) {
|
|
69
|
+
if (role.permissions && role.permissions.length > 0) {
|
|
70
|
+
const hasMatchingPermission = role.permissions.some((perm) =>
|
|
71
|
+
userPermissions.includes(perm)
|
|
72
|
+
);
|
|
73
|
+
if (hasMatchingPermission) {
|
|
74
|
+
return role.value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
|
|
34
82
|
// Initialize form data when user changes
|
|
35
83
|
$effect(() => {
|
|
36
84
|
if (open && user) {
|
|
85
|
+
// Detect role from permissions if role is not already set
|
|
86
|
+
let detectedRole = user.role || '';
|
|
87
|
+
if (!detectedRole && user.permissions && user.permissions.length > 0) {
|
|
88
|
+
detectedRole = detectRoleFromPermissions(user.permissions);
|
|
89
|
+
}
|
|
90
|
+
|
|
37
91
|
formData = {
|
|
38
92
|
first_name: user.first_name || '',
|
|
39
93
|
last_name: user.last_name || '',
|
|
40
94
|
email_addresses: user.email_addresses || [{ email_address: '' }],
|
|
41
95
|
phone_numbers: user.phone_numbers || [],
|
|
42
|
-
role:
|
|
96
|
+
role: detectedRole,
|
|
43
97
|
permissions: user.permissions || []
|
|
44
98
|
};
|
|
45
99
|
} else if (open && !user) {
|