|
| 1 | +import { useState } from "react"; |
| 2 | +import { Layout as DashboardLayout } from "/src/layouts/index.js"; |
| 3 | +import { CippTablePage } from "/src/components/CippComponents/CippTablePage.jsx"; |
| 4 | +import { |
| 5 | + Button, |
| 6 | + Accordion, |
| 7 | + AccordionSummary, |
| 8 | + AccordionDetails, |
| 9 | + Typography, |
| 10 | + SvgIcon, |
| 11 | + Stack, |
| 12 | +} from "@mui/material"; |
| 13 | +import { Grid } from "@mui/system"; |
| 14 | +import { ExpandMore, Sort } from "@mui/icons-material"; |
| 15 | +import { FunnelIcon, XMarkIcon } from "@heroicons/react/24/outline"; |
| 16 | +import { useForm } from "react-hook-form"; |
| 17 | +import CippFormComponent from "/src/components/CippComponents/CippFormComponent"; |
| 18 | + |
| 19 | +const Page = () => { |
| 20 | + const formControl = useForm({ |
| 21 | + defaultValues: { |
| 22 | + period: { value: "D30", label: "30 days" }, |
| 23 | + }, |
| 24 | + }); |
| 25 | + |
| 26 | + const [expanded, setExpanded] = useState(false); |
| 27 | + const [selectedPeriod, setSelectedPeriod] = useState("D30"); |
| 28 | + const [selectedPeriodLabel, setSelectedPeriodLabel] = useState("30 days"); |
| 29 | + |
| 30 | + const periodOptions = [ |
| 31 | + { value: "D7", label: "7 days" }, |
| 32 | + { value: "D30", label: "30 days" }, |
| 33 | + { value: "D90", label: "90 days" }, |
| 34 | + { value: "D180", label: "180 days" }, |
| 35 | + ]; |
| 36 | + |
| 37 | + const onSubmit = (data) => { |
| 38 | + const periodValue = |
| 39 | + typeof data.period === "object" && data.period?.value ? data.period.value : data.period; |
| 40 | + const periodLabel = |
| 41 | + typeof data.period === "object" && data.period?.label ? data.period.label : data.period; |
| 42 | + |
| 43 | + setSelectedPeriod(periodValue); |
| 44 | + setSelectedPeriodLabel(periodLabel); |
| 45 | + setExpanded(false); |
| 46 | + }; |
| 47 | + |
| 48 | + const clearFilters = () => { |
| 49 | + formControl.reset({ |
| 50 | + period: { value: "D30", label: "30 days" }, |
| 51 | + }); |
| 52 | + setSelectedPeriod("D30"); |
| 53 | + setSelectedPeriodLabel("30 days"); |
| 54 | + setExpanded(false); |
| 55 | + }; |
| 56 | + |
| 57 | + const tableFilter = ( |
| 58 | + <Accordion expanded={expanded} onChange={() => setExpanded(!expanded)}> |
| 59 | + <AccordionSummary expandIcon={<ExpandMore />}> |
| 60 | + <Stack direction="row" spacing={1} alignItems="center"> |
| 61 | + <SvgIcon> |
| 62 | + <FunnelIcon /> |
| 63 | + </SvgIcon> |
| 64 | + <Typography variant="h6"> |
| 65 | + Report Period |
| 66 | + <span style={{ fontSize: "0.8em", marginLeft: "10px", fontWeight: "normal" }}> |
| 67 | + (Period: {selectedPeriodLabel}) |
| 68 | + </span> |
| 69 | + </Typography> |
| 70 | + </Stack> |
| 71 | + </AccordionSummary> |
| 72 | + <AccordionDetails> |
| 73 | + <form onSubmit={formControl.handleSubmit(onSubmit)}> |
| 74 | + <Grid container spacing={2}> |
| 75 | + <Grid size={{ xs: 12, md: 6 }}> |
| 76 | + <CippFormComponent |
| 77 | + type="autoComplete" |
| 78 | + name="period" |
| 79 | + multiple={false} |
| 80 | + label="Report Period" |
| 81 | + options={periodOptions} |
| 82 | + formControl={formControl} |
| 83 | + disableClearable={true} |
| 84 | + /> |
| 85 | + </Grid> |
| 86 | + |
| 87 | + <Grid size={{ xs: 12 }}> |
| 88 | + <Stack direction="row" spacing={2}> |
| 89 | + <Button |
| 90 | + type="submit" |
| 91 | + variant="contained" |
| 92 | + color="primary" |
| 93 | + startIcon={ |
| 94 | + <SvgIcon> |
| 95 | + <FunnelIcon /> |
| 96 | + </SvgIcon> |
| 97 | + } |
| 98 | + > |
| 99 | + Apply |
| 100 | + </Button> |
| 101 | + <Button |
| 102 | + variant="outlined" |
| 103 | + color="primary" |
| 104 | + startIcon={ |
| 105 | + <SvgIcon> |
| 106 | + <XMarkIcon /> |
| 107 | + </SvgIcon> |
| 108 | + } |
| 109 | + onClick={clearFilters} |
| 110 | + > |
| 111 | + Reset |
| 112 | + </Button> |
| 113 | + </Stack> |
| 114 | + </Grid> |
| 115 | + </Grid> |
| 116 | + </form> |
| 117 | + </AccordionDetails> |
| 118 | + </Accordion> |
| 119 | + ); |
| 120 | + |
| 121 | + return ( |
| 122 | + <CippTablePage |
| 123 | + tableFilter={tableFilter} |
| 124 | + title="Mailbox Activity" |
| 125 | + apiUrl="/api/ListGraphRequest" |
| 126 | + apiData={{ |
| 127 | + Endpoint: `reports/getEmailActivityUserDetail(period='${selectedPeriod}')`, |
| 128 | + $format: "application/json", |
| 129 | + Sort: "userPrincipalName", |
| 130 | + }} |
| 131 | + apiDataKey="Results" |
| 132 | + queryKey={`MailboxActivity-${selectedPeriod}`} |
| 133 | + simpleColumns={[ |
| 134 | + "userPrincipalName", |
| 135 | + "displayName", |
| 136 | + "sendCount", |
| 137 | + "receiveCount", |
| 138 | + "readCount", |
| 139 | + "meetingCreatedCount", |
| 140 | + "meetingInteractedCount", |
| 141 | + "lastActivityDate", |
| 142 | + "reportRefreshDate", |
| 143 | + "reportPeriod", |
| 144 | + ]} |
| 145 | + offCanvas={null} |
| 146 | + /> |
| 147 | + ); |
| 148 | +}; |
| 149 | + |
| 150 | +Page.getLayout = (page) => <DashboardLayout>{page}</DashboardLayout>; |
| 151 | + |
| 152 | +export default Page; |
0 commit comments