-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added new model called Activities to capture user activities * Graphs showing essential metrics * Added index * CodeQL fixes --------- Co-authored-by: Rajat Saxena <[email protected]>
- Loading branch information
1 parent
98902f6
commit c1e4ba2
Showing
173 changed files
with
2,192 additions
and
327 deletions.
There are no files selected for viewing
Binary file added
BIN
+66.6 KB
.yarn/cache/@eslint-community-regexpp-npm-4.10.0-6bfb984c81-2a6e345429.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+16.4 KB
.yarn/cache/@humanwhocodes-config-array-npm-0.11.14-94a02fcc87-861ccce9ea.zip
Binary file not shown.
Binary file added
BIN
+14.1 KB
.yarn/cache/@humanwhocodes-object-schema-npm-2.0.2-77b42018f9-2fc1150336.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+6.86 KB
.yarn/cache/@types-d3-interpolate-npm-3.0.4-e863f31b1c-efd2770e17.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+810 KB
.yarn/cache/@typescript-eslint-eslint-plugin-npm-7.4.0-559b255afa-01932c7629.zip
Binary file not shown.
Binary file added
BIN
+8.79 KB
.yarn/cache/@typescript-eslint-parser-npm-7.4.0-0c13447ea1-ee8dac1a5b.zip
Binary file not shown.
Binary file added
BIN
+333 KB
.yarn/cache/@typescript-eslint-scope-manager-npm-7.4.0-0b20c139fb-6d8677ffed.zip
Binary file not shown.
Binary file added
BIN
+53.4 KB
.yarn/cache/@typescript-eslint-type-utils-npm-7.4.0-7aaf170a20-5906909843.zip
Binary file not shown.
Binary file added
BIN
+30.5 KB
.yarn/cache/@typescript-eslint-types-npm-7.4.0-3e79d39332-0be366b4da.zip
Binary file not shown.
Binary file added
BIN
+174 KB
.yarn/cache/@typescript-eslint-typescript-estree-npm-7.4.0-c2218411fa-af8e487004.zip
Binary file not shown.
Binary file added
BIN
+111 KB
.yarn/cache/@typescript-eslint-utils-npm-7.4.0-cc89951e7f-9f2c83f113.zip
Binary file not shown.
Binary file added
BIN
+9.79 KB
.yarn/cache/@typescript-eslint-visitor-keys-npm-7.4.0-fcd4bb6855-9baa497eef.zip
Binary file not shown.
Binary file added
BIN
+13.9 KB
.yarn/cache/@ungap-structured-clone-npm-1.2.0-648f0b82e0-4f656b7b46.zip
Binary file not shown.
Binary file added
BIN
+7.96 KB
.yarn/cache/array-buffer-byte-length-npm-1.0.1-e7afc30010-53524e08f4.zip
Binary file not shown.
Binary file added
BIN
+13.7 KB
.yarn/cache/array.prototype.findlast-npm-1.2.5-316cb71d39-83ce4ad95b.zip
Binary file not shown.
Binary file added
BIN
+10.7 KB
.yarn/cache/array.prototype.toreversed-npm-1.1.2-48ebc74406-5859819342.zip
Binary file not shown.
Binary file added
BIN
+11.1 KB
.yarn/cache/array.prototype.tosorted-npm-1.1.3-f42c917a7c-555e880808.zip
Binary file not shown.
Binary file added
BIN
+11.1 KB
.yarn/cache/arraybuffer.prototype.slice-npm-1.0.3-97a993a091-352259cba5.zip
Binary file not shown.
Binary file added
BIN
+9.75 KB
.yarn/cache/available-typed-arrays-npm-1.0.7-e5e5d79687-1aa3ffbfe6.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+6.96 KB
.yarn/cache/data-view-byte-length-npm-1.0.1-538a9e432e-dbb3200edc.zip
Binary file not shown.
Binary file added
BIN
+7.76 KB
.yarn/cache/data-view-byte-offset-npm-1.0.0-7112a24a4b-7f0bf8720b.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-6.53 KB
.yarn/cache/eslint-config-standard-npm-17.0.0-2803f6a79a-dc0ed51e18.zip
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-230 KB
.yarn/cache/eslint-plugin-react-npm-7.32.2-b8b92d1b99-2232b3b894.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+7.87 KB
.yarn/cache/get-symbol-description-npm-1.0.2-f8c332e0b5-e1cb53bc21.zip
Binary file not shown.
Binary file added
BIN
+6.59 KB
.yarn/cache/has-property-descriptors-npm-1.0.2-d7077d09f1-fcbb246ea2.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+9.25 KB
.yarn/cache/is-shared-array-buffer-npm-1.0.3-3b3b3142a6-a4fff602c3.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+7.03 KB
.yarn/cache/possible-typed-array-names-npm-1.0.0-3a8176348a-b32d403ece.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+16.2 KB
.yarn/cache/regexp.prototype.flags-npm-1.5.2-a44e05d7d9-d7f333667d.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+16 KB
.yarn/cache/string.prototype.matchall-npm-4.0.11-a18d0665a1-6ac6566ed0.zip
Binary file not shown.
Binary file added
BIN
+14.3 KB
.yarn/cache/string.prototype.trim-npm-1.2.9-7b24b35971-ea2df6ec1e.zip
Binary file not shown.
Binary file added
BIN
+11.5 KB
.yarn/cache/string.prototype.trimend-npm-1.0.8-9c0ed19266-cc3bd2de08.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+9.43 KB
.yarn/cache/typed-array-byte-length-npm-1.0.1-9ab0891fb8-f65e5ecd1c.zip
Binary file not shown.
Binary file added
BIN
+9.46 KB
.yarn/cache/typed-array-byte-offset-npm-1.0.2-14b64ee0e1-c8645c8794.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,52 @@ | ||
import { Address, SiteInfo } from "@courselit/common-models"; | ||
import { AppDispatch, AppState } from "@courselit/state-management"; | ||
import { DASHBOARD_PAGE_HEADER } from "@ui-config/strings"; | ||
import { connect } from "react-redux"; | ||
import ToDo from "./to-do"; | ||
import Metric from "./metric"; | ||
|
||
interface IndexProps { | ||
dispatch: AppDispatch; | ||
address: Address; | ||
loading: boolean; | ||
siteinfo: SiteInfo; | ||
} | ||
|
||
const Index = ({ loading, address, dispatch, siteinfo }: IndexProps) => { | ||
return ( | ||
<div> | ||
<h1 className="text-4xl font-semibold mb-8"> | ||
{DASHBOARD_PAGE_HEADER} | ||
</h1> | ||
<div className="mb-8"> | ||
<ToDo /> | ||
</div> | ||
<div className="grid xs:grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"> | ||
<Metric title="Revenue" type="purchased" duration="7d" /> | ||
<Metric title="Enrollments" type="enrolled" duration="7d" /> | ||
<Metric | ||
title="New accounts" | ||
type="user_created" | ||
duration="7d" | ||
/> | ||
<Metric | ||
title="Subscribers" | ||
type="newsletter_subscribed" | ||
duration="7d" | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const mapStateToProps = (state: AppState) => ({ | ||
address: state.address, | ||
loading: state.networkAction, | ||
siteinfo: state.siteinfo, | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch: AppDispatch) => ({ | ||
dispatch, | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Index); |
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,171 @@ | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
Select, | ||
Skeleton, | ||
} from "@courselit/components-library"; | ||
import constants from "@config/constants"; | ||
import { useEffect, useState } from "react"; | ||
import { FetchBuilder } from "@courselit/utils"; | ||
import { AppState } from "@courselit/state-management"; | ||
import { Address } from "@courselit/common-models"; | ||
import { connect } from "react-redux"; | ||
import { | ||
Line, | ||
LineChart, | ||
ResponsiveContainer, | ||
Tooltip, | ||
XAxis, | ||
YAxis, | ||
} from "recharts"; | ||
const { analyticsDurations, activityTypes } = constants; | ||
|
||
type Duration = (typeof analyticsDurations)[number]; | ||
|
||
interface MetricProps { | ||
title: string; | ||
type: (typeof activityTypes)[number]; | ||
duration?: Duration; | ||
description?: string; | ||
address: Address; | ||
} | ||
|
||
const Metric = ({ | ||
title, | ||
duration = "7d", | ||
type, | ||
description, | ||
address, | ||
}: MetricProps) => { | ||
const [data, setData] = useState<{ | ||
count: number; | ||
points: { date: string; count: number }[]; | ||
}>(); | ||
const [internalDuration, setInternalDuration] = useState(duration); | ||
const [loading, setLoading] = useState(false); | ||
|
||
useEffect(() => { | ||
const getData = async () => { | ||
const query = ` | ||
query { | ||
activities: getActivities( | ||
type: ${type.toUpperCase()}, | ||
duration: _${internalDuration.toUpperCase()} | ||
) { | ||
count, | ||
points { | ||
date, | ||
count | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const fetch = new FetchBuilder() | ||
.setUrl(`${address.backend}/api/graph`) | ||
.setPayload(query) | ||
.setIsGraphQLEndpoint(true) | ||
.build(); | ||
|
||
try { | ||
setLoading(true); | ||
const response = await fetch.exec(); | ||
if (response.activities) { | ||
const pointsWithDate = response.activities.points.map( | ||
(point: { date: string; count: number }) => { | ||
return { | ||
date: new Date( | ||
+point.date, | ||
).toLocaleDateString(), | ||
count: point.count, | ||
}; | ||
}, | ||
); | ||
|
||
setData({ | ||
count: response.activities.count, | ||
points: pointsWithDate, | ||
}); | ||
} | ||
} catch (err: any) { | ||
console.log("Error in fetching activities"); // eslint-disable-line | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
getData(); | ||
}, [internalDuration]); | ||
|
||
return ( | ||
<Card> | ||
<CardHeader> | ||
<div className="flex justify-between items-start"> | ||
<CardTitle>{title}</CardTitle> | ||
<div className="w-[90px]"> | ||
<Select | ||
value={internalDuration} | ||
disabled={loading} | ||
onChange={(e: Duration) => setInternalDuration(e)} | ||
options={[ | ||
{ label: "7d", value: "7d" }, | ||
{ label: "30d", value: "30d" }, | ||
{ label: "90d", value: "90d" }, | ||
{ label: "1y", value: "1y" }, | ||
{ label: "lifetime", value: "lifetime" }, | ||
]} | ||
variant="without-label" | ||
title={"duration"} | ||
/> | ||
</div> | ||
</div> | ||
{description && ( | ||
<CardDescription> | ||
Number of users who enrolled in a course | ||
</CardDescription> | ||
)} | ||
</CardHeader> | ||
<CardContent className="flex flex-col gap-4"> | ||
{loading && ( | ||
<div> | ||
<Skeleton className="h-8 w-full mb-2" /> | ||
<Skeleton className="h-[200px] w-full" /> | ||
</div> | ||
)} | ||
{!loading && ( | ||
<> | ||
<div className="flex text-sm text-slate-500 mb-4 font-bold justify-between"> | ||
<span>Total</span> | ||
<span>{data?.count}</span> | ||
</div> | ||
<ResponsiveContainer width="100%" height={200}> | ||
<LineChart | ||
width={300} | ||
height={200} | ||
data={data?.points} | ||
> | ||
<Line | ||
type="monotone" | ||
dataKey="count" | ||
stroke="#8884d8" | ||
/> | ||
<XAxis dataKey="date" /> | ||
<YAxis /> | ||
<Tooltip /> | ||
</LineChart> | ||
</ResponsiveContainer> | ||
</> | ||
)} | ||
</CardContent> | ||
</Card> | ||
); | ||
}; | ||
|
||
const mapStateToProps = (state: AppState) => ({ | ||
address: state.address, | ||
}); | ||
|
||
export default connect(mapStateToProps)(Metric); |
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,61 @@ | ||
import { SiteInfo } from "@courselit/common-models"; | ||
import { Link } from "@courselit/components-library"; | ||
import { AppState } from "@courselit/state-management"; | ||
import { | ||
SITE_SETTINGS_SECTION_GENERAL, | ||
SITE_SETTINGS_SECTION_PAYMENT, | ||
} from "@ui-config/strings"; | ||
import { connect } from "react-redux"; | ||
|
||
interface TodoProps { | ||
siteinfo: SiteInfo; | ||
} | ||
|
||
const Todo = ({ siteinfo }) => { | ||
return ( | ||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4"> | ||
{(!siteinfo.title || (siteinfo.logo && !siteinfo.logo.file)) && ( | ||
<div className="flex flex-col border border-red-200 p-2 rounded-lg"> | ||
<h2 className="font-semibold mb-1"> | ||
Basic details missing | ||
</h2> | ||
<p className="text-sm text-slate-500 mb-4"> | ||
Give your school a proper name, description and a logo. | ||
</p> | ||
<div> | ||
<Link | ||
href={`/dashboard/settings?tab=${SITE_SETTINGS_SECTION_GENERAL}`} | ||
> | ||
<span className="underline font-medium text-sm text-slate-700"> | ||
Update now | ||
</span> | ||
</Link> | ||
</div> | ||
</div> | ||
)} | ||
{(!siteinfo.currencyISOCode || !siteinfo.paymentMethod) && ( | ||
<div className="flex flex-col border border-red-200 p-2 rounded-lg"> | ||
<h2 className="font-semibold mb-1">Start earning</h2> | ||
<p className="text-sm text-slate-500 mb-4"> | ||
Update your payment details to sell paid products. | ||
</p> | ||
<div> | ||
<Link | ||
href={`/dashboard/settings?tab=${SITE_SETTINGS_SECTION_PAYMENT}`} | ||
> | ||
<span className="underline font-medium text-sm text-slate-700"> | ||
Update now | ||
</span> | ||
</Link> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
const mapStateToProps = (state: AppState) => ({ | ||
siteinfo: state.siteinfo, | ||
}); | ||
|
||
export default connect(mapStateToProps)(Todo); |
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
Oops, something went wrong.