diff --git a/packages/next/src/views/Dashboard/Default/index.tsx b/packages/next/src/views/Dashboard/Default/index.tsx index 05da8f8c98b..18dbe71694b 100644 --- a/packages/next/src/views/Dashboard/Default/index.tsx +++ b/packages/next/src/views/Dashboard/Default/index.tsx @@ -16,7 +16,11 @@ import './index.scss' const baseClass = 'dashboard' export type DashboardProps = { - globalData: Array<{ data: { _isLocked: boolean; _userEditing: ClientUser | null }; slug: string }> + globalData: Array<{ + data: { _isLocked: boolean; _lastEditedAt: string; _userEditing: ClientUser | null } + lockDuration?: number + slug: string + }> Link: React.ComponentType navGroups?: ReturnType permissions: Permissions @@ -95,7 +99,7 @@ export const DefaultDashboard: React.FC = (props) => { let createHREF: string let href: string let hasCreatePermission: boolean - let lockStatus = null + let isLocked = null let userEditing = null if (type === EntityType.collection) { @@ -130,9 +134,24 @@ export const DefaultDashboard: React.FC = (props) => { const globalLockData = globalData.find( (global) => global.slug === entity.slug, ) + if (globalLockData) { - lockStatus = globalLockData.data._isLocked + isLocked = globalLockData.data._isLocked userEditing = globalLockData.data._userEditing + + // Check if the lock is expired + const lockDuration = globalLockData?.lockDuration + const lastEditedAt = new Date( + globalLockData.data?._lastEditedAt, + ).getTime() + + const lockDurationInMilliseconds = lockDuration * 1000 + const lockExpirationTime = lastEditedAt + lockDurationInMilliseconds + + if (new Date().getTime() > lockExpirationTime) { + isLocked = false + userEditing = null + } } } @@ -140,7 +159,7 @@ export const DefaultDashboard: React.FC = (props) => {
  • ) : hasCreatePermission && type === EntityType.collection ? (