feat: open deal by id
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { createContext, FC, useContext, useState } from "react";
|
||||
import { DealSchema } from "../../../client";
|
||||
import { createContext, FC, useContext, useEffect, useState } from "react";
|
||||
import { DealSchema, DealService } from "../../../client";
|
||||
|
||||
type DealPageContextState = {
|
||||
selectedDeal?: DealSchema;
|
||||
@@ -13,14 +13,23 @@ const DealPageContext = createContext<DealPageContextState | undefined>(
|
||||
|
||||
type DealPageContextStateProps = {
|
||||
refetchDeals: () => Promise<void>;
|
||||
defaultDealId?: number;
|
||||
}
|
||||
|
||||
const useDealPageContextState = (props: DealPageContextStateProps) => {
|
||||
const { refetchDeals } = props;
|
||||
const { refetchDeals, defaultDealId } = props;
|
||||
const [selectedDeal, setSelectedDeal] = useState<DealSchema | undefined>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!defaultDealId)
|
||||
return;
|
||||
DealService.getDealById({ dealId: defaultDealId }).then(deal => {
|
||||
setSelectedDeal(deal);
|
||||
|
||||
});
|
||||
}, []);
|
||||
return {
|
||||
selectedDeal,
|
||||
setSelectedDeal,
|
||||
@@ -31,13 +40,15 @@ const useDealPageContextState = (props: DealPageContextStateProps) => {
|
||||
type DealPageContextProviderProps = {
|
||||
children: React.ReactNode;
|
||||
refetchDeals: () => Promise<void>;
|
||||
defaultDealId?: number;
|
||||
};
|
||||
|
||||
export const DealPageContextProvider: FC<DealPageContextProviderProps> = ({
|
||||
children,
|
||||
refetchDeals,
|
||||
defaultDealId,
|
||||
}) => {
|
||||
const state = useDealPageContextState({ refetchDeals });
|
||||
const state = useDealPageContextState({ refetchDeals, defaultDealId });
|
||||
return (
|
||||
<DealPageContext.Provider value={state}>
|
||||
{children}
|
||||
|
||||
@@ -22,6 +22,7 @@ import { motion } from "framer-motion";
|
||||
import { dateWithoutTimezone } from "../../../shared/lib/date.ts";
|
||||
import DealPrefillDrawer from "../drawers/DealPrefillDrawer/DealPrefillDrawer.tsx";
|
||||
import { PrefillDealContextProvider } from "../contexts/PrefillDealContext.tsx";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
|
||||
enum DisplayMode {
|
||||
BOARD,
|
||||
@@ -30,7 +31,7 @@ enum DisplayMode {
|
||||
|
||||
export const LeadsPage: FC = () => {
|
||||
const { data, form } = useDealsPageState();
|
||||
|
||||
const { dealId } = useParams({ strict: false });
|
||||
const { summariesRaw, refetch } = useDealSummaries();
|
||||
const [summaries, setSummaries] = useState(summariesRaw);
|
||||
const [displayMode, setDisplayMode] = useState<DisplayMode>(
|
||||
@@ -394,9 +395,11 @@ export const LeadsPage: FC = () => {
|
||||
backgroundColor: "transparent",
|
||||
boxShadow: "none",
|
||||
}}>
|
||||
<DealPageContextProvider refetchDeals={async () => {
|
||||
await refetch();
|
||||
}}>
|
||||
<DealPageContextProvider
|
||||
defaultDealId={(dealId && parseInt(dealId)) || undefined}
|
||||
refetchDeals={async () => {
|
||||
await refetch();
|
||||
}}>
|
||||
<PrefillDealContextProvider>
|
||||
<PageBlock style={{ flex: 0 }}>
|
||||
<Flex
|
||||
|
||||
Reference in New Issue
Block a user