2025-10-29 22:16:33 -06:00
|
|
|
import React from 'react';
|
2025-12-05 18:26:36 -07:00
|
|
|
import {Button, Form, Grid, Message} from 'semantic-ui-react';
|
2025-10-29 22:16:33 -06:00
|
|
|
import {Header, Segment} from '../Theme';
|
2025-12-05 18:26:36 -07:00
|
|
|
import {TagsContext} from '../../Tags';
|
2025-10-29 22:16:33 -06:00
|
|
|
import {WROLModeMessage} from '../Common';
|
2025-12-02 15:33:46 -07:00
|
|
|
|
2025-10-29 22:16:33 -06:00
|
|
|
/**
|
|
|
|
|
* 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)
|
2025-10-29 22:16:33 -06:00
|
|
|
* @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
|
2025-10-29 22:16:33 -06:00
|
|
|
*/
|
|
|
|
|
export function CollectionEditForm({
|
2025-12-06 14:49:46 -07:00
|
|
|
form,
|
|
|
|
|
onCancel,
|
|
|
|
|
onSubmit,
|
|
|
|
|
title,
|
|
|
|
|
wrolModeContent,
|
|
|
|
|
actionButtons,
|
|
|
|
|
appliedTagName,
|
|
|
|
|
children
|
|
|
|
|
}) {
|
2025-10-29 22:16:33 -06:00
|
|
|
const {SingleTag} = React.useContext(TagsContext);
|
2025-12-02 15:33:46 -07:00
|
|
|
|
2025-10-29 22:16:33 -06:00
|
|
|
const handleSubmit = (e) => {
|
|
|
|
|
e.preventDefault();
|
2025-12-05 18:26:36 -07:00
|
|
|
if (onSubmit) {
|
|
|
|
|
onSubmit(e);
|
|
|
|
|
} else {
|
|
|
|
|
form.onSubmit();
|
|
|
|
|
}
|
2025-10-29 22:16:33 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return <Segment>
|
|
|
|
|
{title && <Header as="h1">{title}</Header>}
|
|
|
|
|
{wrolModeContent && <WROLModeMessage content={wrolModeContent}/>}
|
|
|
|
|
|
2025-12-02 15:33:46 -07:00
|
|
|
{/* 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>
|
2025-10-29 22:16:33 -06:00
|
|
|
</Segment>;
|
|
|
|
|
}
|