diff --git a/src/app/components/user-profile/UserModeration.tsx b/src/app/components/user-profile/UserModeration.tsx new file mode 100644 index 00000000..97837085 --- /dev/null +++ b/src/app/components/user-profile/UserModeration.tsx @@ -0,0 +1,127 @@ +import { Box, Button, color, config, Icon, Icons, MenuItem, Spinner, Text } from 'folds'; +import React, { useCallback } from 'react'; +import { useRoom } from '../../hooks/useRoom'; +import { SequenceCard } from '../sequence-card'; +import { CutoutCard } from '../cutout-card'; +import { SettingTile } from '../setting-tile'; +import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback'; +import { useMatrixClient } from '../../hooks/useMatrixClient'; +import { BreakWord } from '../../styles/Text.css'; +import { useSetting } from '../../state/hooks/settings'; +import { settingsAtom } from '../../state/settings'; +import { timeDayMonYear, timeHourMinute } from '../../utils/time'; + +type UserBanAlertProps = { + userId: string; + reason?: string; + canUnban?: boolean; + bannedBy?: string; + ts?: number; +}; +export function UserBanAlert({ userId, reason, canUnban, bannedBy, ts }: UserBanAlertProps) { + const mx = useMatrixClient(); + const room = useRoom(); + const [hour24Clock] = useSetting(settingsAtom, 'hour24Clock'); + const [dateFormatString] = useSetting(settingsAtom, 'dateFormatString'); + + const time = ts ? timeHourMinute(ts, hour24Clock) : undefined; + const date = ts ? timeDayMonYear(ts, dateFormatString) : undefined; + + const [unbanState, unban] = useAsyncCallback( + useCallback(async () => { + await mx.unban(room.roomId, userId); + }, [mx, room, userId]) + ); + const banning = unbanState.status === AsyncStatus.Loading; + const error = unbanState.status === AsyncStatus.Error; + + return ( + + + + + Banned User + {time && date && ( + + {date} {time} + + )} + + + {bannedBy && ( + + Banned by: {bannedBy} + + )} + + {reason ? ( + <> + Reason: {reason} + + ) : ( + No Reason Provided. + )} + + + {error && ( + + {unbanState.error.message} + + )} + {canUnban && ( + + )} + + + + ); +} + +type UserModerationProps = { + userId: string; + canKick: boolean; + canBan: boolean; +}; +export function UserModeration({ userId, canKick, canBan }: UserModerationProps) { + const room = useRoom(); + + return ( + + Moderation + + } + disabled={!canKick} + > + Kick + + } + disabled={!canBan} + > + Ban + + + + ); +} diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx index 00ed31bc..7a40a622 100644 --- a/src/app/components/user-profile/UserRoomProfile.tsx +++ b/src/app/components/user-profile/UserRoomProfile.tsx @@ -1,4 +1,4 @@ -import { Box, Button, color, config, Icon, Icons, MenuItem, Spinner, Text } from 'folds'; +import { Box, Button, color, config, Icon, Icons, Spinner, Text } from 'folds'; import React, { useCallback } from 'react'; import { UserHero, UserHeroName } from './UserHero'; import { getDMRoomFor, getMxIdServer, mxcUrlToHttp } from '../../utils/matrix'; @@ -8,10 +8,7 @@ import { useMediaAuthentication } from '../../hooks/useMediaAuthentication'; import { usePowerLevels, usePowerLevelsAPI } from '../../hooks/usePowerLevels'; import { useRoom } from '../../hooks/useRoom'; import { useUserPresence } from '../../hooks/useUserPresence'; -import { SequenceCard } from '../sequence-card'; import { MutualRoomsChip, ServerChip } from './UserChips'; -import { CutoutCard } from '../cutout-card'; -import { SettingTile } from '../setting-tile'; import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback'; import { createDM } from '../../../client/action/room'; import { hasDevices } from '../../../util/matrixUtil'; @@ -19,69 +16,7 @@ import { useRoomNavigate } from '../../hooks/useRoomNavigate'; import { useAlive } from '../../hooks/useAlive'; import { useCloseUserRoomProfile } from '../../state/hooks/userRoomProfile'; import { PowerChip } from './PowerChip'; - -type UserBanAlertProps = { - userId: string; - reason?: string; -}; -function UserBanAlert({ userId, reason }: UserBanAlertProps) { - return ( - - - Unban - - } - > - - Banned User - This user has been banned!{reason ? ` Reason: ${reason}` : ''} - - - - ); -} - -type UserModerationProps = { - userId: string; - canKick: boolean; - canBan: boolean; -}; -function UserModeration({ userId, canKick, canBan }: UserModerationProps) { - const room = useRoom(); - - return ( - - Moderation - - } - disabled={!canKick} - > - Kick - - } - disabled={!canBan} - > - Ban - - - - ); -} +import { UserBanAlert, UserModeration } from './UserModeration'; type UserRoomProfileProps = { userId: string; @@ -174,7 +109,15 @@ export function UserRoomProfile({ userId }: UserRoomProfileProps) { - {member?.membership === 'ban' && } + {member?.membership === 'ban' && ( + + )} {(canKick || canBan) && ( )}