-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #614 from ianmcorvidae/login-table
Login table
- Loading branch information
Showing
6 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -132,3 +132,7 @@ storybook-static | |
public/locales* | ||
|
||
.VSCodeCounter | ||
|
||
# editor backup/swap files | ||
*.swp | ||
*.bak |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* | ||
* @author mian | ||
* | ||
* A table of recent logins for the user. | ||
* | ||
*/ | ||
|
||
import React from "react"; | ||
import { useQuery } from "react-query"; | ||
|
||
import { logins, LOGINS_QUERY_KEY } from "serviceFacades/users"; | ||
import ErrorTypographyWithDialog from "components/error/ErrorTypographyWithDialog"; | ||
import { useTranslation } from "i18n"; | ||
import { | ||
formatDate, | ||
getFormattedDistance, | ||
} from "components/utils/DateFormatter"; | ||
import { | ||
useTheme, | ||
Skeleton, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableContainer, | ||
TableHead, | ||
TableRow, | ||
Paper, | ||
} from "@mui/material"; | ||
|
||
export default function LoginsTable() { | ||
const { t } = useTranslation(["dashboard", "common"]); | ||
|
||
const theme = useTheme(); | ||
const { status, data, error } = useQuery({ | ||
queryKey: [LOGINS_QUERY_KEY], | ||
queryFn: () => logins({ limit: 5 }), | ||
}); | ||
|
||
if (status === "error") { | ||
return ( | ||
<div style={{ padding: theme.spacing(1) }}> | ||
<ErrorTypographyWithDialog | ||
errorObject={error} | ||
errorMessage={t("loginsTableError")} | ||
/> | ||
</div> | ||
); | ||
} | ||
if (status === "loading") { | ||
return <Skeleton variant="rectangular" height={200} />; | ||
} | ||
return ( | ||
<TableContainer component={Paper}> | ||
<Table size="small"> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>{t("loginTime")}</TableCell> | ||
<TableCell>{t("ipAddress")}</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{data?.logins.map((row, index) => ( | ||
<TableRow key={index}> | ||
<TableCell> | ||
{formatDate(row["login_time"])} | ||
| ||
<em> | ||
( | ||
{t("common:timestamp", { | ||
timestamp: getFormattedDistance( | ||
row["login_time"] / 1000 | ||
), | ||
})} | ||
) | ||
</em> | ||
</TableCell> | ||
<TableCell>{row["ip_address"]}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
); | ||
} |
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 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