-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- dynamicParams set to true for faster page reload - FEAT: Apex Charts for displaying Enquiries trend
- Loading branch information
Showing
16 changed files
with
327 additions
and
19 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import {ApexOptions} from "apexcharts"; | ||
import {useNotificationsStore} from "@admin/store/useNotificationsStore"; | ||
import {MONTHS, MonthsType} from "@admin/lib/constants"; | ||
import {getDataForMonth, getDataTrend} from "@admin/lib"; | ||
import {useEffect, useState} from "react"; | ||
import dynamic from 'next/dynamic' | ||
import {Card} from "flowbite-react"; | ||
import {TrendIcon} from "@admin/components/Dashboard/TrendIcon"; | ||
|
||
//NOTE: Fix for ApexCharts not working with SSR | ||
const Chart = dynamic(() => import('react-apexcharts'), {ssr: false}); | ||
/** | ||
* The ApexCharts options for the email statistics | ||
*/ | ||
const chartData: ApexOptions = { | ||
chart: { | ||
height: "100%", | ||
type: "area", | ||
dropShadow: { | ||
enabled: false, | ||
}, | ||
toolbar: { | ||
show: false, | ||
}, | ||
}, | ||
tooltip: { | ||
enabled: true, | ||
x: { | ||
show: false, | ||
}, | ||
}, | ||
dataLabels: { | ||
enabled: false, | ||
}, | ||
stroke: { | ||
width: 6, | ||
}, | ||
grid: { | ||
show: false, | ||
strokeDashArray: 4, | ||
}, | ||
xaxis: { | ||
categories: MONTHS, | ||
labels: { | ||
show: false, | ||
}, | ||
axisBorder: { | ||
show: false, | ||
}, | ||
axisTicks: { | ||
show: false, | ||
}, | ||
}, | ||
yaxis: { | ||
show: false, | ||
}, | ||
}; | ||
export const EmailStatistics = () => { | ||
const {notificationPageData} = useNotificationsStore() | ||
const [data, setData] = | ||
useState<number[]>(MONTHS.map((month: MonthsType) => getDataForMonth(month, notificationPageData?.notifications ?? []))) | ||
const [trend, setTrend] = useState(getDataTrend(data)) | ||
useEffect(() => { | ||
setData(MONTHS.map((month: MonthsType) => getDataForMonth(month, notificationPageData?.notifications ?? []))) | ||
setTrend(getDataTrend(data)) | ||
}, [notificationPageData]) | ||
if (!notificationPageData || notificationPageData.notifications.length === 0) return null | ||
return ( | ||
<Card className="w-full dark:bg-gray-800 dark:border-primary-50 px-4 md:px-6"> | ||
<div className="text-cyan-800 dark:text-cyan-50 text-3xl"> | ||
<h4 className="font-bold">Statistics</h4> | ||
<div | ||
className="h-1 w-10 bg-cyan-800 rounded dark:bg-cyan-50"></div> | ||
</div> | ||
<div className="flex justify-between"> | ||
<div> | ||
<h5 className="leading-none text-3xl font-bold text-cyan-800 dark:text-cyan-50 pb-2"> | ||
<span>{notificationPageData?.notifications?.length ?? 0}</span> | ||
</h5> | ||
<p className="text-base font-normal text-gray-500 dark:text-gray-400">Enquiries this year</p> | ||
</div> | ||
<TrendIcon {...trend}/> | ||
</div> | ||
{<Chart options={chartData} series={[ | ||
{ | ||
name: "Enquiries", | ||
data: data, | ||
color: "#155E75", | ||
}, | ||
]} type="area" width="100%" height={350}/>} | ||
</Card> | ||
|
||
); | ||
} |
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,25 @@ | ||
import {TrendType} from "@admin/types"; | ||
import {getAbsoluteValue} from "@admin/lib"; | ||
import {FaArrowDown, FaArrowUp} from "react-icons/fa"; | ||
|
||
export const TrendIcon = ({trend, value}: TrendType) => { | ||
switch (trend) { | ||
case "up": | ||
return (<div | ||
className="flex items-center px-2.5 py-0.5 text-base font-semibold text-green-500 dark:text-green-500 text-center"> | ||
{getAbsoluteValue(value)}% | ||
<FaArrowUp className="ml-1 text-green-500"/> | ||
</div>) | ||
case "down": | ||
return <div | ||
className="flex items-center px-2.5 py-0.5 text-base font-semibold text-red-500 dark:text-red-500 text-center"> | ||
{getAbsoluteValue(value)}% | ||
<FaArrowDown className="ml-1 text-red-500"/> | ||
</div> | ||
case "same": | ||
return <div | ||
className="flex items-center px-2.5 py-0.5 text-base font-semibold text-gray-500 dark:text-gray-500 text-center"> | ||
{getAbsoluteValue(value)}% | ||
</div> | ||
} | ||
} |
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.