Skip to content

Commit e8626ae

Browse files
committed
added flag for notification and network
1 parent 41bc9de commit e8626ae

File tree

9 files changed

+201
-77
lines changed

9 files changed

+201
-77
lines changed

packages/messenger-widget/README.md

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Follow the below given steps :-
9090
theme: undefined,
9191
signInImage: undefined,
9292
siwe: undefined,
93-
disableNetworkDialog: undefined,
93+
disableDialogOptions: undefined,
9494
};
9595

9696
return (
@@ -247,7 +247,7 @@ Follow the below given steps :-
247247
theme: undefined,
248248
signInImage: undefined,
249249
siwe: undefined,
250-
disableNetworkDialog: undefined,
250+
disableDialogOptions: undefined,
251251
};
252252

253253
return (
@@ -455,19 +455,42 @@ Example :
455455
}
456456
```
457457

458-
7. disableNetworkDialog
458+
7. disableDialogOptions
459459
```js
460460
const props: DM3Configuration = {
461461
...
462-
disableNetworkDialog: true,
462+
disableDialogOptions: true,
463463
}
464464
```
465-
This is a optional property of type boolean. To disable network dialog for adding and removing delivery service nodes, its value should be set to true. By default it is false and network dialog is enabled.
465+
This is a optional property of type DisableDialogType. To disable all the properties of dialog set it true. By default all properties are active. All the properties of each category is optional.
466466
```js
467467
Example :
468-
disableNetworkDialog: true
469-
disableNetworkDialog: false
470-
disableNetworkDialog: undefined // its same as this property is not passed in props
468+
disableDialogOptions: true
469+
disableDialogOptions: false
470+
disableDialogOptions: undefined
471+
disableDialogOptions: {
472+
network: true,
473+
notification: {
474+
email: true,
475+
push: false,
476+
},
477+
profile: {
478+
dm3: boolean | {
479+
cloud: false,
480+
optimism: true,
481+
},
482+
self: boolean | {
483+
gnosis: true,
484+
ens: false,
485+
}
486+
}
487+
}
488+
disableDialogOptions: {
489+
notification: {
490+
email: true,
491+
push: false,
492+
},
493+
}
471494
```
472495

473496
8. theme

packages/messenger-widget/src/components/Preferences/Notification/Notification.tsx

Lines changed: 67 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getVerficationModalContent } from './hooks/VerificationContent';
1010
import { DM3ConfigurationContext } from '../../../context/DM3ConfigurationContext';
1111
import { NotificationContext } from '../../../context/NotificationContext';
1212
import loader from '../../../assets/images/loader.svg';
13+
import { ModalContext } from '../../../context/ModalContext';
1314

1415
export function Notification() {
1516
const { screenWidth } = useContext(DM3ConfigurationContext);
@@ -44,6 +45,8 @@ export function Notification() {
4445
loaderData,
4546
} = useContext(NotificationContext);
4647

48+
const { disabledNotification } = useContext(ModalContext);
49+
4750
return (
4851
<div className="position-relative h-100">
4952
<Heading heading={heading} description={description} />
@@ -85,55 +88,59 @@ export function Notification() {
8588
</div>
8689

8790
{/* Email notifications enabled/disabled */}
88-
<div className="notification-content-left mt-4">
89-
<div className="d-flex align-items-center">
90-
<Checkbox
91-
checked={isEmailActive}
91+
{!disabledNotification.email && (
92+
<div className="notification-content-left mt-4">
93+
<div className="d-flex align-items-center">
94+
<Checkbox
95+
checked={isEmailActive}
96+
disabled={!isNotificationsActive}
97+
action={() =>
98+
toggleSpecificNotificationChannel(
99+
!isEmailActive,
100+
NotificationChannelType.EMAIL,
101+
setIsEmailActive,
102+
)
103+
}
104+
heading="Email"
105+
/>
106+
{email && isNotificationsActive ? (
107+
<DeleteIcon
108+
data={email}
109+
type={NotificationChannelType.EMAIL}
110+
deleteNotification={setEmail}
111+
/>
112+
) : (
113+
<NotificationButton
114+
text="Add Email"
115+
disabled={
116+
!isNotificationsActive || !isEmailActive
117+
}
118+
action={() => {
119+
setActiveVerification(
120+
NotificationChannelType.EMAIL,
121+
);
122+
setActiveVerificationContent(
123+
getVerficationModalContent(
124+
NotificationChannelType.EMAIL,
125+
setActiveVerification,
126+
setEmail,
127+
),
128+
);
129+
}}
130+
/>
131+
)}
132+
</div>
133+
<Text
92134
disabled={!isNotificationsActive}
93-
action={() =>
94-
toggleSpecificNotificationChannel(
95-
!isEmailActive,
96-
NotificationChannelType.EMAIL,
97-
setIsEmailActive,
98-
)
135+
text={
136+
'An email is sent to inform you that a message is waiting for you at a delivery service.'
99137
}
100-
heading="Email"
101138
/>
102-
{email && isNotificationsActive ? (
103-
<DeleteIcon
104-
data={email}
105-
type={NotificationChannelType.EMAIL}
106-
deleteNotification={setEmail}
107-
/>
108-
) : (
109-
<NotificationButton
110-
text="Add Email"
111-
disabled={!isNotificationsActive || !isEmailActive}
112-
action={() => {
113-
setActiveVerification(
114-
NotificationChannelType.EMAIL,
115-
);
116-
setActiveVerificationContent(
117-
getVerficationModalContent(
118-
NotificationChannelType.EMAIL,
119-
setActiveVerification,
120-
setEmail,
121-
),
122-
);
123-
}}
124-
/>
125-
)}
139+
<span className="experimental-fun">
140+
Experimental function. Do not use in production!
141+
</span>
126142
</div>
127-
<Text
128-
disabled={!isNotificationsActive}
129-
text={
130-
'An email is sent to inform you that a message is waiting for you at a delivery service.'
131-
}
132-
/>
133-
<span className="experimental-fun">
134-
Experimental function. Do not use in production!
135-
</span>
136-
</div>
143+
)}
137144

138145
{/* Mobile notifications enabled/disabled */}
139146
{/* <div className="notification-content-left mt-4">
@@ -179,22 +186,24 @@ export function Notification() {
179186
</div> */}
180187

181188
{/* Push notifications enabled/disabled */}
182-
<div className="notification-content-left mt-4">
183-
<div className="d-flex align-items-center">
184-
<Checkbox
185-
checked={isPushNotifyActive}
189+
{!disabledNotification.push && (
190+
<div className="notification-content-left mt-4">
191+
<div className="d-flex align-items-center">
192+
<Checkbox
193+
checked={isPushNotifyActive}
194+
disabled={!isNotificationsActive}
195+
action={() =>
196+
pushNotificationAction(!isPushNotifyActive)
197+
}
198+
heading="Push Notifications"
199+
/>
200+
</div>
201+
<Text
186202
disabled={!isNotificationsActive}
187-
action={() =>
188-
pushNotificationAction(!isPushNotifyActive)
189-
}
190-
heading="Push Notifications"
203+
text={'Enable push notifications to your browser.'}
191204
/>
192205
</div>
193-
<Text
194-
disabled={!isNotificationsActive}
195-
text={'Enable push notifications to your browser.'}
196-
/>
197-
</div>
206+
)}
198207
</div>
199208
);
200209
}

packages/messenger-widget/src/context/DM3ConfigurationContext.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export const DM3ConfigurationContext =
3232
showContacts: true,
3333
publicVapidKey: '',
3434
nonce: '',
35-
disableNetworkDialog: false,
3635
},
3736
screenWidth: window.innerWidth,
3837
setScreenWidth: (width: number) => {},

packages/messenger-widget/src/context/ModalContext.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ProfileType,
77
} from '../utils/enum-type-utils';
88
import {
9+
DisabledNotificationType,
910
IConfigureProfileModal,
1011
IOpenEmojiPopup,
1112
PreferencesOptionType,
@@ -40,6 +41,7 @@ export type ModalContextType = {
4041
setPreferencesOptionSelected: (item: PreferencesOptionType | null) => void;
4142
preferencesOptions: PreferencesOptionType[];
4243
updatePreferenceSelected: (ticker: PREFERENCES_ITEMS | null) => void;
44+
disabledNotification: DisabledNotificationType;
4345
};
4446

4547
export const ModalContext = React.createContext<ModalContextType>({
@@ -76,6 +78,10 @@ export const ModalContext = React.createContext<ModalContextType>({
7678
setPreferencesOptionSelected: (item: PreferencesOptionType | null) => {},
7779
preferencesOptions: [],
7880
updatePreferenceSelected: (ticker: PREFERENCES_ITEMS | null) => {},
81+
disabledNotification: {
82+
email: false,
83+
push: false,
84+
},
7985
});
8086

8187
export const ModalContextProvider = ({ children }: { children?: any }) => {
@@ -106,6 +112,7 @@ export const ModalContextProvider = ({ children }: { children?: any }) => {
106112
preferencesOptions,
107113
updatePreferenceSelected,
108114
resetModalStates,
115+
disabledNotification,
109116
} = useModal();
110117

111118
return (
@@ -137,6 +144,7 @@ export const ModalContextProvider = ({ children }: { children?: any }) => {
137144
setPreferencesOptionSelected,
138145
preferencesOptions,
139146
updatePreferenceSelected,
147+
disabledNotification,
140148
}}
141149
>
142150
{children}

packages/messenger-widget/src/demo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function Demo() {
2323
theme: undefined, // OPTIONAL PARAMETER : undefined/themeColors
2424
signInImage: undefined, // OPTIONAL PARAMETER : string URL of image
2525
siwe: undefined, // OPTIONAL PARAMETER : sign in with ethereum
26-
disableNetworkDialog: true, // OPTIONAL PARAMETER : to enable/disable adding or removing DS nodes
26+
disableDialogOptions: undefined, // OPTIONAL PARAMETER : to enable/disable dialog properties
2727
};
2828

2929
return (

packages/messenger-widget/src/hooks/configuration/useDM3Configuration.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const config: DM3Configuration = {
2020
showContacts: true,
2121
publicVapidKey: '',
2222
nonce: '',
23-
disableNetworkDialog: true,
2423
};
2524

2625
describe('useDM3Configuration hook test cases', () => {

packages/messenger-widget/src/hooks/configuration/useDM3Configuration.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export const useDm3Configuration = () => {
2929
showContacts: true,
3030
publicVapidKey: '',
3131
nonce: '',
32-
disableNetworkDialog: false,
3332
});
3433

3534
const validateSiweCredentials = async (data: Siwe) => {

0 commit comments

Comments
 (0)