@@ -30,7 +30,7 @@ export default function PlaygroundPage() {
3030 const { status } = useSession ( ) ;
3131 const router = useRouter ( ) ;
3232 const { data : destinations , loading : destinationsLoading , error : destinationsError } = useDestinations ( ) ;
33- const { data : topics , loading : topicsLoading , error : topicsError } = useTopics ( ) ;
33+ const { loading : topicsLoading , error : topicsError } = useTopics ( ) ;
3434 const [ formData , setFormData ] = useState < FormData > ( {
3535 destinationId : "" ,
3636 topic : "" ,
@@ -55,6 +55,26 @@ export default function PlaygroundPage() {
5555 }
5656 } , [ status , router ] ) ;
5757
58+ // Get the currently selected destination
59+ const selectedDestination = destinations . find (
60+ ( dest ) => dest . id === formData . destinationId
61+ ) ;
62+
63+ // Get available topics for the selected destination
64+ const availableTopics = selectedDestination ?. topics || [ ] ;
65+
66+ // Clear topic selection when destination changes if current topic is not available
67+ useEffect ( ( ) => {
68+ if (
69+ formData . destinationId &&
70+ formData . topic &&
71+ selectedDestination &&
72+ ! selectedDestination . topics . includes ( formData . topic )
73+ ) {
74+ setFormData ( ( prev ) => ( { ...prev , topic : "" } ) ) ;
75+ }
76+ } , [ formData . destinationId , formData . topic , selectedDestination ] ) ;
77+
5878 const validateForm = ( ) : boolean => {
5979 const errors : Partial < FormData > = { } ;
6080
@@ -64,6 +84,8 @@ export default function PlaygroundPage() {
6484
6585 if ( ! formData . topic . trim ( ) ) {
6686 errors . topic = "Topic is required" ;
87+ } else if ( selectedDestination && ! selectedDestination . topics . includes ( formData . topic ) ) {
88+ errors . topic = "Selected topic is not available for this destination" ;
6789 }
6890
6991 if ( ! formData . eventData . trim ( ) ) {
@@ -240,23 +262,23 @@ export default function PlaygroundPage() {
240262 className = {
241263 formErrors . topic ? "border-red-300" : ""
242264 }
243- disabled = { topicsLoading }
265+ disabled = { topicsLoading || ! formData . destinationId }
244266 >
245267 < option value = "" >
246268 { topicsLoading
247269 ? "Loading topics..."
270+ : ! formData . destinationId
271+ ? "Select a destination first"
272+ : availableTopics . length === 0
273+ ? "No topics available for this destination"
248274 : "Select a topic" }
249275 </ option >
250- { topics . map ( ( topic ) => (
251- < option key = { topic } value = { topic } >
252- { topic }
253- </ option >
254- ) ) }
255- { topics . length === 0 && ! topicsLoading && (
256- < option value = "" disabled >
257- No topics available
258- </ option >
259- ) }
276+ { formData . destinationId &&
277+ availableTopics . map ( ( topic ) => (
278+ < option key = { topic } value = { topic } >
279+ { topic }
280+ </ option >
281+ ) ) }
260282 </ Select >
261283 { formErrors . topic && (
262284 < p className = "mt-1 text-sm text-red-600" > { formErrors . topic } </ p >
@@ -266,6 +288,11 @@ export default function PlaygroundPage() {
266288 Failed to load topics: { topicsError }
267289 </ p >
268290 ) }
291+ { formData . destinationId && availableTopics . length === 0 && ! topicsLoading && (
292+ < p className = "mt-1 text-sm text-amber-600" >
293+ This destination is not subscribed to any topics. Configure topics in the destination settings.
294+ </ p >
295+ ) }
269296 </ div >
270297
271298 { /* JSON Payload Editor */ }
0 commit comments