Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: multiple use invite links (#9813)
- Loading branch information
1 parent
6b7a2d6
commit 3094459
Showing
48 changed files
with
1,273 additions
and
344 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
app/assets/javascripts/discourse/app/components/invite-link-panel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import I18n from "I18n"; | ||
import Component from "@ember/component"; | ||
import Group from "discourse/models/group"; | ||
import { readOnly } from "@ember/object/computed"; | ||
import { action } from "@ember/object"; | ||
import discourseComputed from "discourse-common/utils/decorators"; | ||
import Invite from "discourse/models/invite"; | ||
|
||
export default Component.extend({ | ||
inviteModel: readOnly("panel.model.inviteModel"), | ||
userInvitedShow: readOnly("panel.model.userInvitedShow"), | ||
isStaff: readOnly("currentUser.staff"), | ||
maxRedemptionAllowed: 5, | ||
inviteExpiresAt: moment() | ||
.add(1, "month") | ||
.format("YYYY-MM-DD"), | ||
|
||
willDestroyElement() { | ||
this._super(...arguments); | ||
|
||
this.reset(); | ||
}, | ||
|
||
@discourseComputed("isStaff", "inviteModel.saving", "maxRedemptionAllowed") | ||
disabled(isStaff, saving, canInviteTo, maxRedemptionAllowed) { | ||
if (saving) return true; | ||
if (!isStaff) return true; | ||
if (maxRedemptionAllowed < 2) return true; | ||
|
||
return false; | ||
}, | ||
|
||
groupFinder(term) { | ||
return Group.findAll({ term, ignore_automatic: true }); | ||
}, | ||
|
||
errorMessage: I18n.t("user.invited.invite_link.error"), | ||
|
||
reset() { | ||
this.set("maxRedemptionAllowed", 5); | ||
|
||
this.inviteModel.setProperties({ | ||
groupNames: null, | ||
error: false, | ||
saving: false, | ||
finished: false, | ||
inviteLink: null | ||
}); | ||
}, | ||
|
||
@action | ||
generateMultipleUseInviteLink() { | ||
if (this.disabled) { | ||
return; | ||
} | ||
|
||
const groupNames = this.get("inviteModel.groupNames"); | ||
const maxRedemptionAllowed = this.maxRedemptionAllowed; | ||
const inviteExpiresAt = this.inviteExpiresAt; | ||
const userInvitedController = this.userInvitedShow; | ||
const model = this.inviteModel; | ||
model.setProperties({ saving: true, error: false }); | ||
|
||
return model | ||
.generateMultipleUseInviteLink( | ||
groupNames, | ||
maxRedemptionAllowed, | ||
inviteExpiresAt | ||
) | ||
.then(result => { | ||
model.setProperties({ | ||
saving: false, | ||
finished: true, | ||
inviteLink: result | ||
}); | ||
|
||
if (userInvitedController) { | ||
Invite.findInvitedBy( | ||
this.currentUser, | ||
userInvitedController.filter | ||
).then(inviteModel => { | ||
userInvitedController.setProperties({ | ||
model: inviteModel, | ||
totalInvites: inviteModel.invites.length | ||
}); | ||
}); | ||
} | ||
}) | ||
.catch(e => { | ||
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) { | ||
this.set("errorMessage", e.jqXHR.responseJSON.errors[0]); | ||
} else { | ||
this.set("errorMessage", I18n.t("user.invited.invite_link.error")); | ||
} | ||
model.setProperties({ saving: false, error: true }); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
3094459
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://meta.discourse.org/t/multiple-use-invite-links/154325
3094459
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit has been mentioned on Discourse Meta. There might be relevant details there:
https://meta.discourse.org/t/cosmetic-problem-with-invites-screen-in-brave/153613/5