refactor: AllPermission -> ALL_PERMISSION

pull/146/merge
moonrailgun 1 year ago
parent 33f207353b
commit 97dfd40bf1

@ -254,7 +254,7 @@ export { isValidJson } from './utils/json-helper';
export { MessageHelper } from './utils/message-helper';
export {
PERMISSION,
AllPermission,
ALL_PERMISSION,
getPermissionList,
getDefaultPermissionList,
applyDefaultFallbackGroupPermission,

@ -4,7 +4,7 @@ import { model, t } from '..';
*
*
*/
export const AllPermission = Symbol('AllPermission');
export const ALL_PERMISSION = Symbol('AllPermission');
export interface PermissionItemType {
/**

@ -1,6 +1,6 @@
import { Loading } from '@/components/Loading';
import { PillTabs } from '@/components/PillTabs';
import { AllPermission } from 'tailchat-shared';
import { ALL_PERMISSION } from 'tailchat-shared';
import React, { useMemo, useState } from 'react';
import { t, useGroupInfo } from 'tailchat-shared';
import { RoleItem } from './RoleItem';
@ -14,8 +14,8 @@ interface GroupPermissionProps {
}
export const GroupRole: React.FC<GroupPermissionProps> = React.memo((props) => {
const { groupId } = props;
const [roleId, setRoleId] = useState<typeof AllPermission | string>(
AllPermission
const [roleId, setRoleId] = useState<typeof ALL_PERMISSION | string>(
ALL_PERMISSION
);
const groupInfo = useGroupInfo(groupId);
const roles = groupInfo?.roles ?? [];
@ -39,8 +39,8 @@ export const GroupRole: React.FC<GroupPermissionProps> = React.memo((props) => {
<div className="pr-2 mr-2 w-40 mobile:w-28 border-r border-white border-opacity-20">
{/* 角色列表 */}
<RoleItem
active={roleId === AllPermission}
onClick={() => setRoleId(AllPermission)}
active={roleId === ALL_PERMISSION}
onClick={() => setRoleId(ALL_PERMISSION)}
>
{t('所有人')}
</RoleItem>
@ -67,7 +67,7 @@ export const GroupRole: React.FC<GroupPermissionProps> = React.memo((props) => {
{
key: 'summary',
label: t('概述'),
disabled: roleId === AllPermission,
disabled: roleId === ALL_PERMISSION,
children: (
<>
{currentRoleInfo && (
@ -76,7 +76,7 @@ export const GroupRole: React.FC<GroupPermissionProps> = React.memo((props) => {
onChangeRoleName={handleChangeRoleName}
onDeleteRole={async () => {
await handleDeleteRole();
setRoleId(AllPermission); // 删除身份组后切换到所有人
setRoleId(ALL_PERMISSION); // 删除身份组后切换到所有人
}}
/>
)}
@ -98,7 +98,7 @@ export const GroupRole: React.FC<GroupPermissionProps> = React.memo((props) => {
{
key: 'member',
label: t('管理成员'),
disabled: roleId === AllPermission,
disabled: roleId === ALL_PERMISSION,
children: (
<>
{currentRoleInfo && (

@ -1,4 +1,4 @@
import { AllPermission, getPermissionList } from 'tailchat-shared';
import { ALL_PERMISSION, getPermissionList } from 'tailchat-shared';
import { Button } from 'antd';
import React, { useCallback, useMemo } from 'react';
import { model, t } from 'tailchat-shared';
@ -6,7 +6,7 @@ import { useModifyPermission } from '../useModifyPermission';
import { PermissionList } from '@/components/PermissionList';
interface RolePermissionProps {
roleId: typeof AllPermission | string;
roleId: typeof ALL_PERMISSION | string;
currentRoleInfo?: model.group.GroupRole;
fallbackPermissions: string[];
onSavePermission: (permissions: string[]) => Promise<void>;
@ -14,7 +14,7 @@ interface RolePermissionProps {
export const RolePermission: React.FC<RolePermissionProps> = React.memo(
(props) => {
const currentRolePermissions: string[] = useMemo(() => {
if (props.roleId === AllPermission) {
if (props.roleId === ALL_PERMISSION) {
return props.fallbackPermissions;
}

@ -1,5 +1,5 @@
import {
AllPermission,
ALL_PERMISSION,
getDefaultPermissionList,
showSuccessToasts,
} from 'tailchat-shared';
@ -7,7 +7,7 @@ import { model, t, useAsyncRequest } from 'tailchat-shared';
export function useRoleActions(
groupId: string,
roleId: typeof AllPermission | string
roleId: typeof ALL_PERMISSION | string
) {
const [{ loading: loading1 }, handleCreateRole] =
useAsyncRequest(async () => {
@ -21,7 +21,7 @@ export function useRoleActions(
const [{ loading: loading2 }, handleSavePermission] = useAsyncRequest(
async (permissions: string[]) => {
if (roleId === AllPermission) {
if (roleId === ALL_PERMISSION) {
// 所有人权限
await model.group.modifyGroupField(
groupId,
@ -44,7 +44,7 @@ export function useRoleActions(
const [{ loading: loading3 }, handleChangeRoleName] = useAsyncRequest(
async (newRoleName: string) => {
if (roleId === AllPermission) {
if (roleId === ALL_PERMISSION) {
throw new Error(t('无法修改所有人权限组的显示名称'));
}
await model.group.updateGroupRoleName(groupId, roleId, newRoleName);
@ -55,7 +55,7 @@ export function useRoleActions(
const [{ loading: loading4 }, handleDeleteRole] =
useAsyncRequest(async () => {
if (roleId === AllPermission) {
if (roleId === ALL_PERMISSION) {
throw new Error(t('无法删除所有人权限'));
}

Loading…
Cancel
Save