wrolpi/app/src/components/collections/CollectionEditForm.js

88 lines
3.2 KiB
JavaScript
Raw Normal View History

import React from 'react';
2025-12-05 18:26:36 -07:00
import {Button, Form, Grid, Message} from 'semantic-ui-react';
import {Header, Segment} from '../Theme';
2025-12-05 18:26:36 -07:00
import {TagsContext} from '../../Tags';
import {WROLModeMessage} from '../Common';
/**
* Reusable form component for editing collections (Domains, Channels, etc).
*
* @param {Object} form - Form object from useForm hook
* @param {Function} onCancel - Optional callback when cancel is clicked
2025-12-05 18:26:36 -07:00
* @param {Function} onSubmit - Optional custom submit handler (defaults to form.onSubmit)
* @param {String} title - Page title to display in header
* @param {String} wrolModeContent - Content to show in WROL mode message (optional)
* @param {React.ReactNode} actionButtons - Optional additional action buttons to display in the button row
* @param {String} appliedTagName - Optional tag name to display (similar to ChannelEditPage pattern)
2025-12-05 18:26:36 -07:00
* @param {React.ReactNode} children - Form fields to render
*/
export function CollectionEditForm({
2025-12-06 14:49:46 -07:00
form,
onCancel,
onSubmit,
title,
wrolModeContent,
actionButtons,
appliedTagName,
children
}) {
const {SingleTag} = React.useContext(TagsContext);
const handleSubmit = (e) => {
e.preventDefault();
2025-12-05 18:26:36 -07:00
if (onSubmit) {
onSubmit(e);
} else {
form.onSubmit();
}
};
return <Segment>
{title && <Header as="h1">{title}</Header>}
{wrolModeContent && <WROLModeMessage content={wrolModeContent}/>}
{/* Display form-level errors */}
{form.error && <Message error>
<Message.Header>Error</Message.Header>
<p>{form.error}</p>
</Message>}
2025-12-05 18:26:36 -07:00
<Form onSubmit={handleSubmit} loading={form.loading} autoComplete="off">
<Grid stackable>
{children}
{appliedTagName && <Grid.Row>
<Grid.Column>
<SingleTag name={appliedTagName}/>
</Grid.Column>
</Grid.Row>}
<Grid.Row columns={2}>
<Grid.Column>
{actionButtons}
{onCancel && <Button
type='button'
onClick={onCancel}
disabled={form.disabled}
className="action-button-spacing"
>
Cancel
</Button>}
</Grid.Column>
<Grid.Column>
<Button
type='submit'
color='violet'
size='big'
floated='right'
disabled={form.disabled}
>
Save
</Button>
</Grid.Column>
</Grid.Row>
</Grid>
</Form>
</Segment>;
}