11'use client' ;
22
33import type { CreateAMABody } from '@chatsift/api' ;
4+ import { ChannelType } from 'discord-api-types/v10' ;
45import { useParams , useRouter } from 'next/navigation' ;
56import { useState } from 'react' ;
67import { NormalPromptFields } from './NormalPromptFields' ;
78import { PromptModeToggle } from './PromptModeToggle' ;
89import { RawPromptField } from './RawPromptField' ;
9- import { SnowflakeInput } from './SnowflakeInput' ;
1010import { Button } from '@/components/common/Button' ;
11+ import { ChannelSelect , threadTypes } from '@/components/common/ChannelSelect' ;
12+ import { Skeleton } from '@/components/common/Skeleton' ;
1113import { client } from '@/data/client' ;
1214import { APIError } from '@/utils/fetcher' ;
1315
@@ -29,20 +31,6 @@ interface FormData {
2931
3032type FormErrors = Partial < Record < keyof FormData , string > > ;
3133
32- const SNOWFLAKE_REGEX = / ^ \d { 17 , 20 } $ / ;
33-
34- function validateSnowflake ( value : string , required : boolean = true ) : string | undefined {
35- if ( ! value ) {
36- return required ? 'This field is required' : undefined ;
37- }
38-
39- if ( ! SNOWFLAKE_REGEX . test ( value ) ) {
40- return 'Must be a valid Discord ID (17-20 digits)' ;
41- }
42-
43- return undefined ;
44- }
45-
4634function validateURL ( value : string ) : string | undefined {
4735 if ( ! value ) return undefined ;
4836
@@ -75,6 +63,7 @@ export function CreateAMAForm() {
7563 } ) ;
7664 const [ errors , setErrors ] = useState < FormErrors > ( { } ) ;
7765
66+ const { data : guildInfo } = client . guilds . useInfo ( guildId , { for_bot : 'AMA' , force_fresh : 'false' } ) ;
7867 const createAMA = client . guilds . ama . createAMA ( guildId ) ;
7968
8069 const validateForm = ( ) : boolean => {
@@ -86,21 +75,13 @@ export function CreateAMAForm() {
8675 newErrors . title = 'Title must be at most 255 characters' ;
8776 }
8877
89- const answersChannelError = validateSnowflake ( formData . answersChannelId ) ;
90- if ( answersChannelError ) newErrors . answersChannelId = answersChannelError ;
91-
92- const promptChannelError = validateSnowflake ( formData . promptChannelId ) ;
93- if ( promptChannelError ) newErrors . promptChannelId = promptChannelError ;
94-
95- // Optional snowflake fields
96- const modQueueError = validateSnowflake ( formData . modQueueId , false ) ;
97- if ( modQueueError ) newErrors . modQueueId = modQueueError ;
98-
99- const flaggedQueueError = validateSnowflake ( formData . flaggedQueueId , false ) ;
100- if ( flaggedQueueError ) newErrors . flaggedQueueId = flaggedQueueError ;
78+ if ( ! formData . answersChannelId ) {
79+ newErrors . answersChannelId = 'This field is required' ;
80+ }
10181
102- const guestQueueError = validateSnowflake ( formData . guestQueueId , false ) ;
103- if ( guestQueueError ) newErrors . guestQueueId = guestQueueError ;
82+ if ( ! formData . promptChannelId ) {
83+ newErrors . promptChannelId = 'This field is required' ;
84+ }
10485
10586 // Normal mode validations
10687 if ( promptMode === 'normal' ) {
@@ -176,12 +157,31 @@ export function CreateAMAForm() {
176157 setTimeout ( ( ) => formatJSON ( ) , 50 ) ;
177158 } ;
178159
160+ if ( ! guildInfo ) {
161+ return (
162+ < div className = "mt-8 space-y-6" >
163+ < div className = "space-y-4" >
164+ < Skeleton className = "h-7 w-48" />
165+ < Skeleton className = "h-10 w-full" />
166+ < Skeleton className = "h-10 w-full" />
167+ < Skeleton className = "h-10 w-full" />
168+ < Skeleton className = "h-10 w-full" />
169+ < Skeleton className = "h-10 w-full" />
170+ < Skeleton className = "h-10 w-full" />
171+ </ div >
172+ < div className = "space-y-4" >
173+ < Skeleton className = "h-7 w-56" />
174+ < Skeleton className = "h-32 w-full" />
175+ </ div >
176+ </ div >
177+ ) ;
178+ }
179+
179180 return (
180181 < form className = "mt-8 space-y-6" onSubmit = { handleSubmit } >
181182 { /* Base Fields */ }
182183 < div className = "space-y-4" >
183184 < h2 className = "text-xl font-medium text-primary dark:text-primary-dark" > Session Details</ h2 >
184-
185185 < div >
186186 < label className = "block text-sm font-medium text-secondary dark:text-secondary-dark mb-2" htmlFor = "title" >
187187 Title *
@@ -197,46 +197,56 @@ export function CreateAMAForm() {
197197 />
198198 { errors . title && < p className = "mt-1 text-sm text-misc-danger" > { errors . title } </ p > }
199199 </ div >
200-
201- < SnowflakeInput
200+ < ChannelSelect
201+ allowedTypes = { [ ChannelType . GuildText , ChannelType . GuildAnnouncement , ...threadTypes ] }
202+ channels = { guildInfo . channels }
202203 error = { errors . answersChannelId }
203- id = "answersChannelId"
204- label = "Answers Channel ID"
204+ label = "Answers Channel"
205205 onChange = { ( value ) => setFormData ( { ...formData , answersChannelId : value } ) }
206+ placeholder = "Select the channel where answers will be posted"
206207 required
208+ selectedId = "answersChannelId"
207209 value = { formData . answersChannelId }
208- />
209-
210- < SnowflakeInput
210+ /> { ' ' }
211+ < ChannelSelect
212+ allowedTypes = { [ ChannelType . GuildText , ChannelType . GuildAnnouncement ] }
213+ channels = { guildInfo . channels }
211214 error = { errors . promptChannelId }
212- id = "promptChannelId"
213- label = "Prompt Channel ID"
215+ label = "Prompt Channel"
214216 onChange = { ( value ) => setFormData ( { ...formData , promptChannelId : value } ) }
217+ placeholder = "Select the channel where the prompt will be posted"
215218 required
219+ selectedId = "promptChannelId"
216220 value = { formData . promptChannelId }
217- />
218-
219- < SnowflakeInput
221+ /> { ' ' }
222+ < ChannelSelect
223+ allowedTypes = { [ ChannelType . GuildText , ChannelType . GuildAnnouncement ] }
224+ channels = { guildInfo . channels }
220225 error = { errors . modQueueId }
221- id = "modQueueId"
222- label = "Mod Queue ID (optional)"
226+ label = "Mod Queue (optional)"
223227 onChange = { ( value ) => setFormData ( { ...formData , modQueueId : value } ) }
228+ placeholder = "Select a channel for mod queue"
229+ selectedId = "modQueueId"
224230 value = { formData . modQueueId }
225- />
226-
227- < SnowflakeInput
231+ /> { ' ' }
232+ < ChannelSelect
233+ allowedTypes = { [ ChannelType . GuildText , ChannelType . GuildAnnouncement ] }
234+ channels = { guildInfo . channels }
228235 error = { errors . flaggedQueueId }
229- id = "flaggedQueueId"
230- label = "Flagged Queue ID (optional)"
236+ label = "Flagged Queue (optional)"
231237 onChange = { ( value ) => setFormData ( { ...formData , flaggedQueueId : value } ) }
238+ placeholder = "Select a channel for flagged questions"
239+ selectedId = "flaggedQueueId"
232240 value = { formData . flaggedQueueId }
233- />
234-
235- < SnowflakeInput
241+ /> { ' ' }
242+ < ChannelSelect
243+ allowedTypes = { [ ChannelType . GuildText , ChannelType . GuildAnnouncement ] }
244+ channels = { guildInfo . channels }
236245 error = { errors . guestQueueId }
237- id = "guestQueueId"
238- label = "Guest Queue ID (optional)"
246+ label = "Guest Queue (optional)"
239247 onChange = { ( value ) => setFormData ( { ...formData , guestQueueId : value } ) }
248+ placeholder = "Select a channel for guest queue"
249+ selectedId = "guestQueueId"
240250 value = { formData . guestQueueId }
241251 />
242252 </ div >
0 commit comments