/** * WordPress dependencies */ import { Button } from '@safe-wordpress/components'; import { useDispatch } from '@safe-wordpress/data'; import { sprintf, _x, _nx } from '@safe-wordpress/i18n'; /** * External dependencies */ import { DeleteButton } from '@nelio-content/components'; import type { TaskPreset, TaskTemplate as TaskTempl, } from '@nelio-content/types'; /** * Internal dependencies */ import './style.scss'; import { store as NC_TASK_PRESETS } from '~/nelio-content-pages/settings/task-presets/store'; import { useAuthorName } from '@nelio-content/data'; export type TaskTemplateProps = { readonly presetId: TaskPreset[ 'id' ]; readonly task: TaskTempl; readonly disabled: boolean; readonly onDelete: () => void; readonly onUpdate: ( task: TaskTempl ) => void; }; export const TaskTemplate = ( { presetId, task, onDelete, }: TaskTemplateProps ): JSX.Element => { const { openTaskTemplateEditor } = useDispatch( NC_TASK_PRESETS ); const authorName = useAuthorName( task.assigneeId ); const dueDate = getDueDate( task.dateType, task.dateValue ); const onEdit = () => openTaskTemplateEditor( presetId, task ); return (
{ task.task }
{ sprintf( '%1$s • %2$s', task.assigneeId ? authorName : _x( 'Post Author', 'text', 'nelio-content' ), dueDate ) }
); }; // ======= // HELPERS // ======= const getDueDate = ( type: TaskTempl[ 'dateType' ], value: TaskTempl[ 'dateValue' ] ): string => { const numValue = Math.abs( Number.parseInt( value ) || 0 ); switch ( type ) { case 'negative-days': case 'predefined-offset': return ( { '0': _x( 'Same day as publication', 'text', 'nelio-content' ), '-1': _x( 'The day before publication', 'text', 'nelio-content' ), '-7': _x( 'A week before publication', 'text', 'nelio-content' ), }[ value ] || sprintf( /* translators: %d: Number of days. */ _nx( '%d day before publication', '%d days before publication', numValue, 'text', 'nelio-content' ), numValue ) ); case 'positive-days': return sprintf( /* translators: %d: Number of days. */ _nx( '%d day after publication', '%d days after publication', numValue, 'text', 'nelio-content' ), numValue ); } };