import React from 'react'; import type { ComponentEvent, RestAction } from '../../types/project'; import { assignPageOnLoad, getPageOnLoadActionId } from './pageEventUtils'; import styles from './VisualEditor.module.css'; type Props = { events: ComponentEvent[] | undefined; actions: RestAction[]; onChange: (events: ComponentEvent[]) => void }; export default function PageEventEditor({ events, actions, onChange }: Props): React.ReactElement { const actionId = getPageOnLoadActionId(events); const enterActionId = events?.find(event => event.event === 'onEnter')?.actionId ?? ''; const setEnter = (nextActionId: string) => onChange([ ...(events ?? []).filter(event => event.event !== 'onEnter'), ...(nextActionId ? [{ event: 'onEnter', actionId: nextActionId }] : []), ]); const missingReference = actionId !== '' && !actions.some((action) => action.id === actionId); return (