diff --git a/web/src/features/AppUi/Components/AppHostActionDialog.tsx b/web/src/features/AppUi/Components/AppHostActionDialog.tsx index 27635b831..5c87e572b 100644 --- a/web/src/features/AppUi/Components/AppHostActionDialog.tsx +++ b/web/src/features/AppUi/Components/AppHostActionDialog.tsx @@ -1,44 +1,71 @@ +import { useMemo, useState } from 'react' + import { buttonClassName } from '@/shared/Buttons/buttonStyles.ts' import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts' import { Modal } from '@/shared/Modal/index.tsx' import AppUiFrame from '../AppUiFrame.tsx' +import { AppDialogSurfaceContext } from '../appDialogSurfaceContext.ts' import useAppHostActionDialogLogic from '../Hooks/useAppHostActionDialogLogic.ts' import type { AppHostActionDialogProps } from '../Types/app-host-table.types.ts' +import type { AppDialogChrome } from '../Types/app-dialog-surface.types.ts' -/** A host row action of an app, opened in a platform dialog for that host. */ +/** + * A host row action of an app, opened in a platform dialog for that host. An app drawn with the UI + * kit whose root is a dialog fills this dialog's title, navigation and footer itself. + */ export default function AppHostActionDialog(props: AppHostActionDialogProps) { const { t } = useTranslationStore() const { state, handler } = useAppHostActionDialogLogic(props) + const { onOpenChange } = props + const [chrome, setChrome] = useState(null) + const [navigation, setNavigation] = useState(null) + const [footer, setFooter] = useState(null) + const surface = useMemo( + () => ({ setChrome, navigation, footer, close: () => onOpenChange(false) }), + [footer, navigation, onOpenChange], + ) + // The user closed the dialog: the app's root dialog hears of it before the platform closes it. + const close = () => { + chrome?.onClose() + onOpenChange(false) + } return ( { + if (open) onOpenChange(true) + else close() + }} + closeDisabled={chrome?.closeDisabled ?? false} + title={chrome?.heading ?? state.title ?? t('appUi.unavailable')} + description={chrome?.description ?? props.hostDomains.join(', ')} size="xl" fixedHeight height="tall" + navigation={chrome?.navigation ?
: undefined} footer={ - + chrome?.footer ? ( +
+ ) : ( + + ) } > {state.app && state.route ? ( -
- +
+ + +
) : ( {t('appUi.unavailable')} diff --git a/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteActionElements.tsx b/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteActionElements.tsx index bf37e41ba..dca173ef0 100644 --- a/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteActionElements.tsx +++ b/web/src/features/AppUi/Components/RemoteAppView/Components/RemoteActionElements.tsx @@ -1,28 +1,43 @@ import { uiKitCatalog } from '@rentnerproxy/app-contracts' import { LoaderCircle } from 'lucide-react' -import { useMemo } from 'react' +import { useContext, useMemo } from 'react' import { ActionMenu } from '@/shared/ActionMenu/index.tsx' import { buttonClassName } from '@/shared/Buttons/buttonStyles.ts' import { ConfirmDialog } from '@/shared/Modal/Components/ConfirmDialog.tsx' import useRemoteButtonLogic from '../Hooks/useRemoteButtonLogic.ts' +import { useRemoteFormState } from '../Hooks/useRemoteForm.ts' import useRemoteProperties from '../Hooks/useRemoteProperties.ts' +import { useRemoteAppView } from '../Hooks/useRemoteUiEntry.ts' +import { RemoteFormContext } from '../remoteElementContexts.ts' import type { RemoteElementProps } from '../Types/remote-app-view.types.ts' import RemoteUiIcon from './RemoteUiIcon.tsx' -// Submit buttons and their forms arrive with the form elements; until then every button presses. +/** + * A button that sends press. A submit button saves the form it names, or the form it sits in, and + * is enabled only while that form may be saved. + */ export function RemoteButton({ entry, emit }: RemoteElementProps) { - const { label, variant, icon, disabled, pending, pendingLabel, confirm } = useRemoteProperties( - uiKitCatalog['ui-button'].properties, - entry, - ) - const { state, handler } = useRemoteButtonLogic(confirm !== undefined, () => emit('press')) + const { label, variant, icon, disabled, pending, pendingLabel, confirm, type, form } = + useRemoteProperties(uiKitCatalog['ui-button'].properties, entry) + const { forms } = useRemoteAppView() + const surroundingForm = useContext(RemoteFormContext) + const target = type === 'submit' ? (form ?? surroundingForm) : undefined + const targetState = useRemoteFormState(target) + const { state, handler } = useRemoteButtonLogic(confirm !== undefined, () => { + if (target !== undefined) forms.submit(target) + emit('press') + }) return ( <> + + + ) +} + +export function RemoteTextField({ entry, emit }: RemoteElementProps) { + const props = useRemoteProperties(uiKitCatalog['ui-text-field'].properties, entry) + const { locale } = useTranslationStore() + const { kind, required, minLength, maxLength } = props + const rule = useMemo( + () => ({ + kind: 'text', + required: required === true, + minLength, + maxLength, + format: kind === 'email' ? 'email' : kind === 'url' ? 'url' : undefined, + }), + [kind, maxLength, minLength, required], + ) + const field = useRemoteFieldBinding({ + entry, + name: props.name, + own: props.value, + empty: '', + readOnly: props.readonly === true, + disabled: props.disabled === true, + read: readText, + rule, + }) + const common = { + id: field.id, + name: props.name, + label: , + description: props.description, + error: props.error ?? null, + value: field.value, + required: required === true, + readOnly: field.readOnly, + disabled: field.disabled, + placeholder: props.placeholder, + minLength, + maxLength, + locale, + onValueChange: (value: string) => { + field.setValue(value) + emit('change', { value }) + }, + onBlur: () => emit('blur', { value: field.value }), + } + if (kind === 'multiline') return