Skip to content

Commit

Permalink
Remove granular permissions from lists of permissions in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
DinerIsmail committed Nov 12, 2023
1 parent 5c520da commit b5ba58d
Show file tree
Hide file tree
Showing 15 changed files with 345 additions and 529 deletions.
32 changes: 10 additions & 22 deletions components/admin/permissions-table/PermissionsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable sonarjs/cognitive-complexity */
import { memo } from 'react'
import { Badge, Stack, Table, Tbody, Td, Th, Thead, Tr } from '@chakra-ui/react'
import { useSelectedWebName } from '@hooks/webs'

const columns = [
{
Expand All @@ -15,8 +14,6 @@ const columns = [
]

const PermissionsTable = ({ permissions }) => {
const selectedWebName = useSelectedWebName()

return (
<Table borderWidth="1px" fontSize="sm" background="#ffffff" mb="2rem">
<Thead bg="gray.50">
Expand All @@ -43,25 +40,16 @@ const PermissionsTable = ({ permissions }) => {
)
}

if (permission.webs.some((w) => w.title === selectedWebName)) {
return (
<Td key={index}>
<Stack direction="row">
<Badge>Editor</Badge>
{!permission.user.emailVerified && (
<Badge colorScheme="yellow">Invite pending</Badge>
)}
</Stack>
</Td>
)
} else {
const formatter = new Intl.ListFormat('en', {
style: 'long',
type: 'conjunction',
})
const listings = permission.listings.map((l) => l.title)
return <Td key={index}>{formatter.format(listings)}</Td>
}
return (
<Td key={index}>
<Stack direction="row">
<Badge>Editor</Badge>
{!permission.user.emailVerified && (
<Badge colorScheme="yellow">Invite pending</Badge>
)}
</Stack>
</Td>
)
}

return <Td key={index}>{cell}</Td>
Expand Down
25 changes: 6 additions & 19 deletions components/emails/InviteEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,12 @@ import {
} from '@react-email/components'

interface InviteEmailProps {
listings: string
webTitle: string
inviteToWeb: boolean
email: string
url: string
}

const InviteEmail = ({
listings,
webTitle,
inviteToWeb,
email,
url,
}: InviteEmailProps) => {
const InviteEmail = ({ webTitle, email, url }: InviteEmailProps) => {
// Insert invisible space into domains and email address to prevent both the
// email address and the domain from being turned into a hyperlink by email
// clients like Outlook and Apple mail, as this is confusing because it seems
Expand All @@ -48,17 +40,12 @@ const InviteEmail = ({
alt="Resilience Web logo"
style={logo}
/>
<Text style={paragraph}>Hello,</Text>
<Text style={paragraph}>Hello 👋</Text>
<Text style={paragraph}>
You are invited to be an admin of{' '}
<strong>
{listings}
{inviteToWeb === true ? ' Resilience Web' : ''}
</strong>
{inviteToWeb === false ? ` on the ${webTitle} Resilience Web` : ''},
a digital mapping of organisations that are working to create a more
resilient, more equitable and greener future for this city and its
residents.
You are invited to be an editor on{' '}
<strong>{webTitle} Resilience Web</strong>, a digital mapping of
organisations that are working to create a more resilient, more
equitable and greener future for this city and its residents.
</Text>
<Text style={paragraph}>
Click the button below to sign in as{' '}
Expand Down
2 changes: 1 addition & 1 deletion components/homepage/web-cards/WebCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useWebs } from '@hooks/webs'
const orderOnHomepage = ['Cambridge', 'York', 'Durham']

const WebCards = () => {
const { webs } = useWebs()
const { webs } = useWebs({ published: true })

return (
<Container maxW="7xl">
Expand Down
17 changes: 11 additions & 6 deletions hooks/webs/useWebs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,37 @@ import type { Web } from '@prisma/client'
import { useQuery } from '@tanstack/react-query'
import { REMOTE_URL } from '@helpers/config'

export async function fetchWebsHydrate() {
export async function fetchWebsHydrate({ published = false } = {}) {
const BASE_URL =
process.env.VERCEL_ENV === 'preview'
? 'https://resilienceweb.org.uk'
: REMOTE_URL

const response = await fetch(`${BASE_URL}/api/webs?withListings=true`)
const response = await fetch(
`${BASE_URL}/api/webs?withListings=true&published=${published}`,
)
const data: { webs: Web[] } = await response.json()
const { webs } = data
return webs || []
}

async function fetchWebsRequest() {
const response = await fetch(`/api/webs?withListings=true`)
async function fetchWebsRequest({ queryKey }) {
const [_key, { published }] = queryKey
const response = await fetch(
`/api/webs?withListings=true&published=${published}`,
)
const data: { webs: Web[] } = await response.json()
const { webs } = data
return webs || []
}

export default function useWebs() {
export default function useWebs({ published = false } = {}) {
const {
data: webs,
isPending,
isError,
} = useQuery({
queryKey: ['webs'],
queryKey: ['webs', { published }],
queryFn: fetchWebsRequest,
refetchOnWindowFocus: false,
})
Expand Down
Loading

1 comment on commit b5ba58d

@vercel
Copy link

@vercel vercel bot commented on b5ba58d Nov 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.