Skip to content
38 changes: 19 additions & 19 deletions apps/condo/domains/common/components/Comments/CommentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { FormWithAction } from '@condo/domains/common/components/containers/Form
import { Module, useMultipleFileUploadHook } from '@condo/domains/common/components/MultipleFileUpload'
import { useValidations } from '@condo/domains/common/hooks/useValidations'
import { analytics } from '@condo/domains/common/utils/analytics'
import { NoSubscriptionTooltip } from '@condo/domains/subscription/components'
import { SubscriptionFeatureGuard } from '@condo/domains/subscription/components'
import { useOrganizationSubscription } from '@condo/domains/subscription/hooks'
import { GENERATE_COMMENT_TOUR_STEP_CLOSED_COOKIE, UPDATE_COMMENT_TOUR_STEP_CLOSED_COOKIE } from '@condo/domains/ticket/constants/common'

Expand Down Expand Up @@ -405,7 +405,23 @@ const CommentForm: React.FC<ICommentFormProps> = ({
/>
</Tooltip>,
...(rewriteCommentEnabled ? [
hasAiFeature ? (
<SubscriptionFeatureGuard
key='10'
feature='ai'
fallback={<div>
<Button
Copy link
Member

Choose a reason for hiding this comment

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

wouldnt it just add one more button?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we check if we have a feature in the subscription and show children or fallback

compact
minimal
type='secondary'
size='medium'
disabled
icon={<Sparkles size='small'/>}
className={classNames(styles.rewriteTextButton, styles.rewriteButtonWithText)}
>
{UpdateTextMessage}
</Button>
</div>}
>
<RewriteTextButton
commentsContainerRef={commentsContainerRef}
key='rewriteButton'
Expand All @@ -414,23 +430,7 @@ const CommentForm: React.FC<ICommentFormProps> = ({
rewriteTextLoading={rewriteTextLoading}
onClick={handleUpdateComment}
/>
) : (
<NoSubscriptionTooltip key='rewriteButton'>
<div>
<Button
compact
minimal
type='secondary'
size='medium'
disabled
icon={<Sparkles size='small' />}
className={classNames(styles.rewriteTextButton, styles.rewriteButtonWithText)}
>
{UpdateTextMessage}
</Button>
</div>
</NoSubscriptionTooltip>
),
</SubscriptionFeatureGuard>,
] : []),
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { Tooltip, Tour, Typography } from '@open-condo/ui'

import { AIFlowButton } from '@condo/domains/ai/components/AIFlowButton'
import { Loader } from '@condo/domains/common/components/Loader'
import { NoSubscriptionTooltip } from '@condo/domains/subscription/components'
import { useOrganizationSubscription } from '@condo/domains/subscription/hooks'
import { SubscriptionFeatureGuard } from '@condo/domains/subscription/components'
import { GENERATE_COMMENT_TOUR_STEP_CLOSED_COOKIE } from '@condo/domains/ticket/constants/common'

import { Comment } from './Comment'
Expand Down Expand Up @@ -80,8 +79,6 @@ export const CommentsTabContent: React.FC<CommentsTabContentProps> = ({
const GenerateCommentTourStepTitle = intl.formatMessage({ id: 'ai.generateComment.tourStepTitle' })
const GenerateCommentTourStepDescription = intl.formatMessage({ id: 'ai.generateComment.tourStepDescription' })

const { isFeatureAvailable } = useOrganizationSubscription()
const hasAiFeature = isFeatureAvailable('ai')

const lastComment = useMemo(() => comments?.[0], [comments])
const showGenerateAnswerButton = useMemo(() =>
Expand Down Expand Up @@ -114,7 +111,17 @@ export const CommentsTabContent: React.FC<CommentsTabContentProps> = ({
/>
{
showGenerateAnswerButton && lastComment?.id === comment.id && (
hasAiFeature ? (
<SubscriptionFeatureGuard
feature='ai'
placement='left'
fallback={
<div className={styles.generateAnswerButtonWrapper}>
<AIFlowButton disabled>
{GenerateResponseMessage}
</AIFlowButton>
</div>
}
>
<Tooltip placement='left' mouseEnterDelay={1.5} title={GenerateResponseTooltipMessage}>
<div className={styles.generateAnswerButtonWrapper}>
<AIFlowButton
Expand All @@ -125,23 +132,15 @@ export const CommentsTabContent: React.FC<CommentsTabContentProps> = ({
</AIFlowButton>
</div>
</Tooltip>
) : (
<NoSubscriptionTooltip>
<div className={styles.generateAnswerButtonWrapper}>
<AIFlowButton disabled>
{GenerateResponseMessage}
</AIFlowButton>
</div>
</NoSubscriptionTooltip>
)
</SubscriptionFeatureGuard>
)
}
</React.Fragment>
)
}), [
GenerateResponseMessage, GenerateResponseTooltipMessage, comments, editableComment,
generateCommentLoading, generateCommentOnClickHandler, lastComment?.id, setEditableComment,
showGenerateAnswerButton, updateAction, hasAiFeature,
showGenerateAnswerButton, updateAction,
])

const { currentStep, setCurrentStep } = Tour.useTourContext()
Expand Down Expand Up @@ -172,7 +171,17 @@ export const CommentsTabContent: React.FC<CommentsTabContentProps> = ({
PromptDescriptionMessage={PromptDescriptionMessage}
AiButton={<div className={styles.generateCommentButtonWrapper}>
{showGenerateCommentWithoutComments && (
hasAiFeature ? (
<SubscriptionFeatureGuard
feature='ai'
placement='left'
fallback={
<div className={styles.generateCommentInnerButtonWrapper}>
<AIFlowButton disabled>
{GenerateCommentMessage}
</AIFlowButton>
</div>
}
>
<Tour.TourStep
step={1}
title={GenerateCommentTourStepTitle}
Expand All @@ -188,15 +197,7 @@ export const CommentsTabContent: React.FC<CommentsTabContentProps> = ({
</AIFlowButton>
</div>
</Tour.TourStep>
) : (
<NoSubscriptionTooltip>
<div className={styles.generateCommentInnerButtonWrapper}>
<AIFlowButton disabled>
{GenerateCommentMessage}
</AIFlowButton>
</div>
</NoSubscriptionTooltip>
)
</SubscriptionFeatureGuard>
)}
</div> }
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.full-width {
width: 100%;
}
42 changes: 24 additions & 18 deletions apps/condo/domains/onboarding/components/TourPage/TourStepCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import {
COMPLETED_STEP_LINK,
TOUR_STEP_ACTION_PERMISSION,
} from '@condo/domains/onboarding/utils/clientSchema/constants'
import { NoSubscriptionTooltip } from '@condo/domains/subscription/components'
import { SubscriptionFeatureGuard } from '@condo/domains/subscription/components'
import { useOrganizationSubscription } from '@condo/domains/subscription/hooks'

import styles from './TourStepCard.module.css'

import type { AvailableFeature } from '@condo/domains/subscription/constants/features'

/**
Expand Down Expand Up @@ -125,45 +127,49 @@ export const TourStepCard: React.FC<TourStepCardProps> = (props) => {

return CompletePreviousStepMessage
}, [CompletePreviousStepMessage, NoPermissionsMessage, SettingsMessage, hasPermission])
const isDisabledStatus = useMemo(() => stepStatus === TourStepStatusType.Disabled || !hasPermission || !hasRequiredFeature || disabled, [disabled, hasPermission, hasRequiredFeature, stepStatus])
const isDisabledStatus = useMemo(() => stepStatus === TourStepStatusType.Disabled || !hasPermission || disabled, [disabled, hasPermission, stepStatus])
const isDisabledWithRequiredFeature = isDisabledStatus || !hasRequiredFeature

const cardContent = (
<StyledCardButton
status={stepStatus}
header={{
progressIndicator: { disabled: isDisabledStatus, steps: innerSteps },
progressIndicator: { disabled: isDisabledWithRequiredFeature, steps: innerSteps },
headingTitle: CardTitle,
mainLink: completedStepLink,
}}
body={!isDisabledStatus && BodyDescription && {
body={!isDisabledWithRequiredFeature && BodyDescription && {
description: BodyDescription,
}}
onClick={onClick}
disabled={isDisabledStatus}
accent={!isDisabledStatus && isInnerTodoStep}
disabled={isDisabledWithRequiredFeature}
accent={!isDisabledWithRequiredFeature && isInnerTodoStep}
id={step.type}
/>
)

if (!hasRequiredFeature) {
return (
<NoSubscriptionTooltip key={step.id}>
<div style={{ width: '100%' }}>
{cardContent}
</div>
</NoSubscriptionTooltip>
)
}

if (isDisabledStatus) {
return (
<Tooltip title={disabledMessage}>
<div style={{ width: '100%' }}>
<div className={styles.fullWidth}>
{cardContent}
</div>
</Tooltip>
)
}

return cardContent
return <SubscriptionFeatureGuard
key={step.id}
feature={requiredFeature}
skipTooltip={requiredFeature === undefined}
fallback={
<div className={styles.fullWidth}>
{cardContent}
</div>
}
>
<div className={styles.fullWidth}>
{cardContent}
</div>
</SubscriptionFeatureGuard>
}
Loading
Loading