{_t("Make sure the right people have access to %(name)s", {
name: justCreatedOpts?.createOpts?.name || space.name,
})}
{
onFinished(false);
}}
>
{_t("Just me")}
{_t("A private space to organise your rooms")}
{
onFinished(true);
}}
>
{_t("Me and my teammates")}
{_t("A private space for you and your teammates")}
);
};
const validateEmailRules = withValidation({
rules: [
{
key: "email",
test: ({ value }) => !value || Email.looksValid(value),
invalid: () => _t("Doesn't look like a valid email address"),
},
],
});
const SpaceSetupPrivateInvite: React.FC<{
space: Room;
onFinished(): void;
}> = ({ space, onFinished }) => {
const [busy, setBusy] = useState(false);
const [error, setError] = useState("");
const numFields = 3;
const fieldRefs = [useRef(), useRef(), useRef()] as RefObject[];
const [emailAddresses, setEmailAddress] = useStateArray(numFields, "");
const fields = new Array(numFields).fill(0).map((x, i) => {
const name = "emailAddress" + i;
return (
) => setEmailAddress(i, ev.target.value)}
ref={fieldRefs[i]}
onValidate={validateEmailRules}
autoFocus={i === 0}
disabled={busy}
/>
);
});
const onNextClick = async (ev: ButtonEvent): Promise => {
ev.preventDefault();
if (busy) return;
setError("");
for (const fieldRef of fieldRefs) {
const valid = await fieldRef.current?.validate({ allowEmpty: true });
if (valid === false) {
// true/null are allowed
fieldRef.current!.focus();
fieldRef.current!.validate({ allowEmpty: true, focused: true });
return;
}
}
setBusy(true);
const targetIds = emailAddresses.map((name) => name.trim()).filter(Boolean);
try {
const result = await inviteMultipleToRoom(space.roomId, targetIds);
const failedUsers = Object.keys(result.states).filter((a) => result.states[a] === "error");
if (failedUsers.length > 0) {
logger.log("Failed to invite users to space: ", result);
setError(
_t("Failed to invite the following users to your space: %(csvUsers)s", {
csvUsers: failedUsers.join(", "),
}),
);
} else {
onFinished();
}
} catch (err) {
logger.error("Failed to invite users to space: ", err);
setError(_t("We couldn't invite those users. Please check the users you want to invite and try again."));
}
setBusy(false);
};
let onClick = (ev: ButtonEvent): void => {
ev.preventDefault();
onFinished();
};
let buttonLabel = _t("Skip for now");
if (emailAddresses.some((name) => name.trim())) {
onClick = onNextClick;
buttonLabel = busy ? _t("Inviting…") : _t("Continue");
}
return (
{_t("Invite your teammates")}
{_t("Make sure the right people have access. You can invite more later.")}
{_t(
"This is an experimental feature. For now, " +
"new users receiving an invite will have to open the invite on to actually join.",
{},
{
b: (sub) => {sub},
link: () => (
app.element.io
),
},
)}
{error &&
{error}
}
showRoomInviteDialog(space.roomId)}
>
{_t("Invite by username")}