Skip to content

Commit

Permalink
feat(handler): add seen by applicant in the messaging bar (#2989)
Browse files Browse the repository at this point in the history
* chore: add translation

* chore: expose seen_by_applicant

* feat: message has seen by applicant check mark and text

* fix: do not display ahjo ui button in production
  • Loading branch information
sirtawast committed Jun 3, 2024
1 parent cbcf483 commit c4eca38
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 16 deletions.
1 change: 1 addition & 0 deletions backend/benefit/messages/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Meta:
"modified_at",
"content",
"message_type",
"seen_by_applicant",
]

# An applicant is only allowed to send a message if application is in one of these statuses
Expand Down
3 changes: 2 additions & 1 deletion frontend/benefit/handler/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"send": "Lähetä",
"save": "Tallenna",
"close": "Sulje",
"noMessages": "Ei viestejä"
"noMessages": "Ei viestejä",
"seenByUser": "Viesti luettu"
},
"notifications": {
"accepted": {
Expand Down
3 changes: 2 additions & 1 deletion frontend/benefit/handler/public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"send": "Lähetä",
"save": "Tallenna",
"close": "Sulje",
"noMessages": "Ei viestejä"
"noMessages": "Ei viestejä",
"seenByUser": "Viesti luettu"
},
"notifications": {
"accepted": {
Expand Down
3 changes: 2 additions & 1 deletion frontend/benefit/handler/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"send": "Lähetä",
"save": "Tallenna",
"close": "Sulje",
"noMessages": "Ei viestejä"
"noMessages": "Ei viestejä",
"seenByUser": "Viesti luettu"
},
"notifications": {
"accepted": {
Expand Down
6 changes: 5 additions & 1 deletion frontend/benefit/handler/src/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ const Header: React.FC = () => {
return (
<BaseHeader
title={t('common:appName')}
customItems={[<TemporaryAhjoModeSwitch />]}
customItems={[
process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT !== 'production' ? (
<TemporaryAhjoModeSwitch />
) : null,
]}
titleUrl={ROUTES.HOME}
skipToContentLabel={t('common:header.linkSkipToContent')}
menuToggleAriaLabel={t('common:header.menuToggleAriaLabel')}
Expand Down
4 changes: 4 additions & 0 deletions frontend/benefit/handler/src/components/sidebar/Messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const Messages: React.FC<ComponentProps> = ({ data, variant, withScroll }) => {
variant={variant}
alignRight={message.messageType === MESSAGE_TYPES.HANDLER_MESSAGE}
wrapAsColumn
seenByApplicant={
message.messageType === MESSAGE_TYPES.HANDLER_MESSAGE &&
message.seenByApplicant
}
/>
))}
{data.length === 0 && (
Expand Down
2 changes: 2 additions & 0 deletions frontend/benefit/shared/src/types/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export type MessageData = {
content: string;
message_type: MESSAGE_TYPES;
sender?: string;
seen_by_applicant?: boolean;
};

export type Message = {
Expand All @@ -122,6 +123,7 @@ export type Message = {
content: string;
messageType: MESSAGE_TYPES;
sender?: string;
seenByApplicant?: boolean;
};

export type ApplicantTerms = {
Expand Down
40 changes: 28 additions & 12 deletions frontend/shared/src/components/messaging/Message.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { IconCheck } from 'hds-react';
import { useTranslation } from 'next-i18next';
import React from 'react';
import theme from 'shared/styles/theme';
import { MessageVariant } from 'shared/types/messages';

import {
Expand All @@ -7,6 +10,7 @@ import {
$Message,
$MessageContainer,
$Meta,
$SeenByUser,
$Sender,
} from './Messaging.sc';

Expand All @@ -18,6 +22,7 @@ export interface MessageProps {
alignRight?: boolean;
wrapAsColumn?: boolean;
variant: MessageVariant;
seenByApplicant?: boolean;
}

const Message: React.FC<MessageProps> = ({
Expand All @@ -28,17 +33,28 @@ const Message: React.FC<MessageProps> = ({
variant,
alignRight,
wrapAsColumn,
}) => (
<$MessageContainer>
<$Meta alignRight={alignRight} wrapAsColumn={wrapAsColumn}>
<$Sender>{sender}</$Sender>
<$Date>{date}</$Date>
</$Meta>
<$Message isPrimary={isPrimary} variant={variant} alignRight={alignRight}>
{text}
</$Message>
{variant === 'note' && <$Hr />}
</$MessageContainer>
);
seenByApplicant = false,
}) => {
const { t } = useTranslation();

return (
<$MessageContainer>
<$Meta alignRight={alignRight} wrapAsColumn={wrapAsColumn}>
<$Sender>{sender}</$Sender>
<$Date>{date}</$Date>
{seenByApplicant && (
<$SeenByUser>
{t('common:messenger.seenByUser')}{' '}
<IconCheck size="xs" color={theme.colors.tram} />
</$SeenByUser>
)}
</$Meta>
<$Message isPrimary={isPrimary} variant={variant} alignRight={alignRight}>
{text}
</$Message>
{variant === 'note' && <$Hr />}
</$MessageContainer>
);
};

export default Message;
5 changes: 5 additions & 0 deletions frontend/shared/src/components/messaging/Messaging.sc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export const $Date = styled.span`
color: ${({ theme }) => theme.colors.black50};
`;

export const $SeenByUser = styled.span`
font-size: ${({ theme }) => theme.fontSize.body.s};
color: ${({ theme }) => theme.colors.black50};
`;

export const $MessageContainer = styled.div`
display: flex;
flex-direction: column;
Expand Down

0 comments on commit c4eca38

Please sign in to comment.