|
| 1 | +import { Layout as DashboardLayout } from "../../../../layouts/index.js"; |
| 2 | +import { CippTablePage } from "../../../../components/CippComponents/CippTablePage.jsx"; |
| 3 | +import { useState } from "react"; |
| 4 | +import { Button, Alert, SvgIcon, IconButton, Tooltip } from "@mui/material"; |
| 5 | +import { useSettings } from "../../../../hooks/use-settings"; |
| 6 | +import { Stack } from "@mui/system"; |
| 7 | +import { Sync, Info } from "@mui/icons-material"; |
| 8 | +import { useDialog } from "../../../../hooks/use-dialog"; |
| 9 | +import { CippApiDialog } from "../../../../components/CippComponents/CippApiDialog"; |
| 10 | +import { CippQueueTracker } from "../../../../components/CippTable/CippQueueTracker"; |
| 11 | + |
| 12 | +const Page = () => { |
| 13 | + const currentTenant = useSettings().currentTenant; |
| 14 | + const syncDialog = useDialog(); |
| 15 | + const [syncQueueId, setSyncQueueId] = useState(null); |
| 16 | + |
| 17 | + const isAllTenants = currentTenant === "AllTenants"; |
| 18 | + |
| 19 | + const columns = [ |
| 20 | + ...(isAllTenants ? ["Tenant"] : []), |
| 21 | + "UPN", |
| 22 | + "DisplayName", |
| 23 | + "RecipientTypeDetails", |
| 24 | + "ForwardingType", |
| 25 | + "ForwardTo", |
| 26 | + "DeliverToMailboxAndForward", |
| 27 | + "CacheTimestamp", |
| 28 | + ]; |
| 29 | + |
| 30 | + const apiData = { |
| 31 | + UseReportDB: true, |
| 32 | + }; |
| 33 | + |
| 34 | + const filters = [ |
| 35 | + { |
| 36 | + filterName: "External Forwarding", |
| 37 | + value: [{ id: "ForwardingType", value: "External" }], |
| 38 | + type: "column", |
| 39 | + }, |
| 40 | + { |
| 41 | + filterName: "Internal Forwarding", |
| 42 | + value: [{ id: "ForwardingType", value: "Internal" }], |
| 43 | + type: "column", |
| 44 | + }, |
| 45 | + ]; |
| 46 | + |
| 47 | + const pageActions = [ |
| 48 | + <Stack direction="row" spacing={2} alignItems="center" key="actions-stack"> |
| 49 | + <CippQueueTracker |
| 50 | + queueId={syncQueueId} |
| 51 | + queryKey={`mailbox-forwarding-${currentTenant}`} |
| 52 | + title="Mailbox Forwarding Sync" |
| 53 | + /> |
| 54 | + <Tooltip title="This report displays cached mailbox data from the CIPP reporting database. Cache timestamps are shown in the table. Click the Sync button to update the mailbox cache for the current tenant."> |
| 55 | + <IconButton size="small"> |
| 56 | + <Info fontSize="small" /> |
| 57 | + </IconButton> |
| 58 | + </Tooltip> |
| 59 | + <Button |
| 60 | + startIcon={ |
| 61 | + <SvgIcon fontSize="small"> |
| 62 | + <Sync /> |
| 63 | + </SvgIcon> |
| 64 | + } |
| 65 | + size="xs" |
| 66 | + onClick={syncDialog.handleOpen} |
| 67 | + disabled={isAllTenants} |
| 68 | + > |
| 69 | + Sync |
| 70 | + </Button> |
| 71 | + </Stack>, |
| 72 | + ]; |
| 73 | + |
| 74 | + return ( |
| 75 | + <> |
| 76 | + {currentTenant && currentTenant !== "" ? ( |
| 77 | + <CippTablePage |
| 78 | + title="Mailbox Forwarding Report" |
| 79 | + apiUrl="/api/ListMailboxForwarding" |
| 80 | + queryKey={`mailbox-forwarding-${currentTenant}`} |
| 81 | + apiData={apiData} |
| 82 | + simpleColumns={columns} |
| 83 | + filters={filters} |
| 84 | + cardButton={pageActions} |
| 85 | + offCanvas={null} |
| 86 | + /> |
| 87 | + ) : ( |
| 88 | + <Alert severity="warning">Please select a tenant to view mailbox forwarding settings.</Alert> |
| 89 | + )} |
| 90 | + <CippApiDialog |
| 91 | + createDialog={syncDialog} |
| 92 | + title="Sync Mailbox Cache" |
| 93 | + fields={[]} |
| 94 | + api={{ |
| 95 | + type: "GET", |
| 96 | + url: "/api/ExecCIPPDBCache", |
| 97 | + confirmText: `Run mailbox cache sync for ${currentTenant}? This will update mailbox data including forwarding settings.`, |
| 98 | + relatedQueryKeys: [`mailbox-forwarding-${currentTenant}`], |
| 99 | + data: { |
| 100 | + Name: "Mailboxes", |
| 101 | + Types: "", |
| 102 | + }, |
| 103 | + onSuccess: (result) => { |
| 104 | + if (result?.Metadata?.QueueId) { |
| 105 | + setSyncQueueId(result.Metadata.QueueId); |
| 106 | + } |
| 107 | + }, |
| 108 | + }} |
| 109 | + /> |
| 110 | + </> |
| 111 | + ); |
| 112 | +}; |
| 113 | + |
| 114 | +Page.getLayout = (page) => <DashboardLayout>{page}</DashboardLayout>; |
| 115 | + |
| 116 | +export default Page; |
0 commit comments