import { Card, FormLabel } from '@automattic/components'; import { useTranslate } from 'i18n-calypso'; import { useState } from 'react'; import FormButton from 'calypso/components/forms/form-button'; import FormButtonsBar from 'calypso/components/forms/form-buttons-bar'; import FormFieldset from 'calypso/components/forms/form-fieldset'; import FormLegend from 'calypso/components/forms/form-legend'; import FormRadio from 'calypso/components/forms/form-radio'; import FormSettingExplanation from 'calypso/components/forms/form-setting-explanation'; import FormTextInput from 'calypso/components/forms/form-text-input'; import FormTextarea from 'calypso/components/forms/form-textarea'; const INITIAL_UPDATE_FORM_STATE = { description: '', is_public: true, is_immutable: false, title: '', }; const INITIAL_CREATE_FORM_STATE = { ...INITIAL_UPDATE_FORM_STATE, slug: '', }; export default function ListForm( { isCreateForm, isSubmissionDisabled, list = {}, onSubmit } ) { const translate = useTranslate(); const [ formList, updateFormList ] = useState( isCreateForm ? INITIAL_CREATE_FORM_STATE : { ...INITIAL_UPDATE_FORM_STATE, ...list } ); // If list.is_immutable this list is permanent - render minimal form with no edit options if ( list?.is_immutable ) { return ( { translate( 'Name' ) } { translate( 'Slug' ) } ); } const onChange = ( event ) => { const update = { [ event.target.dataset.key ]: event.target.value }; if ( 'is_public' in update ) { update.is_public = update.is_public === 'public'; } updateFormList( { ...formList, ...update } ); }; const isNameValid = typeof formList.title === 'string' && formList.title.length > 0; const isSlugValid = isCreateForm || ( typeof formList.slug === 'string' && formList.slug.length > 0 ); return ( { translate( 'Name (Required)' ) } { translate( 'The name of the list.' ) } { ! isCreateForm && ( { translate( 'Slug' ) } { translate( 'This is used to build the URL to the list.' ) } ) } { translate( 'Visibility' ) } { translate( "Don't worry, posts from private sites will only appear to those with access. " + 'Adding a private site to a public list will not make posts from that site accessible to everyone.' ) } { translate( 'Description' ) } onSubmit( formList ) } > { translate( 'Save' ) } ); }