fix: user management & profit chart

This commit is contained in:
ferdiansyah783
2025-08-10 15:47:04 +07:00
parent de93de2e6d
commit 48570c018f
23 changed files with 989 additions and 599 deletions
@@ -0,0 +1,31 @@
// Next Imports
// Type Imports
// Component Imports
import OrderDetails from '@views/apps/ecommerce/orders/details'
/**
* ! If you need data using an API call, uncomment the below API code, update the `process.env.API_URL` variable in the
* ! `.env` file found at root of your project and also update the API endpoints like `/apps/ecommerce` in below example.
* ! Also, remove the above server action import and the action itself from the `src/app/server/actions.ts` file to clean up unused code
* ! because we've used the server action for getting our static data.
*/
/* const getEcommerceData = async () => {
// Vars
const res = await fetch(`${process.env.API_URL}/apps/ecommerce`)
if (!res.ok) {
throw new Error('Failed to fetch ecommerce data')
}
return res.json()
} */
const OrderDetailsPage = async () => {
return <OrderDetails />
}
export default OrderDetailsPage
@@ -21,7 +21,7 @@ import UserList from '@views/apps/user/list'
const UserListApp = async () => {
return <UserList userData={[]} />
return <UserList />
}
export default UserListApp
@@ -5,15 +5,13 @@ import Grid from '@mui/material/Grid2'
// Component Imports
import DistributedBarChartOrder from '@views/dashboards/crm/DistributedBarChartOrder'
import EarningReportsWithTabs from '@views/dashboards/crm/EarningReportsWithTabs'
// Server Action Imports
import Loading from '../../../../../../components/layout/shared/Loading'
import { useProfitLossAnalytics } from '../../../../../../services/queries/analytics'
import {
ProductDataReport,
ProfitLossReport
} from '../../../../../../types/services/analytic'
import { DailyData, ProductDataReport, ProfitLossReport } from '../../../../../../types/services/analytic'
import EarningReportsWithTabs from '../../../../../../views/dashboards/crm/EarningReportsWithTabs'
import MultipleSeries from '../../../../../../views/dashboards/profit-loss/EarningReportWithTabs'
function formatMetricName(metric: string): string {
const nameMap: { [key: string]: string } = {
@@ -41,7 +39,7 @@ const DashboardProfitLoss = () => {
})
}
const metrics = ['revenue', 'cost', 'gross_profit', 'net_profit']
const metrics = ['cost', 'revenue', 'gross_profit', 'net_profit']
const transformSalesData = (data: ProfitLossReport) => {
return [
@@ -50,16 +48,30 @@ const DashboardProfitLoss = () => {
avatarIcon: 'tabler-package',
date: data.product_data.map((d: ProductDataReport) => d.product_name),
series: [{ data: data.product_data.map((d: ProductDataReport) => d.revenue) }]
},
// {
// type: 'profits',
// avatarIcon: 'tabler-currency-dollar',
// date: data.data.map((d: DailyData) => formatDate(d.date)),
// series: metrics.map(metric => ({
// name: formatMetricName(metric as string),
// data: data.data.map((item: any) => item[metric] as number)
// }))
// }
}
// {
// type: 'profits',
// avatarIcon: 'tabler-currency-dollar',
// date: data.data.map((d: DailyData) => formatDate(d.date)),
// series: metrics.map(metric => ({
// name: formatMetricName(metric as string),
// data: data.data.map((item: any) => item[metric] as number)
// }))
// }
]
}
const transformMultipleData = (data: ProfitLossReport) => {
return [
{
type: 'profits',
avatarIcon: 'tabler-currency-dollar',
date: data.data.map((d: DailyData) => formatDate(d.date)),
series: metrics.map(metric => ({
name: formatMetricName(metric as string),
data: data.data.map((item: any) => item[metric] as number)
}))
}
]
}
@@ -110,6 +122,9 @@ const DashboardProfitLoss = () => {
<Grid size={{ xs: 12, lg: 12 }}>
<EarningReportsWithTabs data={transformSalesData(data!)} />
</Grid>
<Grid size={{ xs: 12, lg: 12 }}>
<MultipleSeries data={transformMultipleData(data!)} />
</Grid>
</Grid>
)
}