From ff964b54a3e954ecfeb3882807d2c46dca96bc0b Mon Sep 17 00:00:00 2001 From: Tessa Thornton Date: Wed, 7 Aug 2019 16:22:47 -0400 Subject: [PATCH] [CORL-97] Add user status details popover to user drawer (#2431) * show tooltip for user status details * localize strings * fix merge conflict * fix date formatting in user details popover * update snapshot * fix rebase --- .../UserHistoryDrawerQuery.tsx | 13 +- .../UserStatusDetailsContainer.css | 0 .../UserStatusDetailsContainer.tsx | 169 ++++++++++++++++++ src/locales/en-US/admin.ftl | 6 + 4 files changed, 185 insertions(+), 3 deletions(-) create mode 100644 src/core/client/admin/components/UserHistoryDrawer/UserStatusDetailsContainer.css create mode 100644 src/core/client/admin/components/UserHistoryDrawer/UserStatusDetailsContainer.tsx diff --git a/src/core/client/admin/components/UserHistoryDrawer/UserHistoryDrawerQuery.tsx b/src/core/client/admin/components/UserHistoryDrawer/UserHistoryDrawerQuery.tsx index 70be0314c..31f0615fa 100644 --- a/src/core/client/admin/components/UserHistoryDrawer/UserHistoryDrawerQuery.tsx +++ b/src/core/client/admin/components/UserHistoryDrawer/UserHistoryDrawerQuery.tsx @@ -2,12 +2,12 @@ import { Localized } from "fluent-react/compat"; import React, { FunctionComponent } from "react"; import { ReadyState } from "react-relay"; +import { UserStatusChangeContainer } from "coral-admin/components/UserStatus"; import { CopyButton } from "coral-framework/components"; import { useCoralContext } from "coral-framework/lib/bootstrap"; import { graphql, QueryRenderer } from "coral-framework/lib/relay"; import { UserHistoryDrawerQuery as QueryTypes } from "coral-admin/__generated__/UserHistoryDrawerQuery.graphql"; -import { UserStatusChangeContainer } from "coral-admin/components/UserStatus"; import { Button, CallOut, @@ -18,6 +18,7 @@ import { } from "coral-ui/components"; import Tabs from "./Tabs"; +import UserStatusDetailsContainer from "./UserStatusDetailsContainer"; import styles from "./UserHistoryDrawerQuery.css"; @@ -48,6 +49,7 @@ const UserHistoryDrawerQuery: FunctionComponent = ({ username email createdAt + ...UserStatusDetailsContainer_user ...UserStatusChangeContainer_user } settings { @@ -92,7 +94,7 @@ const UserHistoryDrawerQuery: FunctionComponent = ({ {user.username}
- +
@@ -103,8 +105,13 @@ const UserHistoryDrawerQuery: FunctionComponent = ({
- +
+
diff --git a/src/core/client/admin/components/UserHistoryDrawer/UserStatusDetailsContainer.css b/src/core/client/admin/components/UserHistoryDrawer/UserStatusDetailsContainer.css new file mode 100644 index 000000000..e69de29bb diff --git a/src/core/client/admin/components/UserHistoryDrawer/UserStatusDetailsContainer.tsx b/src/core/client/admin/components/UserHistoryDrawer/UserStatusDetailsContainer.tsx new file mode 100644 index 000000000..3942104bc --- /dev/null +++ b/src/core/client/admin/components/UserHistoryDrawer/UserStatusDetailsContainer.tsx @@ -0,0 +1,169 @@ +import { graphql, withFragmentContainer } from "coral-framework/lib/relay"; +import { Localized } from "fluent-react/compat"; +import React, { FunctionComponent, useMemo } from "react"; + +import { UserStatusDetailsContainer_user as UserData } from "coral-admin/__generated__/UserStatusDetailsContainer_user.graphql"; +import { useCoralContext } from "coral-framework/lib/bootstrap"; +import { + BaseButton, + Box, + ClickOutside, + Icon, + Popover, + Typography, +} from "coral-ui/components"; + +interface Props { + user: UserData; +} + +const UserStatusDetailsContainer: FunctionComponent = ({ user }) => { + if (!user.status.ban.active && !user.status.suspension.active) { + return null; + } + + const activeBan = useMemo(() => { + return user.status.ban.history.find(item => item.active); + }, [user]); + + const activeSuspension = useMemo(() => { + return user.status.suspension.history.find(item => item.active); + }, [user]); + + const { locales } = useCoralContext(); + + const formatter = new Intl.DateTimeFormat(locales, { + day: "2-digit", + month: "2-digit", + year: "numeric", + hour: "2-digit", + minute: "2-digit", + }); + + return ( +
+ ( + + + {activeBan && ( +
+ } + > + + Banned on {" "} + {formatter.format(activeBan.createdAt)} + + + {activeBan.createdBy && ( + } + $username={activeBan.createdBy.username} + > + + by + {activeBan.createdBy.username} + + + )} +
+ )} + {activeSuspension && ( +
+ {activeSuspension.createdBy && ( + } + $username={activeSuspension.createdBy.username} + > + + Suspended by + {activeSuspension.createdBy.username} + + + )} + } + $timestamp={formatter.format(activeSuspension.from.start)} + > + + Start: + {formatter.format(activeSuspension.from.start)} + + + } + $timestamp={formatter.format(activeSuspension.from.finish)} + id="userDetails-suspension-start" + > + + End: + {formatter.format(activeSuspension.from.finish)} + + +
+ )} +
+
+ )} + > + {({ toggleVisibility, ref }) => ( + { + evt.stopPropagation(); + toggleVisibility(); + }} + aria-label="View user status details" + ref={ref} + > + + info + + + )} +
+
+ ); +}; + +const enhanced = withFragmentContainer({ + user: graphql` + fragment UserStatusDetailsContainer_user on User { + status { + ban { + active + history { + active + createdAt + createdBy { + username + } + } + } + suspension { + until + active + history { + active + from { + start + finish + } + createdBy { + username + } + } + } + } + } + `, +})(UserStatusDetailsContainer); + +export default enhanced; diff --git a/src/locales/en-US/admin.ftl b/src/locales/en-US/admin.ftl index 8e2f3a681..1155c90a4 100644 --- a/src/locales/en-US/admin.ftl +++ b/src/locales/en-US/admin.ftl @@ -682,3 +682,9 @@ invite-goToAdmin = Go to { -product-name } Admin invite-goToOrganization = Go to { $organizationName } invite-tokenNotFound = The specified link is invalid, check to see if it was copied correctly. + +userDetails-banned-on = Banned on { $timestamp } +userDetails-banned-by = by { $username } +userDetails-suspended-by = Suspended by { $username } +userDetails-suspension-start = Start: { $timestamp } +userDetails-suspension-end = End: { $timestamp } \ No newline at end of file