/** * WordPress dependencies */ import { Button, Modal } from '@safe-wordpress/components'; import { useDispatch, useSelect } from '@safe-wordpress/data'; import { _x } from '@safe-wordpress/i18n'; /** * External dependencies */ import { padStart, sortBy, trim } from 'lodash'; import { SaveButton } from '@nelio-content/components'; import { replaceOrAppend } from '@nelio-content/utils'; import type { TaskTemplate } from '@nelio-content/types'; /** * Internal dependencies */ import './style.scss'; import { store as NC_TASK_PRESETS } from '~/nelio-content-pages/settings/task-presets/store'; import { Assignee } from './assignee'; import { DateDue } from './date-due'; import { TaskColor } from './task-color'; import { TaskDescriptionEditor } from './task-description-editor'; export const TaskTemplateEditor = (): JSX.Element | null => { const context = useSelect( ( select ) => select( NC_TASK_PRESETS ).getEditingTaskSource(), [] ); const attrs = useSelect( ( select ) => select( NC_TASK_PRESETS ).getEditingTask(), [] ); const preset = useSelect( ( select ) => select( NC_TASK_PRESETS ).getTaskPreset( context?.presetId ), [ context?.presetId ] ); const isExistingTask = ! useIsNew(); const isVisible = useSelect( ( select ) => select( NC_TASK_PRESETS ).isTaskTemplateEditorOpen(), [] ); const error = useSelect( ( select ) => select( NC_TASK_PRESETS ).getEditingTaskError(), [] ); const isExistingTaskDirty = useSelect( ( select ) => { const { isEditingTaskDirty } = select( NC_TASK_PRESETS ); return isExistingTask && isEditingTaskDirty(); }, [ isExistingTask ] ); const { closeTaskTemplateEditor: close, setTaskTemplates } = useDispatch( NC_TASK_PRESETS ); const saveAndClose = () => { if ( context && preset ) { const task = { ...attrs, task: trim( attrs.task ), }; void setTaskTemplates( preset.id, sortBy( replaceOrAppend( context.source, task, preset.tasks ), getSortingString ) ); } void close(); }; const title =