compose: Migrate compose_invite_users to use compose_banner.

This is part several updates for #22524.

Testing note: I removed the tests test_compose_invite_users_clicked
and test_compose_invite_close_clicked, since they heavily relied on
the old way of rendering banners and were too UI-focused (instead of
logic focused) for me to feel like it was worth testing that the
banners removed when clicking the buttons.
This commit is contained in:
evykassirer
2022-08-19 17:51:13 -07:00
committed by Tim Abbott
parent 89230ba554
commit ab5d088188
10 changed files with 81 additions and 220 deletions

View File

@@ -3,7 +3,7 @@ import $ from "jquery";
import * as resolved_topic from "../shared/js/resolved_topic";
import render_compose_all_everyone from "../templates/compose_all_everyone.hbs";
import render_compose_banner from "../templates/compose_banner/compose_banner.hbs";
import render_compose_invite_users from "../templates/compose_invite_users.hbs";
import render_not_subscribed_warning from "../templates/compose_banner/not_subscribed_warning.hbs";
import render_compose_not_subscribed from "../templates/compose_not_subscribed.hbs";
import render_compose_private_stream_alert from "../templates/compose_private_stream_alert.hbs";
@@ -140,26 +140,32 @@ export function warn_if_mentioning_unsubscribed_user(mentioned) {
}
if (needs_subscribe_warning(user_id, sub.stream_id)) {
const $error_area = $("#compose_invite_users");
const $existing_invites_area = $("#compose_invite_users .compose_invite_user");
const $existing_invites_area = $(
`#compose_banners .${compose_error.CLASSNAMES.recipient_not_subscribed}`,
);
const existing_invites = Array.from($existing_invites_area, (user_row) =>
Number.parseInt($(user_row).data("user-id"), 10),
);
const can_subscribe_other_users = settings_data.user_can_subscribe_other_users();
if (!existing_invites.includes(user_id)) {
const context = {
user_id,
stream_id: sub.stream_id,
banner_type: compose_error.WARNING,
button_text: can_subscribe_other_users
? $t({defaultMessage: "Subscribe them"})
: null,
can_subscribe_other_users,
name: mentioned.full_name,
can_subscribe_other_users: settings_data.user_can_subscribe_other_users(),
classname: compose_error.CLASSNAMES.recipient_not_subscribed,
};
const new_row = render_compose_invite_users(context);
$error_area.append(new_row);
const new_row = render_not_subscribed_warning(context);
$("#compose_banners").append(new_row);
}
$error_area.show();
}
}