import type { AppForm } from '@/components/form'; import { type AdminLocation, useAllAdminLocations } from '@/api/admin/locations/queries'; import { type NodeFormValues, nodeNumberValidators, validateNodeName } from '@/components/admin/nodes/nodeForm'; import TitledGreyBox from '@/components/elements/TitledGreyBox'; import { useTranslation } from '@/sdk/localization'; interface Props { form: AppForm; prefix?: string; requiresSslScheme?: boolean; } type LocationOption = AdminLocation; interface FormFieldsProps { form: AppForm; prefix: string; } interface IdentityFieldsProps extends FormFieldsProps { locations: LocationOption[]; } interface NetworkFieldsProps extends FormFieldsProps { requiresSslScheme: boolean; } const IdentityFields = ({ form, locations, prefix }: IdentityFieldsProps) => { const { t } = useTranslation(); return (
validateNodeName(value), }} > {(field) => ( )} {(field) => ( )} (value >= 1 ? undefined : t('A location must be selected.')), }} > {(field) => ( ({ value: location.attributes.id, label: location.attributes.short, }))} /> )}
); }; const NetworkFields = ({ form, prefix, requiresSslScheme }: NetworkFieldsProps) => { const { t } = useTranslation(); const schemeDescription = requiresSslScheme ? t('This Panel is using HTTPS, so browsers require node connections to use SSL.') : t('In most cases you should use SSL. Use HTTP only for non-SSL nodes.'); return (
(value.length >= 1 ? undefined : t('An FQDN must be provided.')), }} > {(field) => ( )} requiresSslScheme && value === 'http' ? t('HTTP node connections cannot be used when the Panel is loaded over HTTPS.') : undefined, }} > {(field) => ( )}
{(field) => ( )} {(field) => ( )} {(field) => ( )}
); }; const ResourceFields = ({ form, prefix }: FormFieldsProps) => { const { t } = useTranslation(); const validators = nodeNumberValidators(t); return (
{(field) => } {(field) => ( )} {(field) => } {(field) => ( )}
); }; const DaemonFields = ({ form, prefix }: FormFieldsProps) => { const { t } = useTranslation(); const validators = nodeNumberValidators(t); return (
{(field) => ( )} {(field) => ( )} {(field) => ( )} {(field) => }
); }; export default function NodeFormFields({ form, prefix = '', requiresSslScheme = false }: Props) { const { t } = useTranslation(); const { data: locations = [] } = useAllAdminLocations(); return (
); }