Skip to content

Commit 86aa4cd

Browse files
authored
Merge pull request #779 from AppQuality/develop
release 20240229
2 parents e492dab + 0e39aa3 commit 86aa4cd

22 files changed

+484
-346
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.4.0",
44
"private": true,
55
"dependencies": {
6-
"@appquality/unguess-design-system": "3.1.72",
6+
"@appquality/unguess-design-system": "3.1.78",
77
"@headwayapp/react-widget": "^0.0.4",
88
"@reduxjs/toolkit": "^1.8.0",
99
"@rtk-query/codegen-openapi": "1.2.0",

src/features/api/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const apiSlice = createApi({
2828
'CustomStatuses',
2929
'Bug',
3030
'BugComments',
31+
'Preferences',
3132
],
3233
endpoints: () => ({}),
3334
});

src/features/api/apiTags.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ unguessApi.enhanceEndpoints({
8989
deleteCampaignsByCidBugsAndBidCommentsCmid: {
9090
invalidatesTags: ['BugComments'],
9191
},
92+
getUsersMePreferences: {
93+
providesTags: ['Preferences'],
94+
},
95+
putUsersMePreferencesByPrefid: {
96+
invalidatesTags: ['Preferences'],
97+
},
9298
postCampaignsByCidBugsAndBidComments: {
9399
invalidatesTags: ['Bugs'],
94100
async onQueryStarted({ cid, bid }, { dispatch, queryFulfilled }) {

src/features/api/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,22 @@ const injectedRtkApi = api.injectEndpoints({
483483
body: queryArg.body,
484484
}),
485485
}),
486+
getUsersMePreferences: build.query<
487+
GetUsersMePreferencesApiResponse,
488+
GetUsersMePreferencesApiArg
489+
>({
490+
query: () => ({ url: `/users/me/preferences` }),
491+
}),
492+
putUsersMePreferencesByPrefid: build.mutation<
493+
PutUsersMePreferencesByPrefidApiResponse,
494+
PutUsersMePreferencesByPrefidApiArg
495+
>({
496+
query: (queryArg) => ({
497+
url: `/users/me/preferences/${queryArg.prefid}`,
498+
method: 'PUT',
499+
body: queryArg.body,
500+
}),
501+
}),
486502
}),
487503
overrideExisting: false,
488504
});
@@ -1198,6 +1214,18 @@ export type DeleteCampaignsByCidBugsAndBidCommentsCmidApiArg = {
11981214
cmid: string;
11991215
body: {};
12001216
};
1217+
export type GetUsersMePreferencesApiResponse = /** status 200 OK */ {
1218+
items?: UserPreference[];
1219+
};
1220+
export type GetUsersMePreferencesApiArg = void;
1221+
export type PutUsersMePreferencesByPrefidApiResponse =
1222+
/** status 200 OK */ UserPreference;
1223+
export type PutUsersMePreferencesByPrefidApiArg = {
1224+
prefid: string;
1225+
body: {
1226+
value: number;
1227+
};
1228+
};
12011229
export type Error = {
12021230
message: string;
12031231
code: number;
@@ -1576,6 +1604,11 @@ export type BugComment = {
15761604
isInternal: boolean;
15771605
};
15781606
};
1607+
export type UserPreference = {
1608+
preference_id: number;
1609+
value: number;
1610+
name: string;
1611+
};
15791612
export const {
15801613
use$getQuery,
15811614
usePostAuthenticateMutation,
@@ -1631,4 +1664,6 @@ export const {
16311664
useGetCampaignsByCidBugsAndBidCommentsQuery,
16321665
usePostCampaignsByCidBugsAndBidCommentsMutation,
16331666
useDeleteCampaignsByCidBugsAndBidCommentsCmidMutation,
1667+
useGetUsersMePreferencesQuery,
1668+
usePutUsersMePreferencesByPrefidMutation,
16341669
} = injectedRtkApi;

src/features/navigation/Navigation.tsx

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
Content,
33
Notification,
44
ProfileModal,
5+
Skeleton,
56
useToast,
67
} from '@appquality/unguess-design-system';
78
import { useEffect } from 'react';
@@ -22,6 +23,10 @@ import i18n from 'src/i18n';
2223
import styled from 'styled-components';
2324
import { Header } from '../../common/components/navigation/header/header';
2425
import { usePathWithoutLocale } from './usePathWithoutLocale';
26+
import {
27+
useGetUsersMePreferencesQuery,
28+
usePutUsersMePreferencesByPrefidMutation,
29+
} from '../api';
2530

