Files

117 lines
3.6 KiB
TypeScript
Raw Permalink Normal View History

2026-10-05 18:10:18 -04:00
import type { AppForm } from '@/components/form';
import type { MountValues } from '@/api/admin/mounts/queries';
import TitledGreyBox from '@/components/elements/TitledGreyBox';
2026-10-08 18:49:15 -04:00
import { validateMountName } from '@/components/admin/mounts/mountForm';
2026-10-08 16:53:20 -04:00
2026-10-05 18:10:18 -04:00
interface Props {
form: AppForm<MountValues>;
}
const DetailsFields = ({ form }: Props) => (
2026-10-08 16:53:20 -04:00
<div className='space-y-6'>
2026-10-05 18:10:18 -04:00
<form.AppField
2026-10-08 16:53:20 -04:00
name='name'
2026-10-05 18:10:18 -04:00
validators={{
2026-10-08 16:53:20 -04:00
onChange: ({ value }) => validateMountName(value),
2026-10-05 18:10:18 -04:00
}}
>
{(field) => (
<field.TextField
2026-10-08 16:53:20 -04:00
type='text'
id='name'
label='Name'
description='A unique name used to identify this mount.'
2026-10-05 18:10:18 -04:00
/>
)}
</form.AppField>
<form.AppField
2026-10-08 16:53:20 -04:00
name='description'
2026-10-05 18:10:18 -04:00
validators={{
onChange: ({ value }) =>
value.length <= 191 ? undefined : 'A description must not exceed 191 characters.',
}}
>
{(field) => (
<field.TextField
2026-10-08 16:53:20 -04:00
type='text'
id='description'
label='Description'
description='A longer description for this mount.'
2026-10-05 18:10:18 -04:00
/>
)}
</form.AppField>
</div>
);
const PathFields = ({ form }: Props) => (
2026-10-08 16:53:20 -04:00
<div className='grid grid-cols-1 lg:grid-cols-2 gap-6'>
2026-10-05 18:10:18 -04:00
<form.AppField
2026-10-08 16:53:20 -04:00
name='source'
2026-10-05 18:10:18 -04:00
validators={{
onChange: ({ value }) => (value.length >= 1 ? undefined : 'A source path must be provided.'),
}}
>
{(field) => (
<field.TextField
2026-10-08 16:53:20 -04:00
type='text'
id='source'
label='Source'
description='The path on the host system to mount into the container.'
2026-10-05 18:10:18 -04:00
/>
)}
</form.AppField>
<form.AppField
2026-10-08 16:53:20 -04:00
name='target'
2026-10-05 18:10:18 -04:00
validators={{
onChange: ({ value }) => (value.length >= 1 ? undefined : 'A target path must be provided.'),
}}
>
{(field) => (
<field.TextField
2026-10-08 16:53:20 -04:00
type='text'
id='target'
label='Target'
description='The path inside the container where the source will be mounted.'
2026-10-05 18:10:18 -04:00
/>
)}
</form.AppField>
</div>
);
const AccessFields = ({ form }: Props) => (
2026-10-08 16:53:20 -04:00
<div className='space-y-6'>
<form.AppField name='readOnly'>
2026-10-05 18:10:18 -04:00
{(field) => (
<field.SwitchField
2026-10-08 16:53:20 -04:00
label='Read Only'
description='Mount this volume as read only inside the container.'
2026-10-05 18:10:18 -04:00
/>
)}
</form.AppField>
2026-10-08 16:53:20 -04:00
<form.AppField name='userMountable'>
2026-10-05 18:10:18 -04:00
{(field) => (
<field.SwitchField
2026-10-08 16:53:20 -04:00
label='User Mountable'
description='Allow this mount to be added to servers by users.'
2026-10-05 18:10:18 -04:00
/>
)}
</form.AppField>
</div>
);
export default function MountFormFields({ form }: Props) {
return (
2026-10-08 16:53:20 -04:00
<div className='space-y-6'>
<TitledGreyBox title='Mount Details'>
2026-10-05 18:10:18 -04:00
<DetailsFields form={form} />
</TitledGreyBox>
2026-10-08 16:53:20 -04:00
<TitledGreyBox title='Paths'>
2026-10-05 18:10:18 -04:00
<PathFields form={form} />
</TitledGreyBox>
2026-10-08 16:53:20 -04:00
<TitledGreyBox title='Access'>
2026-10-05 18:10:18 -04:00
<AccessFields form={form} />
</TitledGreyBox>
</div>
);
}