FIX: when showing edit invite form, display saved invite data in fields (#24907)

https://meta.discourse.org/t/lets-talk-suggestion-for-improvement-invite-feature/284655/11?u=yigit
This commit is contained in:
marstall 2023-12-16 09:49:21 -05:00 committed by GitHub
parent e30da10486
commit 6f3c498b83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 92 additions and 10 deletions

View File

@ -48,13 +48,15 @@ export default Component.extend(bufferedProperty("invite"), {
this.set("topics", this.invite?.topics || this.model.topics || []);
this.buffered.setProperties({
max_redemptions_allowed: 1,
expires_at: moment()
.add(this.siteSettings.invite_expiry_days, "days")
.format(FORMAT),
groupIds: this.model?.groupIds,
topicId: this.model.topicId,
topicTitle: this.model.topicTitle,
max_redemptions_allowed: this.model.invite?.max_redemptions_allowed ?? 1,
expires_at:
this.model.invite?.expires_at ??
moment()
.add(this.siteSettings.invite_expiry_days, "days")
.format(FORMAT),
groupIds: this.model.invite?.groupIds,
topicId: this.model.invite?.topicId,
topicTitle: this.model.invite?.topicTitle,
});
},

View File

@ -58,13 +58,13 @@ acceptance("Invites - Create & Edit Invite Modal", function (needs) {
assert
.dom("table.user-invite-list tbody tr")
.exists({ count: 2 }, "is seeded with two rows");
.exists({ count: 3 }, "is seeded with three rows");
await click(".btn-primary");
assert
.dom("table.user-invite-list tbody tr")
.exists({ count: 3 }, "gets added to the list");
.exists({ count: 4 }, "gets added to the list");
});
test("copying saves invite", async function (assert) {
@ -242,3 +242,34 @@ acceptance(
});
}
);
acceptance(
"Invites - Populates Edit Invite Form with saved invite data",
function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.get("/groups/search.json", () => {
return helper.response([
{
id: 41,
automatic: false,
name: "Macdonald",
},
]);
});
});
test("shows correct saved data in form", async function (assert) {
await visit("/u/eviltrout/invited/pending");
await click(
".user-invite-list tbody tr:nth-child(3) .invite-actions .btn:first-child"
); // third invite edit button
assert.dom("#invite-max-redemptions").hasValue("10");
assert
.dom(".invite-to-topic .name")
.hasText("Welcome to Discourse! :wave:");
assert.dom(".invite-to-groups .formatted-selection").hasText("Macdonald");
assert.dom("#invite-email").hasValue("cat.com");
});
}
);

View File

@ -288,6 +288,7 @@ export function applyDefaultHandlers(pretender) {
updated_at: "2023-06-01T04:47:13.195Z",
expires_at: "2023-08-30T04:47:00.000Z",
expired: false,
max_redemptions_allowed: 10,
topics: [],
groups: [],
},
@ -307,6 +308,54 @@ export function applyDefaultHandlers(pretender) {
topics: [],
groups: [],
},
{
id: 10,
invite_key: "hMFT8G1oKP",
link: "http://localhost:3000/invites/hMFT8G1oKP",
email: null,
domain: "cat.com",
redemption_count: 0,
emailed: false,
can_delete_invite: true,
custom_message: null,
created_at: "2023-06-01T04:47:13.195Z",
updated_at: "2023-06-01T04:47:13.195Z",
expires_at: "2023-08-30T04:47:00.000Z",
expired: false,
max_redemptions_allowed: 10,
topics: [
{
id: 5,
title: "Welcome to Discourse! :wave:",
fancy_title: "Welcome to Discourse! :wave:",
slug: "welcome-to-discourse",
posts_count: 1,
},
],
groups: [
{
id: 41,
automatic: false,
name: "discourse",
user_count: 0,
alias_level: 0,
visible: true,
automatic_membership_email_domains: "",
primary_group: false,
title: null,
grant_trust_level: null,
has_messages: false,
flair_url: null,
flair_bg_color: null,
flair_color: null,
bio_raw: "",
bio_cooked: null,
public_admission: true,
allow_membership_requests: false,
full_name: "Awesome Team",
},
],
},
],
can_see_invite_details: true,
counts: {

View File

@ -8,7 +8,7 @@ acceptance("User invites", function (needs) {
test("hides delete button based on can_delete_invite", async function (assert) {
await visit("/u/eviltrout/invited");
assert.dom("table.user-invite-list tbody tr").exists({ count: 2 });
assert.dom("table.user-invite-list tbody tr").exists({ count: 3 });
assert
.dom("table.user-invite-list tbody tr:nth-child(1) button.cancel")
.exists();