Fix ticket category saving and synchronization error handling
- Updated the ticket category saving logic to handle empty description and emoji fields, ensuring they are set to null if trimmed. - Enhanced error handling in the `maybeSyncTicketPanel` function to prevent UI errors when synchronization fails, allowing category CRUD operations to succeed. - Updated the response handling to include support role IDs in the UI after saving, improving data consistency. - Added validation for support role IDs in the dashboard schemas to ensure correct data types are used.
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
SuggestionActionSchema,
|
||||
TagDashboardCreateSchema,
|
||||
TicketCategoryDashboardCreateSchema,
|
||||
TicketCategoryDashboardUpdateSchema,
|
||||
TicketConfigDashboardPatchSchema,
|
||||
WelcomeConfigDashboardPatchSchema
|
||||
} from './dashboard.js';
|
||||
@@ -99,6 +100,22 @@ describe('dashboard schemas', () => {
|
||||
expect(parsed.supportRoleIds).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('validates ticket category update with support roles', () => {
|
||||
const parsed = TicketCategoryDashboardUpdateSchema.parse({
|
||||
supportRoleIds: ['123456789012345678', '234567890123456789']
|
||||
});
|
||||
expect(parsed.supportRoleIds).toEqual(['123456789012345678', '234567890123456789']);
|
||||
});
|
||||
|
||||
it('rejects invalid support role ids on ticket category create', () => {
|
||||
expect(() =>
|
||||
TicketCategoryDashboardCreateSchema.parse({
|
||||
name: 'Support',
|
||||
supportRoleIds: ['not-a-snowflake']
|
||||
})
|
||||
).toThrow();
|
||||
});
|
||||
|
||||
it('validates giveaway creation input', () => {
|
||||
const parsed = GiveawayCreateDashboardSchema.parse({
|
||||
channelId: '123456789012345678',
|
||||
|
||||
@@ -403,7 +403,7 @@ export const TicketCategoryDashboardSchema = z.object({
|
||||
name: z.string().min(1).max(100),
|
||||
description: z.string().max(500).nullable().optional(),
|
||||
emoji: z.string().max(80).nullable().optional(),
|
||||
supportRoleIds: z.array(z.string())
|
||||
supportRoleIds: z.array(SnowflakeSchema)
|
||||
});
|
||||
export type TicketCategoryDashboard = z.infer<typeof TicketCategoryDashboardSchema>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user