Skip to content

Commit

Permalink
feat: update declined request logic and copy for pending state
Browse files Browse the repository at this point in the history
  • Loading branch information
drewlyton committed Oct 1, 2024
1 parent 695dc05 commit 8a8fbe2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ export function RequestAccessScreen() {
if (requests && requests?.length) {
const projectRequests = requests.filter((request) => request.resourceId === projectId)
const declinedRequest = projectRequests.find((request) => request.status === 'declined')
if (declinedRequest) {
if (
declinedRequest &&
isAfter(addWeeks(new Date(declinedRequest.createdAt), 2), new Date())
) {
setHasBeenDenied(true)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ export const useRoleRequestsStatus = () => {
)

const declinedRequest = projectRequests.find((request) => request.status === 'declined')
if (declinedRequest) {
return {loading: false, error: false, status: 'denied'}
if (
declinedRequest &&
isAfter(addWeeks(new Date(declinedRequest.createdAt), 2), new Date())
) {
return {loading: false, error: false, status: 'declined'}
}

const pendingRequest = projectRequests.find(
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/structure/i18n/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const structureLocaleStrings = defineLocalesResources('structure', {
'banners.permission-check-banner.missing-permission_update_other':
'Your roles <Roles/> do not have permissions to edit this document.',
/** The pending text for the request permission button that appears for viewer roles */
'banners.permission-check-banner.request-permission-button.sent': 'Request sent',
'banners.permission-check-banner.request-permission-button.sent': 'Editor request sent',
/** The text for the request permission button that appears for viewer roles */
'banners.permission-check-banner.request-permission-button.text': 'Ask to edit',
/** The text for the reload button */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function PermissionCheckBanner({granted, requiredPermission}: PermissionC
} = useRoleRequestsStatus()
const [requestSent, setRequestSent] = useState(false)
const requestPending = useMemo(
() => roleRequestStatus === 'pending' || requestSent,
() => roleRequestStatus === 'pending' || roleRequestStatus === 'declined' || requestSent,
[roleRequestStatus, requestSent],
)
const currentUserRoles = currentUser?.roles || []
Expand Down

0 comments on commit 8a8fbe2

Please sign in to comment.