From bcd02b1dead34f2c674a2c9f90a8e03aecb9198b Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 20 Jan 2024 21:08:51 +0000 Subject: [PATCH] fix: only send value if not empty (closes #458) --- src/buttons/edit.js | 44 ++++++++++++++++++-------------------- src/lib/tickets/manager.js | 22 +++++++++---------- 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/buttons/edit.js b/src/buttons/edit.js index 510bc107b..914225c17 100644 --- a/src/buttons/edit.js +++ b/src/buttons/edit.js @@ -36,6 +36,15 @@ module.exports = class EditButton extends Button { const getMessage = client.i18n.getLocale(ticket.guild.locale); if (ticket.questionAnswers.length === 0) { + const field = new TextInputBuilder() + .setCustomId('topic') + .setLabel(getMessage('modals.topic.label')) + .setStyle(TextInputStyle.Paragraph) + .setMaxLength(1000) + .setMinLength(5) + .setPlaceholder(getMessage('modals.topic.placeholder')) + .setRequired(true); + if (ticket.topic) field.setValue(cryptr.decrypt(ticket.topic)); await interaction.showModal( new ModalBuilder() .setCustomId(JSON.stringify({ @@ -45,17 +54,7 @@ module.exports = class EditButton extends Button { .setTitle(ticket.category.name) .setComponents( new ActionRowBuilder() - .setComponents( - new TextInputBuilder() - .setCustomId('topic') - .setLabel(getMessage('modals.topic.label')) - .setStyle(TextInputStyle.Paragraph) - .setMaxLength(1000) - .setMinLength(5) - .setPlaceholder(getMessage('modals.topic.placeholder')) - .setRequired(true) - .setValue(ticket.topic ? cryptr.decrypt(ticket.topic) : ''), - ), + .setComponents(field), ), ); } else { @@ -71,18 +70,17 @@ module.exports = class EditButton extends Button { .filter(a => a.question.type === 'TEXT') // TODO: remove this when modals support select menus .map(a => { if (a.question.type === 'TEXT') { - return new ActionRowBuilder() - .setComponents( - new TextInputBuilder() - .setCustomId(String(a.id)) - .setLabel(a.question.label) - .setStyle(a.question.style) - .setMaxLength(Math.min(a.question.maxLength, 1000)) - .setMinLength(a.question.minLength) - .setPlaceholder(a.question.placeholder) - .setRequired(a.question.required) - .setValue(a.value ? cryptr.decrypt(a.value) : a.question.value), - ); + const field = new TextInputBuilder() + .setCustomId(String(a.id)) + .setLabel(a.question.label) + .setStyle(a.question.style) + .setMaxLength(Math.min(a.question.maxLength, 1000)) + .setMinLength(a.question.minLength) + .setPlaceholder(a.question.placeholder) + .setRequired(a.question.required); + if (a.value) field.setValue(cryptr.decrypt(a.value)); + else if (a.question.value) field.setValue(a.question.value); + return new ActionRowBuilder().setComponents(field); } else if (a.question.type === 'MENU') { return new ActionRowBuilder() .setComponents( diff --git a/src/lib/tickets/manager.js b/src/lib/tickets/manager.js index ad51628c0..06dbaa0c7 100644 --- a/src/lib/tickets/manager.js +++ b/src/lib/tickets/manager.js @@ -285,18 +285,16 @@ module.exports = class TicketManager { .filter(q => q.type === 'TEXT') // TODO: remove this when modals support select menus .map(q => { if (q.type === 'TEXT') { - return new ActionRowBuilder() - .setComponents( - new TextInputBuilder() - .setCustomId(q.id) - .setLabel(q.label) - .setStyle(q.style) - .setMaxLength(Math.min(q.maxLength, 1000)) - .setMinLength(q.minLength) - .setPlaceholder(q.placeholder) - .setRequired(q.required) - .setValue(q.value), - ); + const field = new TextInputBuilder() + .setCustomId(q.id) + .setLabel(q.label) + .setStyle(q.style) + .setMaxLength(Math.min(q.maxLength, 1000)) + .setMinLength(q.minLength) + .setPlaceholder(q.placeholder) + .setRequired(q.required); + if (q.value) field.setValue(q.value); + return new ActionRowBuilder().setComponents(field); } else if (q.type === 'MENU') { return new ActionRowBuilder() .setComponents(