import type { Shout } from '../../graphql/schema/core.gen' import { getPagePath } from '@nanostores/router' import { clsx } from 'clsx' import { useConfirm } from '../../context/confirm' import { useLocalize } from '../../context/localize' import { useSnackbar } from '../../context/snackbar' import { router } from '../../stores/router' import { Icon } from '../_shared/Icon' import styles from './Draft.module.scss' type Props = { class?: string shout: Shout onPublish: (shout: Shout) => void onDelete: (shout: Shout) => void } export const Draft = (props: Props) => { const { t, formatDate } = useLocalize() const { showConfirm } = useConfirm() const { showSnackbar } = useSnackbar() const handlePublishLinkClick = (e) => { e.preventDefault() if (props.shout.main_topic) { props.onPublish(props.shout) } else { showSnackbar({ body: t('Please, set the main topic first') }) } } const handleDeleteLinkClick = async (e) => { e.preventDefault() const isConfirmed = await showConfirm({ confirmBody: t('Are you sure you want to delete this draft?'), confirmButtonLabel: t('Delete'), confirmButtonVariant: 'danger', declineButtonVariant: 'primary', }) if (isConfirmed) { props.onDelete(props.shout) await showSnackbar({ body: t('Draft successfully deleted') }) } } return (