refactor: AllPermission -> ALL_PERMISSION

pull/146/merge
moonrailgun 2 years ago
parent 33f207353b
commit 97dfd40bf1

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

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

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

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

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

Loading…
Cancel
Save