|
|
@@ -2,11 +2,11 @@ import React, { FC, useCallback } from 'react';
|
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
-import { SupportedActionType } from '~/interfaces/activity';
|
|
|
+import { SupportedActionType, SupportedActionCategoryType, SupportedActionCategory, PageActions, CommentActions, UserActions, AdminActions } from '~/interfaces/activity';
|
|
|
|
|
|
type Props = {
|
|
|
- dropdownItems: Array<{actionCategory: string, actionNames: SupportedActionType[]}>
|
|
|
actionMap: Map<SupportedActionType, boolean>
|
|
|
+ availableActions: SupportedActionType[]
|
|
|
onChangeAction: (action: SupportedActionType) => void
|
|
|
onChangeMultipleAction: (actions: SupportedActionType[], isChecked: boolean) => void
|
|
|
}
|
|
|
@@ -14,9 +14,28 @@ type Props = {
|
|
|
export const SelectActionDropdown: FC<Props> = (props: Props) => {
|
|
|
const { t } = useTranslation();
|
|
|
const {
|
|
|
- dropdownItems, actionMap, onChangeAction, onChangeMultipleAction,
|
|
|
+ actionMap, availableActions, onChangeAction, onChangeMultipleAction,
|
|
|
} = props;
|
|
|
|
|
|
+ const dropdownItems: Array<{actionCategory: SupportedActionCategoryType, actions: SupportedActionType[]}> = [
|
|
|
+ {
|
|
|
+ actionCategory: SupportedActionCategory.PAGE,
|
|
|
+ actions: PageActions.filter(action => availableActions.includes(action)),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ actionCategory: SupportedActionCategory.COMMENT,
|
|
|
+ actions: CommentActions.filter(action => availableActions.includes(action)),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ actionCategory: SupportedActionCategory.USER,
|
|
|
+ actions: UserActions.filter(action => availableActions.includes(action)),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ actionCategory: SupportedActionCategory.ADMIN,
|
|
|
+ actions: AdminActions.filter(action => availableActions.includes(action)),
|
|
|
+ }
|
|
|
+ ];
|
|
|
+
|
|
|
const actionCheckboxChangedHandler = useCallback((action) => {
|
|
|
if (onChangeAction != null) {
|
|
|
onChangeAction(action);
|
|
|
@@ -43,13 +62,13 @@ export const SelectActionDropdown: FC<Props> = (props: Props) => {
|
|
|
type="checkbox"
|
|
|
className="form-check-input"
|
|
|
defaultChecked
|
|
|
- onChange={(e) => { multipleActionCheckboxChangedHandler(item.actionNames, e.target.checked) }}
|
|
|
+ onChange={(e) => { multipleActionCheckboxChangedHandler(item.actions, e.target.checked) }}
|
|
|
/>
|
|
|
<label className="form-check-label">{item.actionCategory}</label>
|
|
|
</div>
|
|
|
</div>
|
|
|
{
|
|
|
- item.actionNames.map(action => (
|
|
|
+ item.actions.map(action => (
|
|
|
<div className="dropdown-item" key={action}>
|
|
|
<div className="form-group px-4 m-0">
|
|
|
<input
|