fleet/website/assets/js/pages/admin/generate-license.page.js
Eric ab504d766a
Website: Update admin license generator (#13101)
Closes: https://github.com/fleetdm/confidential/issues/3230

Changes:
- Added a new (optional) input to the admin license key generator:
`partnerName`.
- Renamed `admin/generate-license-key.js` to
`admin/build-license-key.js`, updated routes and regenerated
`cloud.setup.js`
- Updated the create license key helper to add a `partner` field to the
generated license key if `partnerName` is provided.
2023-08-04 14:48:29 -05:00

75 lines
2.7 KiB
JavaScript
Vendored

parasails.registerPage('generate-license', {
// ╦╔╗╔╦╔╦╗╦╔═╗╦ ╔═╗╔╦╗╔═╗╔╦╗╔═╗
// ║║║║║ ║ ║╠═╣║ ╚═╗ ║ ╠═╣ ║ ║╣
// ╩╝╚╝╩ ╩ ╩╩ ╩╩═╝ ╚═╝ ╩ ╩ ╩ ╩ ╚═╝
data: {
// Form data
formData: {},
// For tracking client-side validation errors in our form.
// > Has property set to `true` for each invalid property in `formData`.
formErrors: {},
// Form rules
formRules: {
numberOfHosts: {required: true},
organization: {required: true},
expiresAt: {required: true},
},
// Syncing / loading state
syncing: false,
// Server error state
cloudError: '',
generatedLicenseKey: '',
showResult: false,
},
// ╦ ╦╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╔═╗
// ║ ║╠╣ ║╣ ║ ╚╦╝║ ║ ║╣
// ╩═╝╩╚ ╚═╝╚═╝ ╩ ╚═╝╩═╝╚═╝
beforeMount: function() {
// Get a formatted date string for year from today's date.
let oneYearFromNowDateString = moment(Date.now() + (365*24*60*60*1000)).format('YYYY-MM-DD');
// Set the starting value for the validTo input
this.formData.expiresAt = oneYearFromNowDateString;
},
mounted: async function() {
//…
},
// ╦╔╗╔╔╦╗╔═╗╦═╗╔═╗╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
// ║║║║ ║ ║╣ ╠╦╝╠═╣║ ║ ║║ ║║║║╚═╗
// ╩╝╚╝ ╩ ╚═╝╩╚═╩ ╩╚═╝ ╩ ╩╚═╝╝╚╝╚═╝
methods: {
handleSubmittingForm: async function() {
let validToDate = new Date(this.formData.expiresAt);
let licenseExpiresAt = validToDate.getTime();
this.generatedLicenseKey = await Cloud.buildLicenseKey.with({
numberOfHosts: this.formData.numberOfHosts,
organization: this.formData.organization,
expiresAt: licenseExpiresAt,
partnerName: this.formData.partnerName,
});
},
submittedQuoteForm: async function() {
this.syncing = false;
this.showResult = true;
},
clickCopyLicenseKey: function(){
$('[purpose="copied-notification"]').finish();
$('[purpose="copied-notification"]').fadeIn(100).delay(2000).fadeOut(500);
// https://caniuse.com/mdn-api_clipboard_writetext
navigator.clipboard.writeText(this.generatedLicenseKey);
},
clickClearFormFields: async function() {
this.generatedLicenseKey = '';
this.showResult = false;
this.formErrors = {};
this.formData = {};
this.formData.validTo = moment(Date.now() + (365*24*60*60*1000)).format('YYYY-MM-DD');
await this.forceRender();
}
}
});