Skip to content

Commit

Permalink
final fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xWyvernPx committed Nov 7, 2023
1 parent aea8475 commit eed231e
Show file tree
Hide file tree
Showing 23 changed files with 521 additions and 121 deletions.
40 changes: 28 additions & 12 deletions src/base/components/common/chart/IncomeAreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTheme } from '@mui/material/styles';
// third-party
import ReactApexChart, { Props as ChartProps } from 'react-apexcharts';
import useConfig from '@/base/hooks/useConfig';
import useAnalytics from './useAnalytics';

// project import
// import useConfig from 'hooks/useConfig';
Expand Down Expand Up @@ -45,6 +46,9 @@ const IncomeAreaChart = ({ slot }: Props) => {
const line = theme.palette.divider;

const [options, setOptions] = useState<ChartProps>(areaChartOptions);
const {cusAnaWeek, kitchenAnaWeek} = useAnalytics(slot as ("month"| "week"));
console.log("cusAnaWeek=>", cusAnaWeek);
console.log("kitchenAnaWeek=>", kitchenAnaWeek);

useEffect(() => {
setOptions((prevState) => ({
Expand Down Expand Up @@ -105,19 +109,31 @@ const IncomeAreaChart = ({ slot }: Props) => {
data: [0, 43, 14, 56, 24, 105, 68]
}
]);

useEffect(() => {
useEffect(()=>{
setSeries([
{
name: 'Kitchen',
data: slot === 'month' ? [76, 85, 101, 98, 87, 105, 91, 114, 94, 86, 115, 35] : [31, 40, 28, 51, 42, 109, 100]
},
{
name: 'Customer',
data: slot === 'month' ? [110, 60, 150, 35, 60, 36, 26, 45, 65, 52, 53, 41] : [11, 32, 45, 32, 34, 52, 41]
}
]);
}, [slot]);
{
name: 'Kitchen',
data: kitchenAnaWeek
},
{
name: 'Customer',
data: cusAnaWeek
}
]);
},[cusAnaWeek, kitchenAnaWeek])
// useEffect(() => {
// setSeries([
// {
// name: 'Kitchen',
// data: slot === 'month' ? [76, 85, 101, 98, 87, 105, 91, 114, 94, 86, 115, 35] : [31, 40, 28, 51, 42, 109, 100]
// },
// {
// name: 'Customer',
// data: slot === 'month' ? [110, 60, 150, 35, 60, 36, 26, 45, 65, 52, 53, 41] : [11, 32, 45, 32, 34, 52, 41]
// }
// ]);
// }, [slot]);


return <ReactApexChart options={options} series={series} type="area" height={450} />;
};
Expand Down
4 changes: 2 additions & 2 deletions src/base/components/common/chart/OrdersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ const OrderStatusRender = ({ status }: Props) => {
color = 'success';
title = 'Paid';
break;
case "CANCEL":
case "CANCELED":
color = 'error';
title = 'Rejected';
break;
case "COMPLETE":
case "COMPLETED":
color = 'primary';
title = 'Complete';
break;
Expand Down
105 changes: 105 additions & 0 deletions src/base/components/common/chart/useAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import axiosClient from '@/base/service/axiosClient';
import { useEffect, useState } from 'react'



const dates = ['2023-10-30', '2023-10-31', '2023-11-01','2023-11-02', '2023-11-03', '2023-11-04', '2023-11-05']
const months = [
{
from: '2023-01-01T00:00:00.000',
to: '2023-01-31T23:59:59.000'
},
{
from: '2023-02-01T00:00:00.000',
to: '2023-02-28T23:59:59.000'
},
{
from: '2023-03-01T00:00:00.000',
to: '2023-03-31T23:59:59.000'
},
{
from: '2023-04-01T00:00:00.000',
to: '2023-04-30T23:59:59.000'
},
{
from: '2023-05-01T00:00:00.000',
to: '2023-05-31T23:59:59.000'
},
{
from: '2023-06-01T00:00:00.000',
to: '2023-06-30T23:59:59.000'
},
{
from: '2023-07-01T00:00:00.000',
to: '2023-07-31T23:59:59.000'
},
{
from: '2023-08-01T00:00:00.000',
to: '2023-08-31T23:59:59.000'
},
{
from: '2023-09-01T00:00:00.000',
to: '2023-09-30T23:59:59.000'
},
{
from: '2023-10-01T00:00:00.000',
to: '2023-10-31T23:59:59.000'
},
{
from: '2023-11-01T00:00:00.000',
to: '2023-11-30T23:59:59.000'
},
{
from: '2023-12-01T00:00:00.000',
to: '2023-12-31T23:59:59.000'
}
];
const useAnalytics = (type : "week" | "month") => {
const [kitchenAnaWeek, setKitchen] = useState<number[]>([]);
const [cusAnaWeek, setCus] = useState<number[]>([]);
const fetchKitchenWeek = async () => {
const rawRes = await Promise.all(months.map(m => axiosClient.get("/kitchen", {params: {
FromDate : m.from,
ToDate : m.to
}}).then(d=>d.data).then(d => d?.totalCount)))
setKitchen(rawRes)
}
const fetchCustomerWeek = async () => {
const rawRes = await Promise.all(months.map(m => axiosClient.get("/customer", {params: {
FromDate : m.from,
ToDate : m.to
}}).then(d=>d.data).then(d => d?.totalCount)))
setCus(rawRes);
}

const fetchKitchenMonth = async () => {
const rawRes = await Promise.all(dates.map(d => axiosClient.get("/kitchen", {params: {
FromDate : d+"T00:00:00.000",
ToDate : d+"T23:59:59.000"
}}).then(d=>d.data).then(d => d?.totalCount)))
setKitchen(rawRes)
}
const fetchCustomerMonth = async () => {
const rawRes = await Promise.all(dates.map(d => axiosClient.get("/customer", {params: {
FromDate : d+"T00:00:00.000",
ToDate : d+"T23:59:59.000"
}}).then(d=>d.data).then(d => d?.totalCount)))
setCus(rawRes);
}
useEffect(()=>{
if(type =="month"){
fetchKitchenWeek();
fetchCustomerWeek();
}else {
fetchKitchenMonth();
fetchCustomerMonth();
}
},[type])
return ({
kitchenAnaWeek,
cusAnaWeek
}
)
}

export default useAnalytics
3 changes: 1 addition & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'react-toastify/dist/ReactToastify.css';
* Fix regeneratorRuntime is not defined
*/
import "regenerator-runtime";
// import "./utils/errorTracking/sentry";
import "./utils/errorTracking/sentry";
import { LocalizationProvider } from "@mui/x-date-pickers";
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
import { QueryClientProvider } from "react-query";
Expand All @@ -21,7 +21,6 @@ import { FirebaseProvider } from "./base/store/context/FirebaseContext.tsx";

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>

<QueryClientProvider client={queryClient}>
<LocalizationProvider dateAdapter={AdapterDayjs}>
<RecoilRoot>
Expand Down
15 changes: 11 additions & 4 deletions src/modules/area/hooks/useAreaTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@ const useAreaTable = (props: Props) => {
},
meta: {
align: "left"
}
},
enableSorting:false,

}),
columnHelper.accessor("name", {
header: "Area Name",
meta: {
align: "left"
}
},
enableSorting:false,

}),
columnHelper.accessor("noOfKitchens", {
header: "Number of kitchens",
Expand All @@ -91,7 +95,8 @@ const useAreaTable = (props: Props) => {
),
meta: {
align: "right"
}
},
enableSorting:false,
}),
columnHelper.accessor("createdDate", {
header: "CreatedDate",
Expand All @@ -100,7 +105,9 @@ const useAreaTable = (props: Props) => {
},
meta: {
align: "left"
}
},
enableSorting:false,

}),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
columnHelper.accessor<any, any>("action", {
Expand Down
21 changes: 14 additions & 7 deletions src/modules/customer/pages/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const CustomerList = () => {
refreshCustomerData,
setSortState,
deleteCustomer: {mutateAsync : mutateDelete},
totalRows
totalRows,
setKeyword
} = useCustomerData();
useEffect(()=>{
refreshCustomerData()
Expand Down Expand Up @@ -109,7 +110,7 @@ const CustomerList = () => {
),
enableSorting: false,
}),
columnHelper.accessor("id", {
columnHelper.accessor("no", {
header: () => {
return "#";
},
Expand Down Expand Up @@ -146,7 +147,9 @@ const CustomerList = () => {
},
meta: {
align : "left"
}
},
enableSorting: false,

}),
// columnHelper.accessor("user.avatarUrl", {
// header: "Avatar",
Expand Down Expand Up @@ -176,7 +179,8 @@ const CustomerList = () => {
),
meta: {
align : "left"
}
},
enableSorting: false,
}),
columnHelper.accessor("orderQuantity", {
header: "Order",
Expand All @@ -185,7 +189,8 @@ const CustomerList = () => {
),
meta: {
align : "right"
}
},
enableSorting: false,
}),
columnHelper.accessor("spentMoney", {
header: "Spent",
Expand All @@ -200,7 +205,9 @@ const CustomerList = () => {
),
meta: {
align : "right"
}
},
enableSorting: false,

}),
columnHelper.accessor("status", {
header: "Status",
Expand Down Expand Up @@ -340,7 +347,7 @@ const CustomerList = () => {
</IconButton>
</>
}
onSearchKeywordChange={(q) => console.log(q)}
onSearchKeywordChange={(q) => setKeyword(q)}
onSortByChange={(sort) => setSortState(sort)}
filter={{
isShow: true,
Expand Down
11 changes: 10 additions & 1 deletion src/modules/customer/service/customer.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ interface CustomerGetParams {
keyword?: string;
// filter :
}
const customerKeyMap = {
no : "No",
email :"Email",
status : "Status"
}
const CustomerApi = {
getCustomers: (params: CustomerGetParams) => {
const endpoint = "/customer";
return axiosClient.get<ResponseObject<CustomerAdmin[]>>(endpoint, {
params: {
PageNumber: params.paging.pageIndex + 1 ?? 1,
PageSize: params.paging?.pageSize ?? 10
PageSize: params.paging?.pageSize ?? 10,
KeySearch : params?.keyword??"",
...((!!params?.sort ?? false) && (!!params?.sort?.[0] ?? false) ? {
OrderBy: `${customerKeyMap[params?.sort?.[0]?.id??"no"]??"No"}:${params?.sort?.[0]?.desc? "desc" : "asc"}`,
} :{})

},
});
Expand Down
Loading

0 comments on commit eed231e

Please sign in to comment.