2021-09-17 15:34:49 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2021-09-17 15:34:49 +01:00
|
|
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2021-09-17 15:34:49 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React, { ComponentProps, useMemo, useState } from "react";
|
2023-08-04 08:36:16 +01:00
|
|
|
import { Room } from "matrix-js-sdk/src/matrix";
|
2021-09-29 16:05:03 +01:00
|
|
|
|
2021-09-17 15:34:49 +01:00
|
|
|
import ConfirmUserActionDialog from "./ConfirmUserActionDialog";
|
2021-11-11 13:07:41 +00:00
|
|
|
import SpaceStore from "../../../stores/spaces/SpaceStore";
|
2021-09-17 15:34:49 +01:00
|
|
|
import SpaceChildrenPicker from "../spaces/SpaceChildrenPicker";
|
|
|
|
|
|
|
|
|
|
type BaseProps = ComponentProps<typeof ConfirmUserActionDialog>;
|
2022-03-22 17:07:37 -06:00
|
|
|
interface IProps extends Omit<BaseProps, "matrixClient" | "children" | "onFinished"> {
|
2021-09-17 15:34:49 +01:00
|
|
|
space: Room;
|
|
|
|
|
allLabel: string;
|
|
|
|
|
specificLabel: string;
|
|
|
|
|
noneLabel?: string;
|
2021-09-17 16:02:12 +01:00
|
|
|
warningMessage?: string;
|
2023-05-16 14:25:43 +01:00
|
|
|
onFinished(success?: boolean, reason?: string, rooms?: Room[]): void;
|
2021-09-17 15:34:49 +01:00
|
|
|
spaceChildFilter?(child: Room): boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ConfirmSpaceUserActionDialog: React.FC<IProps> = ({
|
|
|
|
|
space,
|
|
|
|
|
spaceChildFilter,
|
|
|
|
|
allLabel,
|
|
|
|
|
specificLabel,
|
|
|
|
|
noneLabel,
|
2021-09-17 16:02:12 +01:00
|
|
|
warningMessage,
|
2021-09-17 15:34:49 +01:00
|
|
|
onFinished,
|
|
|
|
|
...props
|
|
|
|
|
}) => {
|
|
|
|
|
const spaceChildren = useMemo(() => {
|
|
|
|
|
const children = SpaceStore.instance.getChildren(space.roomId);
|
|
|
|
|
if (spaceChildFilter) {
|
|
|
|
|
return children.filter(spaceChildFilter);
|
|
|
|
|
}
|
|
|
|
|
return children;
|
|
|
|
|
}, [space.roomId, spaceChildFilter]);
|
|
|
|
|
|
|
|
|
|
const [roomsToLeave, setRoomsToLeave] = useState<Room[]>([]);
|
|
|
|
|
const selectedRooms = useMemo(() => new Set(roomsToLeave), [roomsToLeave]);
|
|
|
|
|
|
2023-04-13 08:52:57 +01:00
|
|
|
let warning: JSX.Element | undefined;
|
2021-09-29 16:05:03 +01:00
|
|
|
if (warningMessage) {
|
2021-09-17 16:02:12 +01:00
|
|
|
warning = <div className="mx_ConfirmSpaceUserActionDialog_warning">{warningMessage}</div>;
|
2021-09-17 15:34:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ConfirmUserActionDialog
|
|
|
|
|
{...props}
|
2023-05-16 14:25:43 +01:00
|
|
|
onFinished={(success?: boolean, reason?: string) => {
|
2021-09-17 15:34:49 +01:00
|
|
|
onFinished(success, reason, roomsToLeave);
|
|
|
|
|
}}
|
|
|
|
|
className="mx_ConfirmSpaceUserActionDialog"
|
2022-01-25 10:40:02 +01:00
|
|
|
roomId={space.roomId}
|
2021-09-17 15:34:49 +01:00
|
|
|
>
|
|
|
|
|
{warning}
|
|
|
|
|
<SpaceChildrenPicker
|
|
|
|
|
space={space}
|
|
|
|
|
spaceChildren={spaceChildren}
|
|
|
|
|
selected={selectedRooms}
|
|
|
|
|
allLabel={allLabel}
|
|
|
|
|
specificLabel={specificLabel}
|
|
|
|
|
noneLabel={noneLabel}
|
|
|
|
|
onChange={setRoomsToLeave}
|
|
|
|
|
/>
|
|
|
|
|
</ConfirmUserActionDialog>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ConfirmSpaceUserActionDialog;
|