import { Button, FormToggle, Tooltip } from '@wordpress/components'; import { chevronDown, chevronUp, Icon, info } from '@wordpress/icons'; import clsx from 'clsx'; import { useTranslate } from 'i18n-calypso'; import { useState } from 'react'; import { useDateTimeFormat } from 'calypso/blocks/plugin-scheduled-updates-common/hooks/use-date-time-format'; import { usePrepareMultisitePluginsTooltipInfo } from 'calypso/blocks/plugin-scheduled-updates-common/hooks/use-prepare-plugins-tooltip-info'; import { usePrepareScheduleName } from 'calypso/blocks/plugin-scheduled-updates-common/hooks/use-prepare-schedule-name'; import { ScheduleListLastRunStatus } from 'calypso/blocks/plugins-scheduled-updates-multisite/schedule-list-last-run-status'; import { ScheduleListTableRowMenu } from 'calypso/blocks/plugins-scheduled-updates-multisite/schedule-list-table-row-menu'; import { useScheduledUpdatesActivateBatchMutation } from 'calypso/data/plugins/use-scheduled-updates-activate-batch-mutation'; import { SiteSlug } from 'calypso/types'; import type { MultisiteSchedulesUpdates, ScheduleUpdates, } from 'calypso/data/plugins/use-update-schedules-query'; type Props = { className?: string; compact?: boolean; schedule: MultisiteSchedulesUpdates; onEditClick: ( id: string ) => void; onRemoveClick: ( id: string ) => void; onLogsClick: ( id: string, siteSlug: SiteSlug ) => void; }; export const ScheduleListCard = ( props: Props ) => { const translate = useTranslate(); const { className, compact, schedule, onEditClick, onRemoveClick, onLogsClick } = props; const { prepareScheduleName } = usePrepareScheduleName(); const { prepareDateTime } = useDateTimeFormat(); const { preparePluginsTooltipInfo } = usePrepareMultisitePluginsTooltipInfo( schedule.sites.map( ( site ) => site.ID ) ); const { activateSchedule } = useScheduledUpdatesActivateBatchMutation(); const [ isExpanded, setIsExpanded ] = useState( false ); const batchActiveState = schedule.sites.some( ( site ) => site.active ); return (
{ ! compact && ( <>
activateSchedule( schedule.sites.map( ( site ) => ( { id: site.ID, slug: site.slug } ) ), schedule.schedule_id, { active: e.target.checked } ) } />
) } { isExpanded && (
{ schedule.sites.map( ( site ) => (
{ site.title }
activateSchedule( [ { id: site.ID, slug: site.slug } ], schedule.schedule_id, { active: e.target.checked, } ) } />
) ) }
) } { ! compact && (
{ prepareDateTime( schedule.timestamp ) }
) }
); };