Skip to content

Commit

Permalink
chore: Users with noTemplateLimit flag can create custom templates (#…
Browse files Browse the repository at this point in the history
…9162)

* chore: Users with noTemplateLimit flag can create custom templates

* Allow creating templates on legacy dialog with noTemplateLimit flag
  • Loading branch information
Dschoordsch authored Nov 14, 2023
1 parent 40872db commit e150daf
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ const SUPPORTED_CUSTOM_ACTIVITIES: SupportedActivity[] = [
const query = graphql`
query CreateNewActivityQuery {
viewer {
featureFlags {
noTemplateLimit
}
preferredTeamId
teams {
id
Expand Down Expand Up @@ -158,7 +161,7 @@ export const CreateNewActivity = (props: Props) => {
return selectedActivity
})
const {viewer} = data
const {teams, availableTemplates, preferredTeamId} = viewer
const {teams, availableTemplates, preferredTeamId, featureFlags} = viewer
const [selectedTeam, setSelectedTeam] = useState(
teams.find((team) => team.id === preferredTeamId) ?? sortByTier(teams)[0]!
)
Expand Down Expand Up @@ -331,7 +334,7 @@ export const CreateNewActivity = (props: Props) => {
</div>
{error && <div className='px-4 text-tomato-500'>{error.message}</div>}
<div className='mt-auto flex w-full bg-slate-200 p-2 shadow-card-1'>
{selectedTeam.tier === 'starter' ? (
{selectedTeam.tier === 'starter' && !featureFlags.noTemplateLimit ? (
<div className='mx-auto flex h-12 items-center gap-24'>
<div className='w-96'>
Upgrade to the <b>Team Plan</b> to create custom activities unlocking your team’s
Expand Down
17 changes: 14 additions & 3 deletions packages/client/modules/meeting/components/AddNewPokerTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,32 @@ const AddNewPokerTemplate = (props: Props) => {
fragment AddNewPokerTemplate_team on Team {
id
tier
viewerTeamMember {
id
user {
id
featureFlags {
noTemplateLimit
}
}
}
}
`,
teamRef
)
const {id: teamId, tier} = team
const {id: teamId, tier, viewerTeamMember} = team
const {onError, onCompleted, submitMutation, submitting, error} = useMutationProps()
const errorTimerId = useRef<undefined | number>()
useEffect(() => {
return () => {
window.clearTimeout(errorTimerId.current)
}
}, [])
const canEditTemplates =
tier !== 'starter' || viewerTeamMember?.user?.featureFlags?.noTemplateLimit
const addNewTemplate = () => {
if (submitting) return
if (tier === 'starter') {
if (!canEditTemplates) {
displayUpgradeDetails()
return
}
Expand Down Expand Up @@ -98,7 +109,7 @@ const AddNewPokerTemplate = (props: Props) => {
<div>
{error && <ErrorLine>{error.message}</ErrorLine>}
<AddPokerTemplateLink palette='blue' onClick={addNewTemplate} waiting={submitting}>
Create New Template {tier === 'starter' && '🔒'}
Create New Template {!canEditTemplates && '🔒'}
</AddPokerTemplateLink>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,32 @@ const AddNewReflectTemplate = (props: Props) => {
fragment AddNewReflectTemplate_team on Team {
id
tier
viewerTeamMember {
id
user {
id
featureFlags {
noTemplateLimit
}
}
}
}
`,
teamRef
)
const {tier, id: teamId} = team
const {id: teamId, tier, viewerTeamMember} = team
const {onError, onCompleted, submitMutation, submitting, error} = useMutationProps()
const errorTimerId = useRef<undefined | number>()
useEffect(() => {
return () => {
window.clearTimeout(errorTimerId.current)
}
}, [])
const canEditTemplates =
tier !== 'starter' || viewerTeamMember?.user?.featureFlags?.noTemplateLimit
const addNewTemplate = () => {
if (submitting) return
if (tier === 'starter') {
if (!canEditTemplates) {
displayUpgradeDetails()
return
}
Expand Down Expand Up @@ -95,7 +106,7 @@ const AddNewReflectTemplate = (props: Props) => {
<div>
{error && <ErrorLine>{error.message}</ErrorLine>}
<AddRetroTemplateLink palette='blue' onClick={addNewTemplate} waiting={submitting}>
Create New Template {tier === 'starter' && '🔒'}
Create New Template {!canEditTemplates && '🔒'}
</AddRetroTemplateLink>
</div>
)
Expand Down
11 changes: 6 additions & 5 deletions packages/server/graphql/mutations/addPokerTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ const addPokerTemplate = {
}

// VALIDATION
const allTemplates = await dataLoader
.get('meetingTemplatesByType')
.load({meetingType: 'poker', teamId})
const [allTemplates, viewerTeam, viewer] = await Promise.all([
dataLoader.get('meetingTemplatesByType').load({meetingType: 'poker', teamId}),
dataLoader.get('teams').load(teamId),
dataLoader.get('users').loadNonNull(viewerId)
])
if (allTemplates.length >= Threshold.MAX_RETRO_TEAM_TEMPLATES) {
return standardError(new Error('Too many templates'), {userId: viewerId})
}

const viewerTeam = await dataLoader.get('teams').load(teamId)
if (!viewerTeam) {
return standardError(new Error('Team not found'), {userId: viewerId})
}
if (viewerTeam.tier === 'starter') {
if (viewerTeam.tier === 'starter' && !viewer.featureFlags.includes('noTemplateLimit')) {
return standardError(new Error('Creating templates is a premium feature'), {userId: viewerId})
}
let data
Expand Down
11 changes: 6 additions & 5 deletions packages/server/graphql/mutations/addReflectTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ const addReflectTemplate = {
}

// VALIDATION
const allTemplates = await dataLoader
.get('meetingTemplatesByType')
.load({meetingType: 'retrospective', teamId})
const [allTemplates, viewerTeam, viewer] = await Promise.all([
dataLoader.get('meetingTemplatesByType').load({meetingType: 'retrospective', teamId}),
dataLoader.get('teams').load(teamId),
dataLoader.get('users').loadNonNull(viewerId)
])

if (allTemplates.length >= Threshold.MAX_RETRO_TEAM_TEMPLATES) {
return standardError(new Error('Too many templates'), {userId: viewerId})
}
const viewerTeam = await dataLoader.get('teams').load(teamId)
if (!viewerTeam) {
return standardError(new Error('Team not found'), {userId: viewerId})
}
if (viewerTeam.tier === 'starter') {
if (viewerTeam.tier === 'starter' && !viewer.featureFlags.includes('noTemplateLimit')) {
return standardError(new Error('Creating templates is a premium feature'), {userId: viewerId})
}
let data
Expand Down

0 comments on commit e150daf

Please sign in to comment.