Skip to content

Commit

Permalink
šŸ› Hotfix : display back poll admin section when user is administrator (ā€¦
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlaa authored Feb 13, 2025
1 parent 169aae0 commit 041958b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nosgestesclimat-site-nextjs",
"license": "MIT",
"version": "2.9.2",
"version": "2.9.3",
"description": "The leading open source climate footprint calculator",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
} from '@/constants/tracking/pages/pollDashboard'
import ButtonLink from '@/design-system/inputs/ButtonLink'
import CopyInput from '@/design-system/inputs/CopyInput'
import useFetchOrganisation from '@/hooks/organisations/useFetchOrganisation'
import { useUser } from '@/publicodes-state'
import type { PublicOrganisationPoll } from '@/types/organisations'
import { trackEvent } from '@/utils/matomo/trackEvent'
import { useParams } from 'next/navigation'
Expand All @@ -21,7 +23,25 @@ type Props = {
export default function AdminSection({ poll }: Props) {
const { orgaSlug, pollSlug } = useParams()

if (!poll?.organisation.administrators) return null
const { user } = useUser()

// Organisation can only be fetched by a authentified organisation administrator
const { data: organisation, isLoading: isLoadingOrganisation } =
useFetchOrganisation()

// Temp hotfix to display the admin section
const isAdmin =
poll?.organisation.administrators ||
organisation?.administrators.find(
({ userId, email }) =>
userId === user.userId ||
// Cover possible edge case where admin changes browser and looses his/her original userId
email === user.organisation?.administratorEmail ||
// Unsecure remove as soon as possible
organisation?.slug === user.organisation?.slug
)

if (!isAdmin || isLoadingOrganisation) return null

return (
<section className="mb-10 rounded-xl bg-gray-50 p-6">
Expand Down
1 change: 1 addition & 0 deletions src/types/organisations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type VerifiedUser = {
optedInForCommunications: boolean
createdAt: string
updatedAt: string | null
userId: string
}

type BaseOrganisation = {
Expand Down

0 comments on commit 041958b

Please sign in to comment.