import { MouseEvent } from "react"; import AutorenewIcon from "@mui/icons-material/Autorenew"; import DestinationsIcon from "@mui/icons-material/CloudQueue"; import FolderSharedIcon from "@mui/icons-material/FolderShared"; import ViewListIcon from "@mui/icons-material/ViewList"; import { Button, Datagrid, DateField, List, ListProps, Pagination, RaRecord, ReferenceField, ReferenceManyField, ResourceProps, SearchInput, Show, ShowProps, Tab, TabbedShowLayout, TextField, TopToolbar, useRecordContext, useDelete, useNotify, useRefresh, useTranslate, DateFieldProps, } from "react-admin"; import { DATE_FORMAT } from "../components/date"; import { get } from "lodash"; const DestinationPagination = () => ; const destinationRowSx = (record: RaRecord) => ({ backgroundColor: record.retry_last_ts > 0 ? "warning.light" : "primary.contrastText", "& .MuiButtonBase-root": { color: "primary.dark", }, }); const destinationFilters = []; export const DestinationReconnectButton = () => { const record = useRecordContext(); const refresh = useRefresh(); const notify = useNotify(); const [handleReconnect, { isLoading }] = useDelete(); // Reconnect is not required if no error has occurred. (`failure_ts`) if (!record || !record.failure_ts) return null; const handleClick = (e: MouseEvent) => { // Prevents redirection to the detail page when clicking in the list e.stopPropagation(); handleReconnect( "destinations", { id: record.id }, { onSuccess: () => { notify("ra.notification.updated", { messageArgs: { smart_count: 1 }, }); refresh(); }, onError: () => { notify("ra.message.error", { type: "error" }); }, } ); }; return ( ); }; const DestinationShowActions = () => ( ); const DestinationTitle = () => { const record = useRecordContext(); const translate = useTranslate(); return ( {translate("resources.destinations.name", 1)} {record?.destination} ); }; const RetryDateField = (props: DateFieldProps) => { const record = useRecordContext(props); if (props.source && get(record, props.source) === 0) { return ; } return ; }; export const DestinationList = (props: ListProps) => { return ( } sort={{ field: "destination", order: "ASC" }} > `${id}/show/rooms`} bulkActionButtons={false}> ); }; export const DestinationShow = (props: ShowProps) => { const translate = useTranslate(); return ( } title={} {...props}> }> } path="rooms"> } perPage={50} > `/rooms/${id}/show`}> ); }; const resource: ResourceProps = { name: "destinations", icon: DestinationsIcon, list: DestinationList, show: DestinationShow, }; export default resource;