-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8832e6
commit 5acef9a
Showing
7 changed files
with
288 additions
and
153 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { useState } from "react"; | ||
import { useDownloadCSV } from "user/reporting/csv.library"; | ||
import { | ||
Alert, | ||
Button, | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogContentText, | ||
DialogTitle, | ||
LinearProgress, | ||
ListItemIcon, | ||
Menu, | ||
MenuItem, | ||
Snackbar, | ||
TextField, | ||
} from "@mui/material"; | ||
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown"; | ||
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp"; | ||
import DownloadIcon from "@mui/icons-material/Download"; | ||
|
||
interface ReportMenuProps { | ||
hasVerifiedConversions: boolean; | ||
campaignId: string; | ||
} | ||
export const ReportMenu = ({ | ||
campaignId, | ||
hasVerifiedConversions, | ||
}: ReportMenuProps) => { | ||
const [privateKey, setPrivateKey] = useState<string>(); | ||
const [dialogue, setDialogue] = useState(false); | ||
const [isError, setIsError] = useState(false); | ||
const { download, loading, error } = useDownloadCSV({ | ||
onComplete() { | ||
setAnchorEl(null); | ||
setDialogue(false); | ||
setPrivateKey(undefined); | ||
}, | ||
onError() { | ||
setIsError(true); | ||
setDialogue(false); | ||
setPrivateKey(undefined); | ||
}, | ||
}); | ||
|
||
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); | ||
const menu = Boolean(anchorEl); | ||
return ( | ||
<> | ||
<Button | ||
variant="contained" | ||
onClick={(e) => setAnchorEl(e.currentTarget)} | ||
endIcon={ | ||
anchorEl === null ? ( | ||
<KeyboardArrowDownIcon /> | ||
) : ( | ||
<KeyboardArrowUpIcon /> | ||
) | ||
} | ||
disabled={loading} | ||
> | ||
Download Report | ||
</Button> | ||
|
||
<Menu anchorEl={anchorEl} open={menu} onClose={() => setAnchorEl(null)}> | ||
<MenuItem | ||
onClick={() => download(campaignId, false)} | ||
disabled={loading} | ||
> | ||
<ListItemIcon> | ||
<DownloadIcon /> | ||
</ListItemIcon> | ||
Performance Report | ||
</MenuItem> | ||
, | ||
{hasVerifiedConversions && ( | ||
<MenuItem onClick={() => setDialogue(true)} disabled={loading}> | ||
<ListItemIcon> | ||
<DownloadIcon /> | ||
</ListItemIcon> | ||
Verified Conversions Report | ||
</MenuItem> | ||
)} | ||
</Menu> | ||
|
||
<Snackbar | ||
open={isError} | ||
autoHideDuration={6000} | ||
onClose={() => setIsError(false)} | ||
anchorOrigin={{ vertical: "top", horizontal: "center" }} | ||
> | ||
<Alert | ||
onClose={() => setIsError(false)} | ||
severity="error" | ||
sx={{ width: "100%" }} | ||
> | ||
{error} | ||
</Alert> | ||
</Snackbar> | ||
|
||
<Dialog open={dialogue} onClose={() => setDialogue(false)}> | ||
<DialogTitle>Decrypt Conversion Data?</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText> | ||
To protect user’s privacy, verified Ad conversion data is | ||
encrypted so that the identities of converted users remain anonymous | ||
to Brave. You can decrypt the conversion data in the CSV file by | ||
providing your private key here. If no key is provided, you will | ||
receive the encrypted conversion data. Your private key will never | ||
be sent to or stored on any Brave servers. | ||
</DialogContentText> | ||
<TextField | ||
autoFocus | ||
onChange={(e) => setPrivateKey(e.target.value)} | ||
margin="normal" | ||
value={privateKey} | ||
label="Private key" | ||
fullWidth | ||
variant="standard" | ||
/> | ||
{loading && <LinearProgress />} | ||
</DialogContent> | ||
<DialogActions> | ||
<Button | ||
variant="outlined" | ||
onClick={() => setDialogue(false)} | ||
disabled={loading} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
variant="contained" | ||
onClick={() => download(campaignId, true, privateKey)} | ||
disabled={loading} | ||
> | ||
Export | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.