From acd41d06536db8e274504ae944622afd8328c757 Mon Sep 17 00:00:00 2001 From: nimrodkra <41470823+nimrodkra@users.noreply.github.com> Date: Mon, 16 Nov 2026 19:08:58 +0000 Subject: [PATCH 1/3] feat: Enterprise squads toggle the verified badge and ad-free Enterprise squads can now hide their verified badge and turn ads back on from Manage > Branding. Squads whose plan doesn't include them see both settings locked to Enterprise, so they know the package has them. The plan still decides what a squad is entitled to (verified, adFree). The new showVerifiedBadge and hideAds fields carry the admins' choice: every badge reads showsVerifiedBadge and every ad placement reads isSourceAdFree, both falling back to the entitlement. Places where verified unlocks features (brand color, products, discover grouping) keep reading verified. --- .../cards/ad/squad/SquadAdEntityCard.tsx | 4 +- .../cards/common/AuthorSourceStack.tsx | 5 +- .../cards/entity/SquadEntityCard.tsx | 4 +- .../components/post/PostExcoPlayerWidget.tsx | 1 + .../src/components/post/PostSourceInfo.tsx | 4 +- .../components/post/composer/AudienceChip.tsx | 10 +- .../post/hybrid/PostHybridColumn.tsx | 4 +- .../components/post/reader/SourceStrip.tsx | 4 +- .../sidebar/sections/squadMenuItem.tsx | 6 +- .../squads/SquadCommentJoinBanner.tsx | 4 +- .../widgets/PostUsersHighlights.tsx | 4 +- .../ActiveOrRecomendedSquadsComponents.tsx | 4 +- .../stack/UserStackTopSquadsTooltip.tsx | 3 +- .../squads/components/VerifiedSquad.tsx | 3 +- .../components/discover/FeaturedSquads.tsx | 4 +- .../components/discover/SquadDiscoverRow.tsx | 5 +- .../components/header/SquadProfileHeader.tsx | 8 +- .../squads/components/jobs/SquadJobs.tsx | 4 +- .../manage/SquadEnterpriseSettings.spec.tsx | 102 +++++++++++++++++ .../manage/SquadEnterpriseSettings.tsx | 107 ++++++++++++++++++ .../components/manage/SquadManageBranding.tsx | 3 + .../components/manage/SquadManageLayout.tsx | 4 +- .../squads/components/widgets/SquadRow.tsx | 4 +- .../squads/hooks/useUpdateSquadSettings.ts | 48 ++++++++ .../src/features/squads/lib/features.spec.ts | 24 ++++ .../src/features/squads/lib/features.ts | 13 +++ packages/shared/src/graphql/fragments.ts | 3 + packages/shared/src/graphql/sources.ts | 4 + packages/shared/src/graphql/squads.ts | 37 ++++++ packages/shared/src/graphql/tools.ts | 1 + packages/shared/src/graphql/user/userStack.ts | 3 +- packages/shared/src/graphql/users.ts | 1 + packages/shared/src/lib/ads.spec.ts | 16 +++ packages/shared/src/lib/ads.ts | 7 +- .../tools/ToolOfficialSquadCard.tsx | 3 +- .../webapp/components/tools/ToolSquadCard.tsx | 3 +- 36 files changed, 414 insertions(+), 50 deletions(-) create mode 100644 packages/shared/src/features/squads/components/manage/SquadEnterpriseSettings.spec.tsx create mode 100644 packages/shared/src/features/squads/components/manage/SquadEnterpriseSettings.tsx create mode 100644 packages/shared/src/features/squads/hooks/useUpdateSquadSettings.ts create mode 100644 packages/shared/src/features/squads/lib/features.spec.ts diff --git a/packages/shared/src/components/cards/ad/squad/SquadAdEntityCard.tsx b/packages/shared/src/components/cards/ad/squad/SquadAdEntityCard.tsx index 2f7255359d0..72d0c1d3e85 100644 --- a/packages/shared/src/components/cards/ad/squad/SquadAdEntityCard.tsx +++ b/packages/shared/src/components/cards/ad/squad/SquadAdEntityCard.tsx @@ -23,7 +23,7 @@ import { AdViewability } from '../common/AdViewability'; import type { ViewabilityData } from '../../../../features/monetization/viewability'; import { storeSquadBoostClick } from '../../../../features/monetization/squadBoostClick'; import { useScrambler } from '../../../../hooks/useScrambler'; -import { hasSquadFeature } from '../../../../features/squads/lib/features'; +import { showsVerifiedBadge } from '../../../../features/squads/lib/features'; import { VerifiedSquadBadge } from '../../../../features/squads/components/VerifiedSquad'; import { SquadRow } from '../../../../features/squads/components/widgets/SquadRow'; import { useSquadAd } from './common'; @@ -116,7 +116,7 @@ export function SquadAdEntityCard({ const squadName = ( {name} - {hasSquadFeature(squad, 'verified') && } + {showsVerifiedBadge(squad) && } ); diff --git a/packages/shared/src/components/cards/common/AuthorSourceStack.tsx b/packages/shared/src/components/cards/common/AuthorSourceStack.tsx index 4d3c4b7e618..4ce443d311a 100644 --- a/packages/shared/src/components/cards/common/AuthorSourceStack.tsx +++ b/packages/shared/src/components/cards/common/AuthorSourceStack.tsx @@ -9,7 +9,7 @@ import { ProfileImageSize, roundClasses } from '../../ProfilePicture'; import { ProfileImageLink } from '../../profile/ProfileImageLink'; import SourceButton from './SourceButton'; import { useViewSize, ViewSize } from '../../../hooks'; -import { hasSquadFeature } from '../../../features/squads/lib/features'; +import { showsVerifiedBadge } from '../../../features/squads/lib/features'; import { VerifiedLogoCheck } from '../../../features/squads/components/VerifiedSquad'; const HoverCard = dynamic( @@ -88,8 +88,7 @@ export const AuthorSourceStack = ({ // The card shows the squad's logo without its name, so a verified squad's // seal sits on the logo itself - const hasCheck = - showVerifiedCheck && hasSquadFeature(source ?? undefined, 'verified'); + const hasCheck = showVerifiedCheck && showsVerifiedBadge(source ?? undefined); const sourceButton = showSource ? ( ) : null; diff --git a/packages/shared/src/components/cards/entity/SquadEntityCard.tsx b/packages/shared/src/components/cards/entity/SquadEntityCard.tsx index 86fc3eac5a0..b010a00fc9b 100644 --- a/packages/shared/src/components/cards/entity/SquadEntityCard.tsx +++ b/packages/shared/src/components/cards/entity/SquadEntityCard.tsx @@ -18,7 +18,7 @@ import EntityDescription from './EntityDescription'; import EntityCard from './EntityCard'; import { ContentPreferenceType } from '../../../graphql/contentPreference'; import useShowFollowAction from '../../../hooks/useShowFollowAction'; -import { hasSquadFeature } from '../../../features/squads/lib/features'; +import { showsVerifiedBadge } from '../../../features/squads/lib/features'; import { VerifiedSquadBadge } from '../../../features/squads/components/VerifiedSquad'; type SquadEntityCardProps = { @@ -91,7 +91,7 @@ const SquadEntityCard = ({ bold > {name} - {hasSquadFeature(squad, 'verified') && } + {showsVerifiedBadge(squad) && } {description && } diff --git a/packages/shared/src/components/post/PostExcoPlayerWidget.tsx b/packages/shared/src/components/post/PostExcoPlayerWidget.tsx index 67231461c78..550084e509b 100644 --- a/packages/shared/src/components/post/PostExcoPlayerWidget.tsx +++ b/packages/shared/src/components/post/PostExcoPlayerWidget.tsx @@ -127,6 +127,7 @@ export function PostExcoPlayerWidget({ const isAdFree = shouldSkipSourceAds(post.source) || (post.source?.type === SourceType.Squad && + post.source.features?.hideAds === undefined && post.source.features?.adFree === undefined); const canEvaluate = isAuthReadyOrCached && !isPlusAdFree && !isAdFree && !qaPlayerId; diff --git a/packages/shared/src/components/post/PostSourceInfo.tsx b/packages/shared/src/components/post/PostSourceInfo.tsx index 7d03f7c5a35..750b7471d18 100644 --- a/packages/shared/src/components/post/PostSourceInfo.tsx +++ b/packages/shared/src/components/post/PostSourceInfo.tsx @@ -5,7 +5,7 @@ import type { ReactElement, } from 'react'; import React from 'react'; -import { hasSquadFeature } from '../../features/squads/lib/features'; +import { showsVerifiedBadge } from '../../features/squads/lib/features'; import { VerifiedSquadBadge } from '../../features/squads/components/VerifiedSquad'; import Link from '../utilities/Link'; import { isSourceUserSource, SourceType } from '../../graphql/sources'; @@ -85,7 +85,7 @@ function PostSourceInfo({ )} - {hasSquadFeature(source, 'verified') && ( + {showsVerifiedBadge(source) && ( )} {showActionBtn && ( diff --git a/packages/shared/src/components/post/composer/AudienceChip.tsx b/packages/shared/src/components/post/composer/AudienceChip.tsx index e0efcb347e7..78fdf1de787 100644 --- a/packages/shared/src/components/post/composer/AudienceChip.tsx +++ b/packages/shared/src/components/post/composer/AudienceChip.tsx @@ -1,7 +1,7 @@ import type { ReactElement } from 'react'; import React, { useState } from 'react'; import classNames from 'classnames'; -import { hasSquadFeature } from '../../../features/squads/lib/features'; +import { showsVerifiedBadge } from '../../../features/squads/lib/features'; import { VerifiedSquadBadge } from '../../../features/squads/components/VerifiedSquad'; import { DropdownMenu, @@ -179,9 +179,7 @@ export const AudienceChip = ({ {triggerLabel} - {!isMulti && hasSquadFeature(primary, 'verified') && ( - - )} + {!isMulti && showsVerifiedBadge(primary) && } {showChevron && ( {optionLabel} - {hasSquadFeature(option, 'verified') && ( - - )} + {showsVerifiedBadge(option) && } )} {squadAttribution.source.name} - {hasSquadFeature(squadAttribution.source, 'verified') && ( + {showsVerifiedBadge(squadAttribution.source) && ( )} diff --git a/packages/shared/src/components/post/reader/SourceStrip.tsx b/packages/shared/src/components/post/reader/SourceStrip.tsx index 9c16a5a85b2..98b4932203c 100644 --- a/packages/shared/src/components/post/reader/SourceStrip.tsx +++ b/packages/shared/src/components/post/reader/SourceStrip.tsx @@ -1,7 +1,7 @@ import type { ReactElement } from 'react'; import React from 'react'; import classNames from 'classnames'; -import { hasSquadFeature } from '../../../features/squads/lib/features'; +import { showsVerifiedBadge } from '../../../features/squads/lib/features'; import { VerifiedSquadBadge } from '../../../features/squads/components/VerifiedSquad'; import type { SourceTooltip } from '../../../graphql/sources'; import { FollowButton } from '../../contentPreference/FollowButton'; @@ -82,7 +82,7 @@ export function SourceStrip({ {source.name} - {hasSquadFeature(source, 'verified') && } + {showsVerifiedBadge(source) && } {sourceHandle && ( { ), title: name, - titleSuffix: hasSquadFeature(squad, 'verified') ? ( - - ) : undefined, + titleSuffix: showsVerifiedBadge(squad) ? : undefined, path: `${webappUrl}squads/${handle}`, itemClassName: 'group/squad-row', rightIcon: () => , diff --git a/packages/shared/src/components/squads/SquadCommentJoinBanner.tsx b/packages/shared/src/components/squads/SquadCommentJoinBanner.tsx index f507e98f0a5..b6c956b3eeb 100644 --- a/packages/shared/src/components/squads/SquadCommentJoinBanner.tsx +++ b/packages/shared/src/components/squads/SquadCommentJoinBanner.tsx @@ -3,7 +3,7 @@ import React, { useState } from 'react'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import classNames from 'classnames'; import { VerifiedLogoCheck } from '../../features/squads/components/VerifiedSquad'; -import { hasSquadFeature } from '../../features/squads/lib/features'; +import { showsVerifiedBadge } from '../../features/squads/lib/features'; import type { Origin } from '../../lib/log'; import { Button, ButtonColor, ButtonVariant } from '../buttons/Button'; import { SimpleSquadJoinButton } from './SquadActionButton'; @@ -105,7 +105,7 @@ export const SquadCommentJoinBanner = ({ size={isMobile ? ProfileImageSize.Large : ProfileImageSize.XXXXLarge} /> {/* The name is only in the sentence, so the seal sits on the logo */} - {hasSquadFeature(squad, 'verified') && ( + {showsVerifiedBadge(squad) && ( diff --git a/packages/shared/src/components/widgets/PostUsersHighlights.tsx b/packages/shared/src/components/widgets/PostUsersHighlights.tsx index 31549c9cf61..97e7356a2ed 100644 --- a/packages/shared/src/components/widgets/PostUsersHighlights.tsx +++ b/packages/shared/src/components/widgets/PostUsersHighlights.tsx @@ -26,7 +26,7 @@ import { FollowButton } from '../contentPreference/FollowButton'; import { ContentPreferenceType } from '../../graphql/contentPreference'; import { PlusUserBadge } from '../PlusUserBadge'; import { fallbackImages } from '../../lib/config'; -import { hasSquadFeature } from '../../features/squads/lib/features'; +import { showsVerifiedBadge } from '../../features/squads/lib/features'; import { VerifiedSquadBadge } from '../../features/squads/components/VerifiedSquad'; interface PostAuthorProps { @@ -201,7 +201,7 @@ export const UserHighlight = (props: UserHighlightProps): ReactElement => { > {name} - {'features' in user && hasSquadFeature(user, 'verified') && ( + {'features' in user && showsVerifiedBadge(user) && ( )} {isPlus && } diff --git a/packages/shared/src/features/profile/components/ProfileWidgets/ActiveOrRecomendedSquadsComponents.tsx b/packages/shared/src/features/profile/components/ProfileWidgets/ActiveOrRecomendedSquadsComponents.tsx index 89c1976db40..576027e5a8c 100644 --- a/packages/shared/src/features/profile/components/ProfileWidgets/ActiveOrRecomendedSquadsComponents.tsx +++ b/packages/shared/src/features/profile/components/ProfileWidgets/ActiveOrRecomendedSquadsComponents.tsx @@ -1,6 +1,6 @@ import type { ReactElement } from 'react'; import React from 'react'; -import { hasSquadFeature } from '../../../squads/lib/features'; +import { showsVerifiedBadge } from '../../../squads/lib/features'; import { VerifiedSquadBadge } from '../../../squads/components/VerifiedSquad'; import type { Squad } from '../../../../graphql/sources'; import { useAuthContext } from '../../../../contexts/AuthContext'; @@ -54,7 +54,7 @@ export const SquadListItem = ({ > {squad.name} - {hasSquadFeature(squad, 'verified') && } + {showsVerifiedBadge(squad) && } {squad.name} - {squad.features?.verified && } + {showsVerifiedBadge(squad) && } {source.name} - {source.features?.verified && } + {showsVerifiedBadge(source) && } ); diff --git a/packages/shared/src/features/squads/components/discover/FeaturedSquads.tsx b/packages/shared/src/features/squads/components/discover/FeaturedSquads.tsx index 3687346f8b8..9b8ac88e2b7 100644 --- a/packages/shared/src/features/squads/components/discover/FeaturedSquads.tsx +++ b/packages/shared/src/features/squads/components/discover/FeaturedSquads.tsx @@ -41,9 +41,9 @@ import { featuredSquadsQuery, getSquadBanner, getSquadMembersLabel, - isVerifiedSquad, withPromotedSlot, } from './common'; +import { showsVerifiedBadge } from '../../lib/features'; // The Featured area: a mosaic of blocks on tablet and up, a banner rail on // phones. Featured squads are the only cards with a banner, the promoted @@ -74,7 +74,7 @@ const SquadName = ({ > {squad.name} - {isVerifiedSquad(squad) && ( + {showsVerifiedBadge(squad) && ( )} diff --git a/packages/shared/src/features/squads/components/discover/SquadDiscoverRow.tsx b/packages/shared/src/features/squads/components/discover/SquadDiscoverRow.tsx index 0617d1d7464..7318916f173 100644 --- a/packages/shared/src/features/squads/components/discover/SquadDiscoverRow.tsx +++ b/packages/shared/src/features/squads/components/discover/SquadDiscoverRow.tsx @@ -16,7 +16,8 @@ import { VerifiedSquadBadge } from '../VerifiedSquad'; import { SquadJoinButton } from './SquadJoinButton'; import { PromotedLabel, PromotedSquad } from './PromotedSquad'; import type { SquadDiscoverSection } from './common'; -import { getSquadMembersLabel, isVerifiedSquad } from './common'; +import { getSquadMembersLabel } from './common'; +import { showsVerifiedBadge } from '../../lib/features'; interface SquadDiscoverRowProps { squad: Squad; @@ -82,7 +83,7 @@ export const SquadDiscoverRow = ({ > {squad.name} - {isVerifiedSquad(squad) && ( + {showsVerifiedBadge(squad) && ( )} diff --git a/packages/shared/src/features/squads/components/header/SquadProfileHeader.tsx b/packages/shared/src/features/squads/components/header/SquadProfileHeader.tsx index 36961c6b2bc..af12e8e3090 100644 --- a/packages/shared/src/features/squads/components/header/SquadProfileHeader.tsx +++ b/packages/shared/src/features/squads/components/header/SquadProfileHeader.tsx @@ -18,7 +18,11 @@ import { useLazyModal } from '../../../../hooks/useLazyModal'; import { LazyModal } from '../../../../components/modals/common/types'; import { useAuthContext } from '../../../../contexts/AuthContext'; import { useSquadPageContext } from '../../SquadPageContext'; -import { getSquadId, hasSquadFeature } from '../../lib/features'; +import { + getSquadId, + hasSquadFeature, + showsVerifiedBadge, +} from '../../lib/features'; import { getDisplayUrl, squadLinkRel } from '../../lib/links'; import { SquadViewer } from '../../lib/viewer'; import { getSquadMembersUrl } from '../../lib/routes'; @@ -307,7 +311,7 @@ export const SquadProfileHeader = (): ReactElement => { className="flex flex-wrap items-center gap-x-2 gap-y-1 font-bold text-text-primary typo-title2" > {squad.name} - {hasSquadFeature(squad, 'verified') && ( + {showsVerifiedBadge(squad) && ( )} diff --git a/packages/shared/src/features/squads/components/jobs/SquadJobs.tsx b/packages/shared/src/features/squads/components/jobs/SquadJobs.tsx index d3449a8b54e..fab4499dc16 100644 --- a/packages/shared/src/features/squads/components/jobs/SquadJobs.tsx +++ b/packages/shared/src/features/squads/components/jobs/SquadJobs.tsx @@ -34,7 +34,7 @@ import { LogEvent, Origin } from '../../../../lib/log'; import { getDomainFromUrl } from '../../../../lib/links'; import { useSquadPageContext } from '../../SquadPageContext'; import { useSquadJobs } from '../../hooks/useSquadJobs'; -import { hasSquadFeature } from '../../lib/features'; +import { showsVerifiedBadge } from '../../lib/features'; import { getSquadJobMeta } from '../../lib/jobs'; import { getSquadJobFormUrl, @@ -220,7 +220,7 @@ const JobSummary = ({ job }: { job: SquadJob }): ReactElement => { > {squad.name} - {hasSquadFeature(squad, 'verified') && } + {showsVerifiedBadge(squad) && } ) => { + const squad = { + id: 'squad1', + handle: 'acme', + name: 'Acme', + features, + currentMember: { role: SourceMemberRole.Admin }, + } as unknown as Squad; + + render( + + + + + , + ); +}; + +beforeEach(() => { + nock.cleanAll(); +}); + +describe('SquadEnterpriseSettings', () => { + it('shows both settings locked to Enterprise when the plan has neither', () => { + renderSettings({ products: true }); + + expect(screen.queryAllByRole('switch')).toHaveLength(0); + expect(screen.queryAllByRole('checkbox')).toHaveLength(0); + expect(screen.getByText('Verified badge')).toBeInTheDocument(); + expect(screen.getByText('Ad-free')).toBeInTheDocument(); + expect(screen.getAllByText('Enterprise').length).toBeGreaterThan(1); + }); + + it('hides the verified badge when its switch is turned off', async () => { + let saved = false; + mockGraphQL({ + request: { + query: UPDATE_SQUAD_SETTINGS_MUTATION, + variables: { sourceId: 'squad1', showVerifiedBadge: false }, + }, + result: () => { + saved = true; + return { + data: { + updateSquadSettings: { + id: 'squad1', + features: { showVerifiedBadge: false, hideAds: true }, + }, + }, + }; + }, + }); + renderSettings({ verified: true, adFree: true }); + + const badge = screen.getByLabelText('Verified badge'); + expect(badge).toBeChecked(); + expect(screen.getByLabelText('Ad-free')).toBeChecked(); + + fireEvent.click(badge); + + await waitFor(() => expect(saved).toBe(true)); + }); + + it('turns ads back on for an ad-free squad', async () => { + let saved = false; + mockGraphQL({ + request: { + query: UPDATE_SQUAD_SETTINGS_MUTATION, + variables: { sourceId: 'squad1', hideAds: false }, + }, + result: () => { + saved = true; + return { + data: { + updateSquadSettings: { + id: 'squad1', + features: { showVerifiedBadge: true, hideAds: false }, + }, + }, + }; + }, + }); + renderSettings({ verified: true, adFree: true, hideAds: true }); + + fireEvent.click(screen.getByLabelText('Ad-free')); + + await waitFor(() => expect(saved).toBe(true)); + }); +}); diff --git a/packages/shared/src/features/squads/components/manage/SquadEnterpriseSettings.tsx b/packages/shared/src/features/squads/components/manage/SquadEnterpriseSettings.tsx new file mode 100644 index 00000000000..7334ff0e437 --- /dev/null +++ b/packages/shared/src/features/squads/components/manage/SquadEnterpriseSettings.tsx @@ -0,0 +1,107 @@ +import type { ReactElement } from 'react'; +import React from 'react'; +import { Switch } from '../../../../components/fields/Switch'; +import { + Typography, + TypographyColor, + TypographyType, +} from '../../../../components/typography/Typography'; +import { isSourceAdFree } from '../../../../lib/ads'; +import { useSquadPageContext } from '../../SquadPageContext'; +import { useUpdateSquadSettings } from '../../hooks/useUpdateSquadSettings'; +import { hasSquadFeature, showsVerifiedBadge } from '../../lib/features'; +import { SquadEnterpriseGate } from './SquadEnterpriseGate'; + +interface SettingRowProps { + id: string; + title: string; + description: string; + checked: boolean; + disabled: boolean; + onToggle: () => void; +} + +const SettingRow = ({ + id, + title, + description, + checked, + disabled, + onToggle, +}: SettingRowProps): ReactElement => ( + + + + {title} + + + {description} + + + + +); + +const badgeCopy = { + title: 'Verified badge', + description: 'Show the verified badge next to your name.', +}; + +const adFreeCopy = { + title: 'Ad-free', + description: 'No ads on your page, feed and posts.', +}; + +/** + * Enterprise settings, saved as they are toggled. Squads whose plan doesn't + * include one see it locked, so they know Enterprise has it. + */ +export const SquadEnterpriseSettings = (): ReactElement => { + const { squad } = useSquadPageContext(); + const { mutate: onUpdate, isPending } = useUpdateSquadSettings(squad); + const hasBadge = hasSquadFeature(squad, 'verified'); + const hasAdFree = hasSquadFeature(squad, 'adFree'); + + return ( + + + Enterprise + + {hasBadge ? ( + + onUpdate({ showVerifiedBadge: !showsVerifiedBadge(squad) }) + } + /> + ) : ( + + )} + {hasAdFree ? ( + onUpdate({ hideAds: !isSourceAdFree(squad) })} + /> + ) : ( + + )} + + ); +}; diff --git a/packages/shared/src/features/squads/components/manage/SquadManageBranding.tsx b/packages/shared/src/features/squads/components/manage/SquadManageBranding.tsx index 855642888b3..6586d75ffdd 100644 --- a/packages/shared/src/features/squads/components/manage/SquadManageBranding.tsx +++ b/packages/shared/src/features/squads/components/manage/SquadManageBranding.tsx @@ -36,6 +36,7 @@ import { SQUAD_LINK_MAX_LENGTH } from '../../lib/limits'; import { SquadManageSection } from '../../lib/routes'; import { hasSquadFeature } from '../../lib/features'; import { SquadEnterpriseGate } from './SquadEnterpriseGate'; +import { SquadEnterpriseSettings } from './SquadEnterpriseSettings'; import { SquadManageSaveButton, SquadManageSectionPanel, @@ -404,6 +405,8 @@ const SquadManageBrandingForm = ({ > )} + + ); diff --git a/packages/shared/src/features/squads/components/manage/SquadManageLayout.tsx b/packages/shared/src/features/squads/components/manage/SquadManageLayout.tsx index df0c02443a0..63e4e0085b7 100644 --- a/packages/shared/src/features/squads/components/manage/SquadManageLayout.tsx +++ b/packages/shared/src/features/squads/components/manage/SquadManageLayout.tsx @@ -25,7 +25,7 @@ import { import { HorizontalSeparator } from '../../../../components/utilities/common'; import { SquadImage } from '../../../../components/squads/SquadImage'; import { useSquadPageContext } from '../../SquadPageContext'; -import { hasSquadFeature } from '../../lib/features'; +import { showsVerifiedBadge } from '../../lib/features'; import type { SquadManageGroup } from '../../lib/manage'; import { squadManageTitles } from '../../lib/manage'; import { useSquadManageGroups } from '../../hooks/useSquadManageGroups'; @@ -61,7 +61,7 @@ const MenuHeader = (): ReactElement => { > {squad.name} - {hasSquadFeature(squad, 'verified') && } + {showsVerifiedBadge(squad) && } {name} - {hasSquadFeature(squad, 'verified') && } + {showsVerifiedBadge(squad) && } { + const { user } = useAuthContext(); + const client = useQueryClient(); + const { displayToast } = useToastNotification(); + const queryKey = generateQueryKey(RequestKey.Squad, user, squad.handle); + + const setFeatures = (settings: SquadSettingsInput) => + client.setQueryData( + queryKey, + (current) => + current && { + ...current, + features: { ...current.features, ...settings } as Squad['features'], + }, + ); + + return useMutation({ + mutationFn: (settings: SquadSettingsInput) => + updateSquadSettings({ ...settings, sourceId: getSquadId(squad) }), + onMutate: (settings) => { + const previous = client.getQueryData(queryKey)?.features; + setFeatures(settings); + + return { previous }; + }, + onSuccess: (settings) => { + setFeatures(settings); + displayToast('The settings have been updated'); + }, + onError: (_, __, context) => { + if (context?.previous) { + setFeatures(context.previous); + } + displayToast(labels.error.generic); + }, + }); +}; diff --git a/packages/shared/src/features/squads/lib/features.spec.ts b/packages/shared/src/features/squads/lib/features.spec.ts new file mode 100644 index 00000000000..dbe6cf71a05 --- /dev/null +++ b/packages/shared/src/features/squads/lib/features.spec.ts @@ -0,0 +1,24 @@ +import { showsVerifiedBadge } from './features'; + +describe('showsVerifiedBadge', () => { + it.each([ + { name: 'hides it without verified', features: {}, expected: false }, + { + name: 'falls back to verified', + features: { verified: true }, + expected: true, + }, + { + name: 'hides it when the admins turned it off', + features: { verified: true, showVerifiedBadge: false }, + expected: false, + }, + { + name: 'shows it when the API says so', + features: { verified: true, showVerifiedBadge: true }, + expected: true, + }, + ])('$name', ({ features, expected }) => { + expect(showsVerifiedBadge({ features })).toBe(expected); + }); +}); diff --git a/packages/shared/src/features/squads/lib/features.ts b/packages/shared/src/features/squads/lib/features.ts index f834f9e1e09..2287d22a36a 100644 --- a/packages/shared/src/features/squads/lib/features.ts +++ b/packages/shared/src/features/squads/lib/features.ts @@ -8,6 +8,19 @@ export const hasSquadFeature = ( feature: SquadFeature, ): boolean => !!source?.features?.[feature]; +// The plan includes verified, and its admins haven't hidden the badge. Until +// the API sends showVerifiedBadge, verified shows it. +export const showsVerifiedBadge = ( + source: + | { + features?: Partial< + Pick + > | null; + } + | undefined, +): boolean => + !!(source?.features?.showVerifiedBadge ?? source?.features?.verified); + // A company page: verified (Enterprise) or on a daily.dev for Startups plan, // which turns on products. export const isCompanySquad = ( diff --git a/packages/shared/src/graphql/fragments.ts b/packages/shared/src/graphql/fragments.ts index 627a835f2ae..468c64a3549 100644 --- a/packages/shared/src/graphql/fragments.ts +++ b/packages/shared/src/graphql/fragments.ts @@ -222,6 +222,8 @@ export const SOURCE_BASE_FRAGMENT = gql` products cta jobs + showVerifiedBadge + hideAds } currentMember { ...CurrentMember @@ -328,6 +330,7 @@ export const FEED_POST_INFO_FRAGMENT = gql` } features { verified + showVerifiedBadge } } userState { diff --git a/packages/shared/src/graphql/sources.ts b/packages/shared/src/graphql/sources.ts index 20217176659..7800aff4d2d 100644 --- a/packages/shared/src/graphql/sources.ts +++ b/packages/shared/src/graphql/sources.ts @@ -123,6 +123,10 @@ export interface SourceFeatures { /** The header button without the brand color, on the Startups Team plan */ cta?: boolean | null; jobs?: boolean | null; + /** Verified and its admins show the badge. Falls back to verified */ + showVerifiedBadge?: boolean | null; + /** Ad-free and its admins keep the ads off. Falls back to adFree */ + hideAds?: boolean | null; } export interface Source { diff --git a/packages/shared/src/graphql/squads.ts b/packages/shared/src/graphql/squads.ts index 6d5fb22c23f..64b0907cbb7 100644 --- a/packages/shared/src/graphql/squads.ts +++ b/packages/shared/src/graphql/squads.ts @@ -15,6 +15,7 @@ import { SourceMemberRole, SourceType } from './sources'; import type { BasicSourceMember, Source, + SourceFeatures, SourceMember, SourcePermissions, Squad, @@ -335,6 +336,41 @@ export const updateSquadLinks = async ( return res.updateSquadLinks; }; +export const UPDATE_SQUAD_SETTINGS_MUTATION = gql` + mutation UpdateSquadSettings( + $sourceId: ID! + $showVerifiedBadge: Boolean + $hideAds: Boolean + ) { + updateSquadSettings( + sourceId: $sourceId + showVerifiedBadge: $showVerifiedBadge + hideAds: $hideAds + ) { + id + features { + showVerifiedBadge + hideAds + } + } + } +`; + +export type SquadSettingsInput = Partial< + Pick +>; + +export const updateSquadSettings = async ({ + sourceId, + ...input +}: SquadSettingsInput & { sourceId: string }): Promise => { + const res = await gqlClient.request<{ + updateSquadSettings: { features: SquadSettingsInput }; + }>(UPDATE_SQUAD_SETTINGS_MUTATION, { sourceId, ...input }); + + return res.updateSquadSettings.features; +}; + export const UPDATE_SQUAD_RULES_MUTATION = gql` mutation UpdateSquadRules($sourceId: ID!, $rules: [SquadRuleInput!]!) { updateSquadRules(sourceId: $sourceId, rules: $rules) { @@ -488,6 +524,7 @@ export const SIMILAR_SQUADS_QUERY = gql` membersCount features { verified + showVerifiedBadge } } } diff --git a/packages/shared/src/graphql/tools.ts b/packages/shared/src/graphql/tools.ts index 0e5fb1fe102..817e1e755a8 100644 --- a/packages/shared/src/graphql/tools.ts +++ b/packages/shared/src/graphql/tools.ts @@ -93,6 +93,7 @@ const TOOL_OFFICIAL_SOURCE_QUERY = gql` membersCount features { verified + showVerifiedBadge } } } diff --git a/packages/shared/src/graphql/user/userStack.ts b/packages/shared/src/graphql/user/userStack.ts index 5a30c52b027..573ce113875 100644 --- a/packages/shared/src/graphql/user/userStack.ts +++ b/packages/shared/src/graphql/user/userStack.ts @@ -25,7 +25,7 @@ export interface ToolTopSquad { image: string; description: string | null; membersCount: number; - features: Pick | null; + features: Pick | null; } export interface UserStack { @@ -158,6 +158,7 @@ const TOP_SQUADS_FOR_TOOL_QUERY = gql` membersCount features { verified + showVerifiedBadge } } } diff --git a/packages/shared/src/graphql/users.ts b/packages/shared/src/graphql/users.ts index cc5861597d3..ce9fcf05932 100644 --- a/packages/shared/src/graphql/users.ts +++ b/packages/shared/src/graphql/users.ts @@ -132,6 +132,7 @@ sources: publicSourceMemberships(userId: $id, first: 30) { permalink features { verified + showVerifiedBadge } currentMember { role diff --git a/packages/shared/src/lib/ads.spec.ts b/packages/shared/src/lib/ads.spec.ts index b54e264c367..0ee86efa8f3 100644 --- a/packages/shared/src/lib/ads.spec.ts +++ b/packages/shared/src/lib/ads.spec.ts @@ -329,6 +329,22 @@ describe('ads', () => { }, expected: true, }, + { + name: 'serves an ad-free squad that turned ads back on', + source: { + type: SourceType.Squad, + features: { ...features, adFree: true, hideAds: false }, + }, + expected: false, + }, + { + name: 'skips a squad the API says hides ads', + source: { + type: SourceType.Squad, + features: { ...features, hideAds: true }, + }, + expected: true, + }, { name: 'waits on a squad from a feed card until its post loads', source: { type: SourceType.Squad }, diff --git a/packages/shared/src/lib/ads.ts b/packages/shared/src/lib/ads.ts index b8ac5a90960..392d9bbe9be 100644 --- a/packages/shared/src/lib/ads.ts +++ b/packages/shared/src/lib/ads.ts @@ -9,12 +9,13 @@ import { getBrowserClientHints } from '../features/monetization/browserClientHin /** * Squads with the paid `adFree` feature carry no ads on their feed, their - * search results, or the page and modal of any of their posts. Every ad - * placement reads this one rule. + * search results, or the page and modal of any of their posts, unless their + * admins turned ads back on (`hideAds`). Every ad placement reads this one + * rule. */ export const isSourceAdFree = ( source?: Pick | null, -): boolean => !!source?.features?.adFree; +): boolean => !!(source?.features?.hideAds ?? source?.features?.adFree); /** * A squad post opened from a feed card has no features until its own post diff --git a/packages/webapp/components/tools/ToolOfficialSquadCard.tsx b/packages/webapp/components/tools/ToolOfficialSquadCard.tsx index 42a3131d538..3bdd98bcdbb 100644 --- a/packages/webapp/components/tools/ToolOfficialSquadCard.tsx +++ b/packages/webapp/components/tools/ToolOfficialSquadCard.tsx @@ -18,6 +18,7 @@ import { useSquad } from '@dailydotdev/shared/src/hooks/squads/useSquad'; import { largeNumberFormat } from '@dailydotdev/shared/src/lib/numberFormat'; import { Origin } from '@dailydotdev/shared/src/lib/log'; import type { ToolOfficialSource } from '@dailydotdev/shared/src/graphql/tools'; +import { showsVerifiedBadge } from '@dailydotdev/shared/src/features/squads/lib/features'; interface ToolOfficialSquadCardProps { source: ToolOfficialSource; @@ -51,7 +52,7 @@ export const ToolOfficialSquadCard = ({ {source.name} - + {showsVerifiedBadge(source) && } {source.description && ( {squad.name} - {squad.features?.verified && } + {showsVerifiedBadge(squad) && } {squad.description && ( Date: Mon, 16 Nov 2026 19:30:21 +0000 Subject: [PATCH 2/3] fix(squads): name the badge and ads settings for what they do --- .../squads/components/manage/SquadEnterpriseSettings.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/src/features/squads/components/manage/SquadEnterpriseSettings.tsx b/packages/shared/src/features/squads/components/manage/SquadEnterpriseSettings.tsx index 7334ff0e437..00e3677f0e8 100644 --- a/packages/shared/src/features/squads/components/manage/SquadEnterpriseSettings.tsx +++ b/packages/shared/src/features/squads/components/manage/SquadEnterpriseSettings.tsx @@ -76,7 +76,7 @@ export const SquadEnterpriseSettings = (): ReactElement => { return ( - Enterprise + Verified badge and ads {hasBadge ? ( Date: Mon, 16 Nov 2026 19:35:50 +0000 Subject: [PATCH 3/3] feat(squads): show the verified badge next to its setting --- .../components/manage/SquadEnterpriseGate.tsx | 6 +++++- .../manage/SquadEnterpriseSettings.tsx | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/shared/src/features/squads/components/manage/SquadEnterpriseGate.tsx b/packages/shared/src/features/squads/components/manage/SquadEnterpriseGate.tsx index 8aab585dd9f..0e1bff8d21d 100644 --- a/packages/shared/src/features/squads/components/manage/SquadEnterpriseGate.tsx +++ b/packages/shared/src/features/squads/components/manage/SquadEnterpriseGate.tsx @@ -1,4 +1,4 @@ -import type { ReactElement } from 'react'; +import type { ReactElement, ReactNode } from 'react'; import React from 'react'; import { LockIcon } from '../../../../components/icons'; import { IconSize } from '../../../../components/Icon'; @@ -13,10 +13,13 @@ import { export const SquadEnterpriseGate = ({ title, description, + titleSuffix, plan = 'Enterprise', }: { title: string; description: string; + /** Shown after the title, e.g. what the setting looks like */ + titleSuffix?: ReactNode; /** The plan that includes it */ plan?: string; }): ReactElement => ( @@ -29,6 +32,7 @@ export const SquadEnterpriseGate = ({ {title} + {titleSuffix} void; @@ -25,15 +28,19 @@ const SettingRow = ({ id, title, description, + titleSuffix, checked, disabled, onToggle, }: SettingRowProps): ReactElement => ( - - {title} - + + + {title} + + {titleSuffix} + , }; const adFreeCopy = {