Skip to content

Commit 2b65430

Browse files
authored
fix: more cms and permission updates (#217)
* feat: enhance PermissionToggle component with new variants and visual feedback - Added support for 'compact' and 'detailed' variants to the PermissionToggle component. - Introduced optional props for description, icon visibility, and variant selection. - Updated the component's rendering logic to accommodate new visual styles and feedback mechanisms. - Replaced existing RolePermission and UserPermission components with EnhancedPermissionDialog for improved user experience. * refactor: update Role and User permission handling for improved navigation - Replaced dialog-based permission management in RoleList and UserList components with direct navigation to permission pages. - Updated RolePermission and UserPermission components to use buttons for managing permissions, enhancing user experience. - Improved error handling in usePermissions hook to ensure robustness in permission fetching. * feat: enhance PermissionsPage with user existence check and improved error handling - Added a check for user existence when managing user permissions, displaying appropriate error messages if the user is not found. - Updated permission fetching logic to handle user IDs and usernames more effectively. - Improved loading states and error handling for API requests, ensuring better user feedback during permission management. - Grouped permissions by the first two parts of their names for better organization in the UI. * feat: enhance tenant management and permissions handling - Ensured tenantId is consistently stored as a string across various components and middleware, improving data integrity. - Integrated translation support for permission names in the PermissionsPage, enhancing user experience with localized content. - Improved error handling during permission updates and API requests, providing clearer feedback to users. - Updated session management to handle edge cases for tenantId, ensuring robust authentication flow. * feat: improve user permission management and UI responsiveness - Enhanced user permission management by implementing a more efficient user existence check, providing clearer error messages when users are not found. - Optimized permission fetching logic to better handle user IDs and usernames. - Improved loading states and error handling for API requests, ensuring a smoother user experience during permission management. - Organized permissions in the UI by grouping them based on the first two parts of their names for better clarity. * feat: extend block configuration with new components and props - Added imports for CodeBlock, ListBlock, QuoteBlock, TableBlock, and TestimonialBlock configurations and props. - Updated the config object to include new components in the content, layout, and social categories, enhancing the overall block management capabilities. * refactor: remove CodeBlock component and related files - Deleted the CodeBlock component along with its configuration, props, and story files to streamline the codebase. - Updated the main configuration file to remove references to CodeBlock, ensuring consistency across the component management system. * feat: add new block types to ensureValidPuckData function - Extended the ensureValidPuckData function to include CarouselBlock, ListBlock, QuoteBlock, TableBlock, and TestimonialBlock, enhancing the validation capabilities for various content types. * fix: enhance EnhancedPermissionDialog with unsaved changes confirmation - Implemented a confirmation dialog for unsaved changes when closing the EnhancedPermissionDialog, improving user experience by preventing accidental data loss. - Removed redundant onCloseEvent definition and updated dependencies in the useCallback hook for better performance. - Updated useEnhancedPermissionChanges to handle undefined values for oldValue and newValue, ensuring more robust change tracking.
1 parent 1d24b12 commit 2b65430

File tree

67 files changed

+5418
-631
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+5418
-631
lines changed

GEMINI.md

Lines changed: 455 additions & 0 deletions
Large diffs are not rendered by default.

src/src/app/admin/permissions/[type]/[id]/page.tsx

Lines changed: 576 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default function PermissionsLayout({
2+
children,
3+
}: {
4+
children: React.ReactNode
5+
}) {
6+
return (
7+
<div className="min-h-screen bg-background">
8+
{children}
9+
</div>
10+
)
11+
}

src/src/app/api/[...slug]/route.ts

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,33 @@ interface ApiError extends Error {
88
}
99

1010
const getHeaders = async (): Promise<HeadersInit> => {
11-
const session = await getSession()
11+
try {
12+
const session = await getSession()
13+
14+
const headers = new Headers()
15+
16+
// Check if we have a valid access token
17+
if (!session.access_token) {
18+
console.error('Session debug:', {
19+
isLoggedIn: session.isLoggedIn,
20+
hasUserInfo: !!session.userInfo,
21+
hasTenantId: !!session.tenantId,
22+
sessionKeys: Object.keys(session)
23+
})
24+
throw new Error('No access token available in session')
25+
}
1226

13-
const headers = new Headers()
27+
headers.set('Authorization', `Bearer ${session.access_token}`)
28+
headers.set('Content-Type', 'application/json')
29+
headers.set('__tenant', session.tenantId ?? '')
1430

15-
headers.set('Authorization', `Bearer ${session.access_token}`)
16-
headers.set('Content-Type', 'application/json')
17-
headers.set('__tenant', session.tenantId ?? '')
31+
console.log('tenantId', session.tenantId)
1832

19-
return headers
33+
return headers
34+
} catch (error) {
35+
console.error('Error getting headers:', error)
36+
throw new Error(`Failed to get request headers: ${error instanceof Error ? error.message : 'Unknown error'}`)
37+
}
2038
}
2139

2240
const makeApiRequest = async (
@@ -78,23 +96,44 @@ const makeApiRequest = async (
7896
.clone()
7997
.json()
8098
.catch(() => null)
99+
100+
// Better error message handling
101+
let errorMessage = `API request failed with status ${response.status}`
102+
if (errorData?.error) {
103+
if (typeof errorData.error === 'string') {
104+
errorMessage = errorData.error
105+
} else if (typeof errorData.error === 'object') {
106+
errorMessage = errorData.error.message || JSON.stringify(errorData.error)
107+
}
108+
}
109+
81110
console.error(`[${requestId}] API request failed:`, {
82111
status: response.status,
83112
statusText: response.statusText,
84113
errorData,
114+
errorMessage,
85115
url,
86116
method,
87117
duration: `${Date.now() - startTime}ms`,
88118
})
119+
89120
throw Object.assign(
90-
new Error(errorData?.error || `API request failed with status ${response.status}`),
121+
new Error(errorMessage),
91122
{ status: response.status }
92123
)
93124
}
94125

95-
// Forward the response with original headers
126+
// Handle 204 No Content responses
127+
if (response.status === 204) {
128+
return new NextResponse(null, {
129+
status: 204,
130+
headers: response.headers,
131+
})
132+
}
133+
134+
// Forward the response with original headers for other status codes
96135
const responseHeaders = new Headers(response.headers)
97-
const data = await response.json().catch(() => response)
136+
const data = await response.json().catch(() => null)
98137

99138
return NextResponse.json(data, {
100139
status: response.status,
@@ -103,14 +142,22 @@ const makeApiRequest = async (
103142
} catch (error) {
104143
const apiError = error as ApiError
105144
const duration = Date.now() - startTime
145+
146+
// Better error handling to prevent [object Object] issues
147+
const errorMessage = apiError.message ||
148+
(typeof error === 'string' ? error : 'Unknown error occurred')
149+
const errorStatus = apiError.status || 500
150+
106151
console.error(`[${requestId}] API request error:`, {
107-
error: apiError.message,
108-
status: apiError.status,
152+
error: errorMessage,
153+
status: errorStatus,
109154
stack: apiError.stack,
110155
duration: `${duration}ms`,
111156
timestamp: new Date().toISOString(),
157+
originalError: error,
112158
})
113-
return NextResponse.json({ error: apiError.message }, { status: apiError.status || 500 })
159+
160+
return NextResponse.json({ error: errorMessage }, { status: errorStatus })
114161
}
115162
}
116163

src/src/app/auth/login/route.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ export async function GET() {
1818
const openIdClientConfig = await getClientConfig()
1919
let tenantId = session.tenantId
2020

21-
if (
22-
!tenantId ||
23-
tenantId === 'default' ||
24-
(typeof tenantId === 'object' && Object.keys(tenantId).length === 0)
25-
) {
21+
// Ensure tenantId is always a string and handle edge cases
22+
if (!tenantId ||
23+
tenantId === 'default' ||
24+
(typeof tenantId === 'object' && Object.keys(tenantId).length === 0) ||
25+
typeof tenantId !== 'string') {
2626
tenantId = ''
27+
} else {
28+
tenantId = String(tenantId)
2729
}
2830

2931
let parameters: Record<string, string> = {

src/src/app/auth/set-tenant/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ export async function GET() {
2727
try {
2828
const { data } = await tenantGetTenantGuid({ query: { host: host! } })
2929
console.log('Fetched tenant GUID:', data)
30-
session.tenantId = data ?? 'default'
30+
// Ensure tenantId is always a string
31+
session.tenantId = data ? String(data) : ''
3132
} catch (error) {
3233
console.error('Failed to fetch tenant GUID:', error)
33-
session.tenantId = 'default'
34+
session.tenantId = ''
3435
}
3536

3637
await session.save()

0 commit comments

Comments
 (0)