AnalyticsUpgrade.js
5 years ago
Dashboard.js
4 years ago
User.js
5 years ago
Video.js
4 years ago
illustration.js
5 years ago
User.js
172 lines
| 1 | /** @jsx jsx */ |
| 2 | |
| 3 | const { __ } = wp.i18n; |
| 4 | |
| 5 | const { Flex, FlexBlock, FlexItem, Spinner, Button } = wp.components; |
| 6 | |
| 7 | import { history } from "@/router/context"; |
| 8 | import DatePicker from "../components/DatePicker"; |
| 9 | import TopVideos from "../components/TopVideos"; |
| 10 | import TotalVideoViewsByUser from "../components/TotalVideoViewsByUser"; |
| 11 | import VideoAverageWatchTimeByUser from "../components/VideoAverageWatchTimeByUser"; |
| 12 | import VideoTotalWatchTimeByUser from "../components/VideoTotalWatchTimeByUser"; |
| 13 | |
| 14 | const { useEffect, useState } = wp.element; |
| 15 | const { apiFetch } = wp; |
| 16 | |
| 17 | import { css, jsx } from "@emotion/core"; |
| 18 | |
| 19 | const User = ({ route, startDate, endDate, setStartDate, setEndDate }) => { |
| 20 | const [loading, setLoading] = useState(true); |
| 21 | const [user, setUser] = useState({}); |
| 22 | const [error, setError] = useState(""); |
| 23 | |
| 24 | const back = () => { |
| 25 | history.push(`#/`); |
| 26 | }; |
| 27 | |
| 28 | const getUser = async () => { |
| 29 | setLoading(true); |
| 30 | try { |
| 31 | let user = await apiFetch({ |
| 32 | url: `/wp-json/wp/v2/users/${route?.params?.id}?context=edit`, |
| 33 | }); |
| 34 | setUser(user); |
| 35 | } catch (e) { |
| 36 | if (e.code === "rest_no_route") { |
| 37 | setError("User Not Found"); |
| 38 | } |
| 39 | } finally { |
| 40 | setLoading(false); |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | useEffect(() => { |
| 45 | getUser(); |
| 46 | }, []); |
| 47 | |
| 48 | if (error) { |
| 49 | return ( |
| 50 | <div className="presto-flow"> |
| 51 | <Flex> |
| 52 | <FlexBlock> |
| 53 | <h2>{error}</h2> |
| 54 | </FlexBlock> |
| 55 | </Flex> |
| 56 | </div> |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | return ( |
| 61 | <div className="presto-flow"> |
| 62 | <Flex> |
| 63 | <FlexBlock> |
| 64 | <Button isSecondary onClick={back}> |
| 65 | ← {__("Back to Dashboard", "presto-player")} |
| 66 | </Button> |
| 67 | </FlexBlock> |
| 68 | </Flex> |
| 69 | <Flex wrap> |
| 70 | <FlexBlock> |
| 71 | {loading ? ( |
| 72 | <Spinner /> |
| 73 | ) : ( |
| 74 | <div |
| 75 | css={css` |
| 76 | display: flex; |
| 77 | align-items: center; |
| 78 | |
| 79 | .presto__edit-user-button { |
| 80 | opacity: 0; |
| 81 | visibility: hidden; |
| 82 | transition: opacity 0.3s ease; |
| 83 | } |
| 84 | |
| 85 | &:hover { |
| 86 | .presto__edit-user-button { |
| 87 | opacity: 1; |
| 88 | visibility: visible; |
| 89 | } |
| 90 | } |
| 91 | `} |
| 92 | > |
| 93 | <div> |
| 94 | <h1 className="presto-dashboard__title">{user?.name}</h1> |
| 95 | <p |
| 96 | css={css` |
| 97 | margin-top: -10px; |
| 98 | opacity: 0.65; |
| 99 | `} |
| 100 | > |
| 101 | {user?.email} |
| 102 | </p> |
| 103 | </div> |
| 104 | {!!user.id && ( |
| 105 | <div |
| 106 | className="presto__edit-user-button" |
| 107 | css={css` |
| 108 | margin: 0 20px; |
| 109 | `} |
| 110 | > |
| 111 | <Button |
| 112 | href={`/wp-admin/user-edit.php?user_id=${user?.id}`} |
| 113 | isSecondary |
| 114 | isSmall |
| 115 | > |
| 116 | {__("View Profile", "presto-player")} → |
| 117 | </Button> |
| 118 | </div> |
| 119 | )} |
| 120 | </div> |
| 121 | )} |
| 122 | </FlexBlock> |
| 123 | <FlexItem> |
| 124 | <DatePicker |
| 125 | startDate={startDate} |
| 126 | setStartDate={setStartDate} |
| 127 | endDate={endDate} |
| 128 | setEndDate={setEndDate} |
| 129 | /> |
| 130 | </FlexItem> |
| 131 | </Flex> |
| 132 | |
| 133 | <div className="presto-dashboard presto-flow"> |
| 134 | <div className="presto-dashboard__row"> |
| 135 | <div className="presto-dashboard__item"> |
| 136 | <TotalVideoViewsByUser |
| 137 | userId={route?.params?.id} |
| 138 | startDate={startDate} |
| 139 | endDate={endDate} |
| 140 | /> |
| 141 | </div> |
| 142 | <div className="presto-dashboard__item"> |
| 143 | <VideoAverageWatchTimeByUser |
| 144 | userId={route?.params?.id} |
| 145 | startDate={startDate} |
| 146 | endDate={endDate} |
| 147 | /> |
| 148 | </div> |
| 149 | <div className="presto-dashboard__item"> |
| 150 | <VideoTotalWatchTimeByUser |
| 151 | userId={route?.params?.id} |
| 152 | startDate={startDate} |
| 153 | endDate={endDate} |
| 154 | /> |
| 155 | </div> |
| 156 | </div> |
| 157 | <div className="presto-dashboard__row"> |
| 158 | <div className="presto-dashboard__item is-large"> |
| 159 | <TopVideos |
| 160 | startDate={startDate} |
| 161 | endDate={endDate} |
| 162 | userId={route?.params?.id} |
| 163 | /> |
| 164 | </div> |
| 165 | </div> |
| 166 | </div> |
| 167 | </div> |
| 168 | ); |
| 169 | }; |
| 170 | |
| 171 | export default User; |
| 172 |