import React, { useCallback, useEffect, useState } from 'react'; import { defaultSupportedCommandsNameForBroadcastUse, defaultSupportedCommandsNameForSingleUse, defaultSupportedSlackEventActions } from '@growi/slack'; import { useTranslation } from 'next-i18next'; import PropTypes from 'prop-types'; import { apiv3Put } from '~/client/util/apiv3-client'; import { toastError, toastSuccess } from '~/client/util/toastr'; import loggerFactory from '~/utils/logger'; const logger = loggerFactory('growi:SlackIntegration:ManageCommandsProcess'); const PermissionTypes = { ALLOW_ALL: 'allowAll', DENY_ALL: 'denyAll', ALLOW_SPECIFIED: 'allowSpecified', }; const defaultCommandsName = [...defaultSupportedCommandsNameForBroadcastUse, ...defaultSupportedCommandsNameForSingleUse]; // A utility function that returns the new state but identical to the previous state const getUpdatedChannelsList = (commandPermissionObj, commandName, value) => { // string to array const allowedChannelsArray = value.split(','); // trim whitespace from all elements const trimedAllowedChannelsArray = allowedChannelsArray.map(channelName => channelName.trim()); commandPermissionObj[commandName] = trimedAllowedChannelsArray; return commandPermissionObj; }; // A utility function that returns the new state const getUpdatedPermissionSettings = (commandPermissionObj, commandName, value) => { const editedCommandPermissionObj = { ...commandPermissionObj }; switch (value) { case PermissionTypes.ALLOW_ALL: editedCommandPermissionObj[commandName] = true; break; case PermissionTypes.DENY_ALL: editedCommandPermissionObj[commandName] = false; break; case PermissionTypes.ALLOW_SPECIFIED: editedCommandPermissionObj[commandName] = []; break; default: logger.error('Not implemented'); break; } return editedCommandPermissionObj; }; const SinglePermissionSettingComponent = ({ commandName, editingCommandPermission, onPermissionTypeClicked, onPermissionListChanged, }) => { const { t } = useTranslation(); if (editingCommandPermission == null) { return null; } function permissionTypeClickHandler(e) { if (onPermissionTypeClicked == null) { return; } onPermissionTypeClicked(e); } function onPermissionListChangeHandler(e) { if (onPermissionListChanged == null) { return; } onPermissionListChanged(e); } const permission = editingCommandPermission[commandName]; const hiddenClass = Array.isArray(permission) ? '' : 'd-none'; const textareaDefaultValue = Array.isArray(permission) ? permission.join(',') : ''; return (

{commandName}