Skip to content

Commit

Permalink
refactor(thread-ticketing): skip to ticket modal if one category (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarelessInternet authored Mar 9, 2024
1 parent b153e8b commit 234f8c2
Show file tree
Hide file tree
Showing 17 changed files with 270 additions and 145 deletions.
5 changes: 1 addition & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@

// Update the 'dockerComposeFile' list if you have more compose files or use different names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
"dockerComposeFile": [
"../base-compose.yaml",
"docker-compose.yaml"
],
"dockerComposeFile": ["docker-compose.yaml"],

// The 'service' property is the name of the service for the container that VS Code should
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
Expand Down
8 changes: 7 additions & 1 deletion .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ version: '3.8'
services:
database:
container_name: ticketer-development-database
extends:
file: ../base-compose.yaml
service: database
networks:
- ticketer-development-database-network
volumes:
Expand All @@ -22,9 +25,12 @@ services:
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
# array). The sample below assumes your primary file is in the root of your project.
container_name: ticketer-development-bot
extends:
file: ../base-compose.yaml
service: bot
build:
context: .
dockerfile: .devcontainer/bot/Dockerfile
dockerfile: ./bot/Dockerfile
image: ticketer-bot:development
depends_on:
database:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ export default class extends Command.Interaction {
.delete(ticketThreadsCategories)
.where(sql`${ticketThreadsCategories.id} = ${id} RETURNING ${ticketThreadsCategories.categoryTitle}`);

const title = (query[0] as unknown as Pick<typeof ticketThreadsCategories.$inferSelect, 'categoryTitle'>[]).at(
const title = (query.at(0) as unknown as Pick<typeof ticketThreadsCategories.$inferSelect, 'categoryTitle'>[]).at(
0,
)?.categoryTitle;

Expand Down
51 changes: 36 additions & 15 deletions apps/bot/src/commands/thread-ticketing/proxy-ticket-chat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Command, DeferReply } from '@ticketer/djs-framework';
import { Command } from '@ticketer/djs-framework';
import { PermissionFlagsBits } from 'discord.js';
import { ThreadTicketing } from '@/utils';
import { translate } from '@/i18n';
Expand All @@ -16,29 +16,50 @@ export default class extends Command.Interaction {
.setRequired(true),
);

@DeferReply({ ephemeral: true })
public async execute({ interaction }: Command.Context<'chat'>) {
const user = interaction.options.getUser('member', true);
const list = await ThreadTicketing.categoryList({
customId: super.customId('ticket_threads_categories_create_list_proxy', user.id),
const categories = await ThreadTicketing.categoryList({
filterManagerIds: [...interaction.member.roles.cache.keys()],
guildId: interaction.guildId,
locale: interaction.locale,
});

if (!list) {
if (categories.length === 0) {
const translations = translate(interaction.locale).tickets.threads.categories.createTicket.errors.noCategories;

return interaction.editReply({
embeds: [
super
.userEmbedError(interaction.user)
.setTitle(translations.title())
.setDescription(translations.description()),
],
});
return interaction
.reply({
embeds: [
super
.userEmbedError(interaction.user)
.setTitle(translations.title())
.setDescription(translations.description()),
],
ephemeral: true,
})
.catch(() => false);
}

return interaction.editReply({ components: [list] });
if (categories.length === 1) {
void interaction.showModal(
ThreadTicketing.ticketModal.call(this, {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
categoryId: categories.at(0)!.id,
locale: interaction.locale,
}),
);
} else {
return interaction
.reply({
components: [
ThreadTicketing.categoryListSelectMenu({
categories,
customId: super.customId('ticket_threads_categories_create_list_proxy', user.id),
locale: interaction.locale,
}),
],
ephemeral: true,
})
.catch(() => false);
}
}
}
51 changes: 36 additions & 15 deletions apps/bot/src/commands/thread-ticketing/proxy-ticket-user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Command, DeferReply } from '@ticketer/djs-framework';
import { Command } from '@ticketer/djs-framework';
import { PermissionFlagsBits } from 'discord.js';
import { ThreadTicketing } from '@/utils';
import { translate } from '@/i18n';
Expand All @@ -10,29 +10,50 @@ export default class extends Command.Interaction {
PermissionFlagsBits.ManageThreads,
);

@DeferReply({ ephemeral: true })
public async execute({ interaction }: Command.Context<'user'>) {
const user = interaction.targetUser;
const list = await ThreadTicketing.categoryList({
customId: super.customId('ticket_threads_categories_create_list_proxy', user.id),
const categories = await ThreadTicketing.categoryList({
filterManagerIds: [...interaction.member.roles.cache.keys()],
guildId: interaction.guildId,
locale: interaction.locale,
});

if (!list) {
if (categories.length === 0) {
const translations = translate(interaction.locale).tickets.threads.categories.createTicket.errors.noCategories;

return interaction.editReply({
embeds: [
super
.userEmbedError(interaction.user)
.setTitle(translations.title())
.setDescription(translations.description()),
],
});
return interaction
.reply({
embeds: [
super
.userEmbedError(interaction.user)
.setTitle(translations.title())
.setDescription(translations.description()),
],
ephemeral: true,
})
.catch(() => false);
}

return interaction.editReply({ components: [list] });
if (categories.length === 1) {
void interaction.showModal(
ThreadTicketing.ticketModal.call(this, {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
categoryId: categories.at(0)!.id,
locale: interaction.locale,
}),
);
} else {
return interaction
.reply({
components: [
ThreadTicketing.categoryListSelectMenu({
categories,
customId: super.customId('ticket_threads_categories_create_list_proxy', user.id),
locale: interaction.locale,
}),
],
ephemeral: true,
})
.catch(() => false);
}
}
}
Loading

0 comments on commit 234f8c2

Please sign in to comment.