import React, { useEffect } from 'react'; import { FormattedDate, FormattedMessage, defineMessages, useIntl } from 'react-intl'; import { deleteAnnouncement, fetchAdminAnnouncements, initAnnouncementModal } from 'soapbox/actions/admin'; import { openModal } from 'soapbox/actions/modals'; import ScrollableList from 'soapbox/components/scrollable-list'; import { Button, Column, HStack, Stack, Text } from 'soapbox/components/ui'; import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; import { Announcement as AnnouncementEntity } from 'soapbox/types/entities'; const messages = defineMessages({ heading: { id: 'column.admin.announcements', defaultMessage: 'Announcements' }, deleteConfirm: { id: 'confirmations.admin.delete_announcement.confirm', defaultMessage: 'Delete' }, deleteHeading: { id: 'confirmations.admin.delete_announcement.heading', defaultMessage: 'Delete announcement' }, deleteMessage: { id: 'confirmations.admin.delete_announcement.message', defaultMessage: 'Are you sure you want to delete the announcement?' }, }); interface IAnnouncement { announcement: AnnouncementEntity } const Announcement: React.FC = ({ announcement }) => { const intl = useIntl(); const dispatch = useAppDispatch(); const handleEditAnnouncement = (announcement: AnnouncementEntity) => () => { dispatch(initAnnouncementModal(announcement)); }; const handleDeleteAnnouncement = (id: string) => () => { dispatch(openModal('CONFIRM', { heading: intl.formatMessage(messages.deleteHeading), message: intl.formatMessage(messages.deleteMessage), confirm: intl.formatMessage(messages.deleteConfirm), onConfirm: () => dispatch(deleteAnnouncement(id)), })); }; return (
{(announcement.starts_at || announcement.ends_at || announcement.all_day) && ( {announcement.starts_at && ( {' '} )} {announcement.ends_at && ( {' '} )} {announcement.all_day && ( )} )}
); }; const Announcements: React.FC = () => { const intl = useIntl(); const dispatch = useAppDispatch(); const announcements = useAppSelector((state) => state.admin_announcements.items); const isLoading = useAppSelector((state) => state.admin_announcements.isLoading); useEffect(() => { dispatch(fetchAdminAnnouncements()); }, []); const handleCreateAnnouncement = () => { dispatch(initAnnouncementModal()); }; const emptyMessage = ; return ( {announcements.map((announcement) => ( ))} ); }; export default Announcements;