feat: deals table
This commit is contained in:
@@ -1,50 +1,16 @@
|
||||
import {FC, useEffect, useState} from "react";
|
||||
import {FC} from "react";
|
||||
import PageBlock from "../../../components/PageBlock/PageBlock.tsx";
|
||||
import styles from './DealsPage.module.css';
|
||||
import DealStatusSelect from "../components/DealStatusSelect/DealStatusSelect.tsx";
|
||||
import DealsTable from "../components/DealsTable/DealsTable.tsx";
|
||||
import {useDealSummariesFull} from "../../LeadsPage/hooks/useDealSummaries.tsx";
|
||||
import {DealStatusType} from "../../../shared/enums/DealStatus.ts";
|
||||
import {BaseMarketplaceSchema, ClientSchema} from "../../../client";
|
||||
import BaseMarketplaceSelect from "../../../components/Selects/BaseMarketplaceSelect/BaseMarketplaceSelect.tsx";
|
||||
import {useForm} from "@mantine/form";
|
||||
import ClientSelectNew from "../../../components/Selects/ClientSelectNew/ClientSelectNew.tsx";
|
||||
import {DealPageContextProvider} from "../../LeadsPage/contexts/DealPageContext.tsx";
|
||||
import DealEditDrawer from "../../LeadsPage/drawers/DealEditDrawer/DealEditDrawer.tsx";
|
||||
import useDealsPageState from "../hooks/useDealsPageState.tsx";
|
||||
|
||||
type State = {
|
||||
marketplace: BaseMarketplaceSchema | null;
|
||||
dealStatus: DealStatusType | null;
|
||||
client: ClientSchema | null;
|
||||
}
|
||||
export const DealsPage: FC = () => {
|
||||
const {objects} = useDealSummariesFull();
|
||||
const form = useForm<State>({
|
||||
initialValues: {
|
||||
marketplace: null,
|
||||
dealStatus: null,
|
||||
client: null
|
||||
}
|
||||
});
|
||||
const [data, setData] = useState(objects);
|
||||
const applyFilters = () => {
|
||||
let result = objects;
|
||||
if (form.values.marketplace) {
|
||||
result = result.filter(obj => obj.baseMarketplace?.key === form.values.marketplace?.key);
|
||||
}
|
||||
if (form.values.dealStatus) {
|
||||
result = result.filter(obj => obj.status === form.values.dealStatus?.id);
|
||||
}
|
||||
if (form.values.client) {
|
||||
result = result.filter(obj => obj.clientName === form.values.client?.name);
|
||||
|
||||
}
|
||||
setData(result);
|
||||
}
|
||||
useEffect(() => {
|
||||
applyFilters();
|
||||
}, [form.values, objects])
|
||||
|
||||
const {data, form} = useDealsPageState();
|
||||
return (
|
||||
<>
|
||||
<DealPageContextProvider>
|
||||
|
||||
Reference in New Issue
Block a user