Skip to content

Commit

Permalink
Merge pull request #722 from AppQuality/bug-comments-fixes
Browse files Browse the repository at this point in the history
fix: UI fixes to badge and Divider
  • Loading branch information
cannarocks authored Jan 3, 2024
2 parents 15054ee + ae12b3e commit 9eb5669
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 78 deletions.
24 changes: 15 additions & 9 deletions src/pages/Bug/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ChatProvider, LG } from '@appquality/unguess-design-system';
import { useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';
import { useFeatureFlag } from 'src/hooks/useFeatureFlag';
import { appTheme } from 'src/app/theme';
import { BugStateDropdown } from 'src/common/components/BugDetail/BugStateDropdown';
import BugPriority from 'src/common/components/BugDetail/Priority';
Expand Down Expand Up @@ -44,6 +45,9 @@ export const Actions = () => {

const cid = campaignId ? campaignId.toString() : '';
const bid = bugId ? bugId.toString() : '';
const { hasFeatureFlag } = useFeatureFlag();

const canAccessComments = hasFeatureFlag('bug-comments');

const {
data: bug,
Expand Down Expand Up @@ -96,15 +100,17 @@ export const Actions = () => {
<BugPriority bug={bug} />
</GridWrapper>
<BugTags bug={bug} refetchBugTags={refetch} />
<Divider style={{ margin: `${appTheme.space.sm} auto` }} />
<ChatProvider onSave={createCommentHandler}>
<ChatBox
campaignId={cid}
bugId={bid}
isSubmitting={isSubmitting}
setIsSubmitting={setIsSubmitting}
/>
</ChatProvider>
{canAccessComments && (
<ChatProvider onSave={createCommentHandler}>
<Divider style={{ margin: `${appTheme.space.sm} auto` }} />
<ChatBox
campaignId={cid}
bugId={bid}
isSubmitting={isSubmitting}
setIsSubmitting={setIsSubmitting}
/>
</ChatProvider>
)}
</Container>
);
};
126 changes: 58 additions & 68 deletions src/pages/Bug/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import {
import { format } from 'date-fns';
import { t } from 'i18next';
import { useEffect, useState } from 'react';
import { useFeatureFlag } from 'src/hooks/useFeatureFlag';
import { styled } from 'styled-components';
import { useAppSelector } from 'src/app/hooks';
import defaultBkg from 'src/assets/bg-chat.svg';
import { getInitials } from 'src/common/components/navigation/header/utils';
import {
useDeleteCampaignsByCidBugsAndBidCommentsCmidMutation,
useGetCampaignsByCidBugsAndBidCommentsQuery,
} from 'src/features/api';
import { styled } from 'styled-components';
import { DeleteCommentModal } from './DeleteCommentModal';

function convertToLocalTime(utcString: string) {
Expand Down Expand Up @@ -67,10 +66,6 @@ export const ChatBox = ({
commentsRefetch();
};

const { hasFeatureFlag } = useFeatureFlag();

const canAccessFeature = hasFeatureFlag('bug-comments');

useEffect(() => {
if (comments) {
// Scroll to bottom of chat
Expand All @@ -82,69 +77,64 @@ export const ChatBox = ({
}, [comments]);
return (
<>
{canAccessFeature && (
<Chat>
<Chat.Header>{t('__BUG_COMMENTS_CHAT_HEADER__')}</Chat.Header>
{comments && comments.items.length > 0 && (
<StyledComments
id="bug-comments-container"
chatBkg={`url(${defaultBkg}) repeat center center`}
>
{comments.items.map((comment) => (
<Comment
author={{
avatar: getInitials(comment.creator.name),
name: comment.creator.name,
}}
date={convertToLocalTime(comment.creation_date)}
message={comment.text}
key={comment.id}
>
<>
<br />
{(comment.creator.id === user.id ||
user.role === 'administrator') && (
<Button
isBasic
onClick={() => openModal(`${comment.id}`)}
>
{t('__BUG_COMMENTS_CHAT_DELETE__')}
</Button>
)}
</>
</Comment>
))}
</StyledComments>
)}
<Chat.Input
author={{ avatar: getInitials(user.name), name: user.name }}
placeholderOptions={{
placeholder: () => t('__BUG_COMMENTS_CHAT_PLACEHOLDER'),
<Chat>
<Chat.Header>{t('__BUG_COMMENTS_CHAT_HEADER__')}</Chat.Header>
{comments && comments.items.length > 0 && (
<StyledComments
id="bug-comments-container"
chatBkg={`url(${defaultBkg}) repeat center center`}
>
{comments.items.map((comment) => (
<Comment
author={{
avatar: getInitials(comment.creator.name),
name: comment.creator.name,
}}
date={convertToLocalTime(comment.creation_date)}
message={comment.text}
key={comment.id}
>
<>
<br />
{(comment.creator.id === user.id ||
user.role === 'administrator') && (
<Button isBasic onClick={() => openModal(`${comment.id}`)}>
{t('__BUG_COMMENTS_CHAT_DELETE__')}
</Button>
)}
</>
</Comment>
))}
</StyledComments>
)}
<Chat.Input
author={{ avatar: getInitials(user.name), name: user.name }}
placeholderOptions={{
placeholder: () => t('__BUG_COMMENTS_CHAT_PLACEHOLDER'),
}}
/>
<Chat.Footer>
<Button
isBasic
onClick={() => {
editor?.commands.clearContent(true);
}}
/>
<Chat.Footer>
<Button
isBasic
onClick={() => {
editor?.commands.clearContent(true);
}}
>
{t('__BUG_COMMENTS_CHAT_CANCEL__')}
</Button>
<Button
isPrimary
isAccent
disabled={isSubmitting}
onClick={() => {
triggerSave();
setIsSubmitting(true);
}}
>
{t('__BUG_COMMENTS_CHAT_CONFIRM__')}
</Button>
</Chat.Footer>
</Chat>
)}
>
{t('__BUG_COMMENTS_CHAT_CANCEL__')}
</Button>
<Button
isPrimary
isAccent
disabled={isSubmitting}
onClick={() => {
triggerSave();
setIsSubmitting(true);
}}
>
{t('__BUG_COMMENTS_CHAT_CONFIRM__')}
</Button>
</Chat.Footer>
</Chat>
{isModalOpen && (
<DeleteCommentModal
setIsModalOpen={setIsModalOpen}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Bugs/Content/components/BugCommentsDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const CommentsCountBadge = styled.span`
background-color: ${({ theme }) => theme.palette.azure[600]};
color: ${({ theme }) => theme.palette.white};
margin-right: ${({ theme }) => theme.space.md};
width: ${appTheme.space.md};
padding: 0 ${appTheme.space.xxs};
height: ${appTheme.space.sm};
font-size: ${appTheme.fontSizes.xs};
border-radius: ${appTheme.borderRadii.lg};
Expand Down

0 comments on commit 9eb5669

Please sign in to comment.