2631
const StyledContent = styled(Content)`
2732
height: 100%;
@@ -44,7 +49,41 @@ export const Navigation = ({
4449
const { activeWorkspace } = useActiveWorkspace();
4550
const { addToast } = useToast();
4651

47-
// Set isSidebarOpen to false for specific routes
52+
const {
53+
data: preferences,
54+
isLoading: isLoadingPrefs,
55+
isFetching: isFetchingPrefs,
56+
isError,
57+
} = useGetUsersMePreferencesQuery();
58+
59+
const notificationsPreference = preferences?.items?.find(
60+
(preference) => preference?.name === 'notifications_enabled'
61+
);
62+
63+
const [updatePreference] = usePutUsersMePreferencesByPrefidMutation();
64+
65+
const onSetSettings = async (value: number) => {
66+
await updatePreference({
67+
prefid: `${notificationsPreference?.preference_id}`,
68+
body: { value },
69+
})
70+
.unwrap()
71+
.then(() => {
72+
addToast(
73+
({ close }) => (
74+
<Notification
75+
onClose={close}
76+
type="success"
77+
message={t('__PROFILE_MODAL_NOTIFICATIONS_UPDATED')}
78+
closeText={t('__TOAST_CLOSE_TEXT')}
79+
isPrimary
80+
/>
81+
),
82+
{ placement: 'top' }
83+
);
84+
});
85+
};
86+
4887
useEffect(() => {
4988
switch (route) {
5089
case 'service':
@@ -111,6 +150,22 @@ export const Navigation = ({
111150
title: t('__PROFILE_MODAL_PRIVACY_ITEM_LABEL'),
112151
url: 'https://www.iubenda.com/privacy-policy/833252/full-legal',
113152
},
153+
settingValue: notificationsPreference?.value,
154+
i18n: {
155+
settingsTitle: t('__PROFILE_MODAL_NOTIFICATIONS_TITLE'),
156+
settingsIntroText: t('__PROFILE_MODAL_NOTIFICATIONS_INTRO'),
157+
settingsOutroText: {
158+
paragraph_1: t('__PROFILE_MODAL_NOTIFICATIONS_OUTRO_P_1'),
159+
paragraph_2: t('__PROFILE_MODAL_NOTIFICATIONS_OUTRO_P_2'),
160+
paragraph_3: t('__PROFILE_MODAL_NOTIFICATIONS_OUTRO_P_3'),
161+
},
162+
settingsToggle: {
163+
title: t('__PROFILE_MODAL_NOTIFICATIONS_TOGGLE_TITLE'),
164+
on: t('__PROFILE_MODAL_NOTIFICATIONS_TOGGLE_ON'),
165+
off: t('__PROFILE_MODAL_NOTIFICATIONS_TOGGLE_OFF'),
166+
},
167+
},
168+
onSetSettings,
114169
onSelectLanguage: (lang: string) => {
115170
if (pathWithoutLocale === false) return;
116171
if (lang === i18n.language) return;
@@ -158,9 +213,19 @@ export const Navigation = ({
158213

159214
if (!activeWorkspace) return null;
160215

216+
if (isLoadingPrefs) {
217+
return <Skeleton />;
218+
}
219+
if (isError || !preferences) {
220+
return null;
221+
}
161222
return (
162223
<>
163-
<Header {...(isMinimal && { style: { display: 'none' } })} />
224+
<Header
225+
{...(isMinimal && {
226+
style: { display: 'none', opacity: isFetchingPrefs ? 0.5 : 1 },
227+
})}
228+
/>
164229
{isProfileModalOpen && (
165230
<ProfileModal onClose={onProfileModalClose} menuArgs={profileModal} />
166231
)}

src/locales/en/translation.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,15 @@
807807
"__PROFILE_MODAL_FEEDBACK_TITLE": "Give us your feedback",
808808
"__PROFILE_MODAL_LANGUAGES_TITLE": "Change Language",
809809
"__PROFILE_MODAL_LOGOUT_TITLE": "Log Out",
810+
"__PROFILE_MODAL_NOTIFICATIONS_INTRO": "Manage the notifications we send you by email.",
811+
"__PROFILE_MODAL_NOTIFICATIONS_OUTRO_P_1": "By turning on notifications, you will be updated on: ",
812+
"__PROFILE_MODAL_NOTIFICATIONS_OUTRO_P_2": "comments, mentions, campaign starting, campaign ending, and invitations.",
813+
"__PROFILE_MODAL_NOTIFICATIONS_OUTRO_P_3": "By turning off notifications, you will be only updated on mentions and invitations",
814+
"__PROFILE_MODAL_NOTIFICATIONS_TITLE": "Notifications settings",
815+
"__PROFILE_MODAL_NOTIFICATIONS_TOGGLE_OFF": "No",
816+
"__PROFILE_MODAL_NOTIFICATIONS_TOGGLE_ON": "Yes",
817+
"__PROFILE_MODAL_NOTIFICATIONS_TOGGLE_TITLE": "Allow notifications",
818+
"__PROFILE_MODAL_NOTIFICATIONS_UPDATED": "Changes saved",
810819
"__PROFILE_MODAL_PRIVACY_ITEM_LABEL": "Privacy settings",
811820
"__PROJECT_PAGE_UPDATE_PROJECT_NAME_ERROR": "Error",
812821
"__PROJECT_SETTINGS_CTA_TEXT": "Invite",

0 commit comments

Comments
 (0)