|
@@ -16,7 +16,7 @@ type SubscribeRule = {
|
|
|
isEnabled: boolean,
|
|
isEnabled: boolean,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const defaultSubscribeRulesMenuItems = [
|
|
|
|
|
|
|
+const subscribeRulesMenuItems = [
|
|
|
{
|
|
{
|
|
|
name: 'PAGE_CREATE',
|
|
name: 'PAGE_CREATE',
|
|
|
description: 'in_app_notification_settings.default_subscribe_rules.page_create',
|
|
description: 'in_app_notification_settings.default_subscribe_rules.page_create',
|
|
@@ -27,14 +27,14 @@ const defaultSubscribeRulesMenuItems = [
|
|
|
const InAppNotificationSettings: FC<Props> = (props: Props) => {
|
|
const InAppNotificationSettings: FC<Props> = (props: Props) => {
|
|
|
const { appContainer } = props;
|
|
const { appContainer } = props;
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
- const [defaultSubscribeRules, setDefaultSubscribeRules] = useState<SubscribeRule[]>([]);
|
|
|
|
|
|
|
+ const [subscribeRules, setSubscribeRules] = useState<SubscribeRule[]>([]);
|
|
|
|
|
|
|
|
const initializeInAppNotificationSettings = useCallback(async() => {
|
|
const initializeInAppNotificationSettings = useCallback(async() => {
|
|
|
const { data } = await appContainer.apiv3Get('/personal-setting/in-app-notification-settings');
|
|
const { data } = await appContainer.apiv3Get('/personal-setting/in-app-notification-settings');
|
|
|
- const retrievedRules: SubscribeRule[] = data?.defaultSubscribeRules;
|
|
|
|
|
|
|
+ const retrievedRules: SubscribeRule[] = data?.subscribeRules;
|
|
|
|
|
|
|
|
if (retrievedRules != null && retrievedRules.length > 0) {
|
|
if (retrievedRules != null && retrievedRules.length > 0) {
|
|
|
- setDefaultSubscribeRules(retrievedRules);
|
|
|
|
|
|
|
+ setSubscribeRules(retrievedRules);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
const createRulesFormList = (rule: {name: string}) => (
|
|
const createRulesFormList = (rule: {name: string}) => (
|
|
@@ -43,28 +43,28 @@ const InAppNotificationSettings: FC<Props> = (props: Props) => {
|
|
|
isEnabled: false,
|
|
isEnabled: false,
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
- const initializedSubscribeRules = defaultSubscribeRulesMenuItems.map(rule => createRulesFormList(rule));
|
|
|
|
|
- setDefaultSubscribeRules(initializedSubscribeRules);
|
|
|
|
|
|
|
+ const initializedSubscribeRules = subscribeRulesMenuItems.map(rule => createRulesFormList(rule));
|
|
|
|
|
+ setSubscribeRules(initializedSubscribeRules);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}, [appContainer]);
|
|
}, [appContainer]);
|
|
|
|
|
|
|
|
const isCheckedRule = (ruleName: string) => (
|
|
const isCheckedRule = (ruleName: string) => (
|
|
|
- defaultSubscribeRules.find(stateRule => (
|
|
|
|
|
|
|
+ subscribeRules.find(stateRule => (
|
|
|
stateRule.name === ruleName
|
|
stateRule.name === ruleName
|
|
|
))?.isEnabled || false
|
|
))?.isEnabled || false
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
const ruleCheckboxHandler = (isChecked: boolean, ruleName: string) => {
|
|
const ruleCheckboxHandler = (isChecked: boolean, ruleName: string) => {
|
|
|
- setDefaultSubscribeRules(prevState => (
|
|
|
|
|
|
|
+ setSubscribeRules(prevState => (
|
|
|
prevState.filter(rule => rule.name !== ruleName).concat({ name: ruleName, isEnabled: isChecked })
|
|
prevState.filter(rule => rule.name !== ruleName).concat({ name: ruleName, isEnabled: isChecked })
|
|
|
));
|
|
));
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const updateSettingsHandler = async() => {
|
|
const updateSettingsHandler = async() => {
|
|
|
try {
|
|
try {
|
|
|
- const { data } = await appContainer.apiv3Put('/personal-setting/in-app-notification-settings', { defaultSubscribeRules });
|
|
|
|
|
- setDefaultSubscribeRules(data.defaultSubscribeRules);
|
|
|
|
|
|
|
+ const { data } = await appContainer.apiv3Put('/personal-setting/in-app-notification-settings', { subscribeRules });
|
|
|
|
|
+ setSubscribeRules(data.subscribeRules);
|
|
|
toastSuccess(t('toaster.update_successed', { target: 'InAppNotification Settings' }));
|
|
toastSuccess(t('toaster.update_successed', { target: 'InAppNotification Settings' }));
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
@@ -82,7 +82,7 @@ const InAppNotificationSettings: FC<Props> = (props: Props) => {
|
|
|
|
|
|
|
|
<div className="form-group row">
|
|
<div className="form-group row">
|
|
|
<div className="offset-md-3 col-md-6 text-left">
|
|
<div className="offset-md-3 col-md-6 text-left">
|
|
|
- {defaultSubscribeRulesMenuItems.map(rule => (
|
|
|
|
|
|
|
+ {subscribeRulesMenuItems.map(rule => (
|
|
|
<div
|
|
<div
|
|
|
key={rule.name}
|
|
key={rule.name}
|
|
|
className="custom-control custom-switch custom-checkbox-success"
|
|
className="custom-control custom-switch custom-checkbox-success"
|