DEV: Update create-invite-uploader uppy usage (#29282)

This commit is contained in:
David Taylor 2024-10-21 14:42:48 +01:00 committed by GitHub
parent c90fe2666f
commit 4dabdd38db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 27 deletions

View File

@ -5,7 +5,7 @@
uploadProgress=this.uploadProgress
uploaded=this.uploaded
submitDisabled=this.submitDisabled
startUpload=(action "startUpload")
startUpload=this.startUpload
)
this.setElement
this.uppyUpload.setup
}}

View File

@ -1,40 +1,34 @@
import Component from "@ember/component";
import { action } from "@ember/object";
import { getOwner } from "@ember/owner";
import { tagName } from "@ember-decorators/component";
import UppyUploadMixin from "discourse/mixins/uppy-upload";
import UppyUpload from "discourse/lib/uppy/uppy-upload";
import discourseComputed from "discourse-common/utils/decorators";
@tagName("div")
export default class CreateInviteUploader extends Component.extend(
UppyUploadMixin
) {
id = "create-invite-uploader";
type = "csv";
autoStartUploads = false;
uploadUrl = "/invites/upload_csv";
preventDirectS3Uploads = true;
fileInputSelector = "#csv-file";
export default class CreateInviteUploader extends Component {
uppyUpload = new UppyUpload(getOwner(this), {
id: "create-invite-uploader",
type: "csv",
autoStartUploads: false,
uploadUrl: "/invites/upload_csv",
preventDirectS3Uploads: true,
validateUploadedFilesOptions: {
bypassNewUserRestriction: true,
csvOnly: true,
},
uploadDone: () => {
this.set("uploaded", true);
},
});
validateUploadedFilesOptions() {
return { bypassNewUserRestriction: true, csvOnly: true };
}
@discourseComputed("filesAwaitingUpload", "uploading")
@discourseComputed("uppyUpload.filesAwaitingUpload", "uppyUpload.uploading")
submitDisabled(filesAwaitingUpload, uploading) {
return !filesAwaitingUpload || uploading;
}
uploadDone() {
this.set("uploaded", true);
}
@action
startUpload() {
this._startUpload();
}
@action
setElement(element) {
this.uppyUpload.setup(element);
this.uppyUpload.startUpload();
}
}