Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TNO-2831: Vacation Switch feature #2203

Merged
merged 9 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion api/net/Areas/Subscriber/Controllers/WorkOrderController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ public async Task<IActionResult> RequestTranscriptionAsync(long contentId)
NotificationId = notificationId,
ContentId = contentId,
RequestorId = workOrder.RequestorId,
To = !String.IsNullOrWhiteSpace(user.PreferredEmail) ? user.PreferredEmail : user.Email,
To = user != null && !user.IsVacationMode()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not needed. Vacation mode is just to turn off emails.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I understood this part would send email using the email account of To property. So I checked the email account is not under VacationMode.

? (!string.IsNullOrWhiteSpace(user.PreferredEmail) ? user.PreferredEmail : user.Email) ?? string.Empty
: "",
};
await _kafkaProducer.SendMessageAsync(_kafkaOptions.NotificationTopic, request);
}
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion app/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"redux-logger": "3.0.6",
"styled-components": "6.1.11",
"stylis": "4.3.2",
"tno-core": "0.1.135"
"tno-core": "./tno-core-0.1.135.tgz"
},
"devDependencies": {
"@simbathesailor/use-what-changed": "2.0.0",
Expand Down
Binary file added app/editor/tno-core-0.1.135.tgz
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove

Binary file not shown.
10 changes: 5 additions & 5 deletions app/editor/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11074,7 +11074,7 @@ __metadata:
sass-extract-loader: 1.1.0
styled-components: 6.1.11
stylis: 4.3.2
tno-core: ./tno-core-0.1.134.tgz
tno-core: ./tno-core-0.1.135.tgz
typescript: 4.9.5
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -15258,9 +15258,9 @@ __metadata:
languageName: node
linkType: hard

"tno-core@file:./tno-core-0.1.134.tgz::locator=mmi-editor-app%40workspace%3A.":
version: 0.1.134
resolution: "tno-core@file:./tno-core-0.1.134.tgz::locator=mmi-editor-app%40workspace%3A."
"tno-core@file:./tno-core-0.1.135.tgz::locator=mmi-editor-app%40workspace%3A.":
version: 0.1.135
resolution: "tno-core@file:./tno-core-0.1.135.tgz::locator=mmi-editor-app%40workspace%3A."
dependencies:
"@elastic/elasticsearch": ^8.13.1
"@fortawesome/free-solid-svg-icons": ^6.4.2
Expand Down Expand Up @@ -15294,7 +15294,7 @@ __metadata:
stylis: ^4.3.2
tno-core: 0.1.121
yup: ^1.1.1
checksum: 065f8e9ffa3f1b75a4b87c6de36786e74b01f35648503d0dbc9dd6e625aa539682ea1f01665b40eb2834940c7c93ae1eadb8bfbea771c331ff83f777babcc727
checksum: 173bc8738382c6b0ed19d1a93b206c3d769beb344778691fc5529461a229da8f2ce90cb1d2f5a3863096234d61bf4a069442f138244f673bc4dbd203ed15b497
languageName: node
linkType: hard

Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion app/subscriber/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"sheetjs": "file:packages/xlsx-0.20.1.tgz",
"styled-components": "6.1.11",
"stylis": "4.3.2",
"tno-core": "0.1.135"
"tno-core": "./tno-core-0.1.135.tgz"
},
"devDependencies": {
"@testing-library/jest-dom": "6.4.5",
Expand Down
28 changes: 27 additions & 1 deletion app/subscriber/src/components/user-profile/UserProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ScreenSizes } from 'components/layout/constants';
import React from 'react';
import { BiLogOut } from 'react-icons/bi';
import { FaChevronCircleDown, FaUserCircle } from 'react-icons/fa';
import { FaChevronCircleDown, FaUmbrellaBeach, FaUserCircle } from 'react-icons/fa';
import { Link } from 'react-router-dom';
import { Tooltip } from 'react-tooltip';
import { useUsers } from 'store/hooks';
Expand All @@ -21,6 +21,11 @@ export const UserProfile: React.FC = () => {

const [profileMenu, setProfileMenu] = React.useState(false);

const isVacationMode: boolean = !!impersonate
? impersonate?.preferences?.isVacationMode ?? false
: profile?.preferences?.isVacationMode ?? false;
const [showVacationMode, setShowVacationMode] = React.useState(false);

const isAdmin = keycloak.hasClaim(Claim.administrator);

React.useEffect(() => {
Expand All @@ -41,8 +46,29 @@ export const UserProfile: React.FC = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [profile?.preferences?.impersonate, impersonate, storeImpersonate]);

React.useEffect(() => {
if (isVacationMode !== undefined) {
setShowVacationMode(isVacationMode);
}
}, [isVacationMode]);

const handleVacationModeToggle = React.useCallback(() => {
setShowVacationMode(false);
}, [setShowVacationMode]);

return (
<styled.UserProfile>
<Row>
{showVacationMode && (
<span className="vacation-mode-label">
<FaUmbrellaBeach className="icon" />
Vacation mode enabled
<span className="close-button" onClick={handleVacationModeToggle}>
[x]
</span>
</span>
)}
</Row>
<Row
data-tooltip-id="my-info"
direction="row"
Expand Down
21 changes: 21 additions & 0 deletions app/subscriber/src/components/user-profile/styled/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ export const UserProfile = styled.div`
align-items: center;
margin-left: auto;

.vacation-mode-label {
color: #008000;
display: flex;
align-items: center;

.icon {
margin-right: 5px;
}

.close-button {
color: red;
margin-left: 5px;
cursor: pointer;
font-weight: bold;

&:hover {
text-decoration: underline;
}
}
}

.username-info {
display: flex;
align-items: center;
Expand Down
82 changes: 82 additions & 0 deletions app/subscriber/src/features/settings/MyAccountSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React from 'react';
import { FaEnvelope, FaToggleOff, FaToggleOn, FaUmbrellaBeach } from 'react-icons/fa';
import { toast } from 'react-toastify';
import { useUsers } from 'store/hooks';
import { useProfileStore } from 'store/slices';
import { ISubscriberUserModel, ToggleButton } from 'tno-core';

import * as styled from './styled';

const MyAccountSettings = () => {
const { updateUser } = useUsers();
const [{ profile, impersonate }] = useProfileStore();
const isVacationMode: boolean = !!impersonate
? impersonate?.preferences?.isVacationMode ?? false
: profile?.preferences?.isVacationMode ?? false;

const toggleVacationMode = React.useCallback(
async (
profile: ISubscriberUserModel | undefined,
impersonate: ISubscriberUserModel | undefined,
isVacationMode: boolean,
) => {
if (!profile) {
toast.error('User information is missing. Please try again later');
return;
}
const baseProfile = impersonate ?? profile;
const createUser = (): ISubscriberUserModel => {
// use impersonate if it exists, otherwise use profile
return {
...baseProfile,
preferences: {
...baseProfile.preferences,
isVacationMode: isVacationMode,
},
};
};
const user = createUser();

try {
await updateUser(user, !!impersonate);
toast.success('Vacation mode has successfully been updated.');
} catch (error) {
// Handle the error, if needed
console.error('Failed to update user:', error);
}
},
[updateUser],
);

return (
<styled.MyAccountSettings>
<div className="header-row">
<FaEnvelope className="icon" />
<span className="header-text">E-mail notifications</span>
</div>
<p className="description">
Enabling vacation mode will <strong>turn off</strong> all MMI emails to you, until you
disable vacation mode. This will include subscriptions to MMI Products, Alerts and Reports.
</p>
<div className="toggleContainer">
<ToggleButton
on={<FaToggleOn />}
off={<FaToggleOff />}
onClick={() => toggleVacationMode(profile, impersonate, !isVacationMode)}
width="25px"
height="25px"
color="#008000"
label={
<span className="vacation-mode-label">
<FaUmbrellaBeach className="icon" />
Vacation Mode
</span>
}
value={isVacationMode}
/>
</div>
</styled.MyAccountSettings>
);
};

export default MyAccountSettings;
29 changes: 29 additions & 0 deletions app/subscriber/src/features/settings/SettingsLanding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FaCog } from 'react-icons/fa';
import { Col, Row, Show } from 'tno-core';

import { SettingsSessionEnum } from './constants/SettingsSessionEnum';
import MyAccountSettings from './MyAccountSettings';
import { MyMinisterSettings } from './MyMinisterSettings';
import * as styled from './styled';

Expand All @@ -21,6 +22,16 @@ export const SettingsLanding: React.FC<{}> = () => {
<Col className="left-side">
<PageSection header="Settings" includeHeaderIcon className="menuPanel">
<div className="link-box-container">
<div className="link-box" onClick={() => show(SettingsSessionEnum.MyAccount)}>
<h2>
<FaCog className="list-icon" />
<span>My Account</span>
</h2>
<div className="description">
Alerts are configurable search queries that will send stories to you when they meet
your query criteria.
</div>
</div>
<div className="link-box" onClick={() => show(SettingsSessionEnum.MyMinister)}>
<h2>
<FaCog className="list-icon" />
Expand All @@ -47,6 +58,24 @@ export const SettingsLanding: React.FC<{}> = () => {
</Col>
<Show visible={true}>
<Col className="right-side">
<Show visible={session === SettingsSessionEnum.MyAccount}>
<PageSection
header={
<Row className="header-row">
<div className="title">My Account</div>
<Action
variant="close"
className="close-button"
title="Revert"
onClick={() => setSession('')}
/>
</Row>
}
includeHeaderIcon
>
<MyAccountSettings />
</PageSection>
</Show>
<Show visible={session === SettingsSessionEnum.MyMinister}>
<PageSection
header={
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum SettingsSessionEnum {
MyAccount = 'MyAccount',
MyMinister = 'MyMinister',
MyColleagues = 'MyColleagues',
}
47 changes: 47 additions & 0 deletions app/subscriber/src/features/settings/styled/MyAccountSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import styled from 'styled-components';
import { Col } from 'tno-core';

export const MyAccountSettings = styled(Col)`
padding: 0.6em;

.header-row {
display: flex;
align-items: center;
font-size: 1rem;
color: #333;
margin-top: 0.5rem;
margin-bottom: 0.25rem;
margin-left: 0.75rem;
border-bottom: 1px solid #ccc;

.icon {
font-size: 1.2rem;
margin-right: 0.75rem;
}

.header-text {
font-weight: bold;
font-size: 1.1rem;
}
}

.description {
margin-left: 2.8rem;
}

.toggleContainer {
display: flex;
align-items: center;
margin-left: 3rem;

.vacation-mode-label {
color: #008000;
display: flex;
align-items: center;
}

.icon {
margin-right: 5px;
}
}
`;
1 change: 1 addition & 0 deletions app/subscriber/src/features/settings/styled/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './MyAccountSettings';
export * from './MyMinisterSettings';
export * from './SettingsLanding';
Binary file added app/subscriber/tno-core-0.1.134.tgz
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove

Binary file not shown.
Binary file added app/subscriber/tno-core-0.1.135.tgz
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove

Binary file not shown.
21 changes: 5 additions & 16 deletions app/subscriber/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10677,7 +10677,6 @@ __metadata:
pretty-quick: 4.0.0
react: 18.3.1
react-beautiful-dnd: 13.1.1
react-chartjs-2: 5.2.0
react-color: 2.19.3
react-datepicker: 6.9.0
react-dom: 18.3.1
Expand All @@ -10698,7 +10697,7 @@ __metadata:
sheetjs: "file:packages/xlsx-0.20.1.tgz"
styled-components: 6.1.11
stylis: 4.3.2
tno-core: ./tno-core-0.1.134.tgz
tno-core: ./tno-core-0.1.135.tgz
typescript: 4.9.5
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -12640,16 +12639,6 @@ __metadata:
languageName: node
linkType: hard

"react-chartjs-2@npm:5.2.0":
version: 5.2.0
resolution: "react-chartjs-2@npm:5.2.0"
peerDependencies:
chart.js: ^4.1.1
react: ^16.8.0 || ^17.0.0 || ^18.0.0
checksum: ace702185be1450e5888a8bcd8b5fc1995067e3b11d236764a67f5567a3d7c32ff16923b8d48d3d39bda6e45135da6c044c9b43fbe8e1978f95aca9d2c0ce348
languageName: node
linkType: hard

"react-color@npm:2.19.3":
version: 2.19.3
resolution: "react-color@npm:2.19.3"
Expand Down Expand Up @@ -14740,9 +14729,9 @@ __metadata:
languageName: node
linkType: hard

"tno-core@file:./tno-core-0.1.134.tgz::locator=mmi-subscriber-app%40workspace%3A.":
version: 0.1.134
resolution: "tno-core@file:./tno-core-0.1.134.tgz::locator=mmi-subscriber-app%40workspace%3A."
"tno-core@file:./tno-core-0.1.135.tgz::locator=mmi-subscriber-app%40workspace%3A.":
version: 0.1.135
resolution: "tno-core@file:./tno-core-0.1.135.tgz::locator=mmi-subscriber-app%40workspace%3A."
dependencies:
"@elastic/elasticsearch": ^8.13.1
"@fortawesome/free-solid-svg-icons": ^6.4.2
Expand Down Expand Up @@ -14776,7 +14765,7 @@ __metadata:
stylis: ^4.3.2
tno-core: 0.1.121
yup: ^1.1.1
checksum: 065f8e9ffa3f1b75a4b87c6de36786e74b01f35648503d0dbc9dd6e625aa539682ea1f01665b40eb2834940c7c93ae1eadb8bfbea771c331ff83f777babcc727
checksum: 173bc8738382c6b0ed19d1a93b206c3d769beb344778691fc5529461a229da8f2ce90cb1d2f5a3863096234d61bf4a069442f138244f673bc4dbd203ed15b497
languageName: node
linkType: hard

Expand Down
Loading
Loading