Skip to content

Commit

Permalink
2548: Split feedback toolbar item component
Browse files Browse the repository at this point in the history
  • Loading branch information
steffenkleinle committed Dec 3, 2024
1 parent 4b87183 commit 0b8f07f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 27 deletions.
3 changes: 2 additions & 1 deletion web/src/components/CityContentToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ const CityContentToolbar = (props: CityContentToolbarProps) => {
id='copy-icon'
/>
</Tooltip>
{hasFeedbackOption && <FeedbackToolbarItem route={route} slug={feedbackTarget} />}
{hasFeedbackOption && <FeedbackToolbarItem route={route} slug={feedbackTarget} positive />}
{hasFeedbackOption && <FeedbackToolbarItem route={route} slug={feedbackTarget} positive={false} />}
</Toolbar>
)
}
Expand Down
7 changes: 3 additions & 4 deletions web/src/components/FeedbackContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ type FeedbackContainerProps = {
noResults?: boolean
slug?: string
onSubmit?: () => void
isPositiveRating: boolean | null
setIsPositiveRating?: (isPositiveFeedback: boolean | null) => void
initialRating: boolean | null
}

export type SendingStatusType = 'idle' | 'sending' | 'failed' | 'successful'
Expand All @@ -30,9 +29,9 @@ export const FeedbackContainer = ({
slug,
onClose,
onSubmit,
isPositiveRating,
setIsPositiveRating,
initialRating,
}: FeedbackContainerProps): ReactElement => {
const [isPositiveRating, setIsPositiveRating] = useState<boolean | null>(initialRating)
const [comment, setComment] = useState<string>('')
const [contactMail, setContactMail] = useState<string>('')
const [sendingStatus, setSendingStatus] = useState<SendingStatusType>('idle')
Expand Down
24 changes: 6 additions & 18 deletions web/src/components/FeedbackToolbarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import ToolbarItem from './ToolbarItem'
type FeedbackToolbarItemProps = {
route: RouteType
slug?: string
positive: boolean
}

const FeedbackToolbarItem = ({ route, slug }: FeedbackToolbarItemProps): ReactElement => {
const FeedbackToolbarItem = ({ route, slug, positive }: FeedbackToolbarItemProps): ReactElement => {
const { cityCode, languageCode } = useCityContentParams()
const [isFeedbackOpen, setIsFeedbackOpen] = useState(false)
const [isSubmitted, setIsSubmitted] = useState(false)
const [isPositiveRating, setIsPositiveRating] = useState<boolean | null>(null)
const { t } = useTranslation('feedback')
const title = isSubmitted ? t('thanksHeadline') : t('headline')

Expand All @@ -34,26 +34,14 @@ const FeedbackToolbarItem = ({ route, slug }: FeedbackToolbarItemProps): ReactEl
cityCode={cityCode}
language={languageCode}
slug={slug}
isPositiveRating={isPositiveRating}
setIsPositiveRating={setIsPositiveRating}
initialRating={positive}
/>
</Modal>
)}
<ToolbarItem
icon={HappySmileyIcon}
text={t('useful')}
onClick={() => {
setIsFeedbackOpen(true)
setIsPositiveRating(true)
}}
/>
<ToolbarItem
icon={SadSmileyIcon}
text={t('notUseful')}
onClick={() => {
setIsFeedbackOpen(true)
setIsPositiveRating(false)
}}
icon={positive ? HappySmileyIcon : SadSmileyIcon}
text={t(positive ? 'useful' : 'notUseful')}
onClick={() => setIsFeedbackOpen(true)}
/>
</>
)
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/SearchFeedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const SearchFeedback = ({ cityCode, languageCode, query, noResults }: SearchFeed
routeType={SEARCH_ROUTE}
query={query}
noResults={noResults}
isPositiveRating={null}
initialRating={null}
/>
</Container>
)
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/__tests__/FeedbackContainer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ describe('FeedbackContainer', () => {
language,
onClose: closeModal,
query,
isPositiveRating: null,
initialRating: null,
})

it('should display thanks message for modal', async () => {
const { getByRole, findByText } = renderWithTheme(
<FeedbackContainer {...buildDefaultProps(CATEGORIES_ROUTE)} isPositiveRating />,
<FeedbackContainer {...buildDefaultProps(CATEGORIES_ROUTE)} initialRating />,
)
const button = getByRole('button', {
name: 'feedback:send',
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/__tests__/FeedbackToolbarItem.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jest.mock('focus-trap-react', () => ({ children }: { children: ReactElement }) =
describe('FeedbackToolbarItem', () => {
it('should open and update title on submit feedback', async () => {
const { queryByText, findByText, getByText } = renderWithRouterAndTheme(
<FeedbackToolbarItem route={CATEGORIES_ROUTE} slug='my-slug' />,
<FeedbackToolbarItem route={CATEGORIES_ROUTE} slug='my-slug' positive />,
)

expect(queryByText('feedback:headline')).toBeFalsy()
Expand Down

0 comments on commit 0b8f07f

Please sign in to comment.