feat: open deal by id
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
				
			|||||||
import { createContext, FC, useContext, useState } from "react";
 | 
					import { createContext, FC, useContext, useEffect, useState } from "react";
 | 
				
			||||||
import { DealSchema } from "../../../client";
 | 
					import { DealSchema, DealService } from "../../../client";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type DealPageContextState = {
 | 
					type DealPageContextState = {
 | 
				
			||||||
    selectedDeal?: DealSchema;
 | 
					    selectedDeal?: DealSchema;
 | 
				
			||||||
@@ -13,14 +13,23 @@ const DealPageContext = createContext<DealPageContextState | undefined>(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
type DealPageContextStateProps = {
 | 
					type DealPageContextStateProps = {
 | 
				
			||||||
    refetchDeals: () => Promise<void>;
 | 
					    refetchDeals: () => Promise<void>;
 | 
				
			||||||
 | 
					    defaultDealId?: number;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const useDealPageContextState = (props: DealPageContextStateProps) => {
 | 
					const useDealPageContextState = (props: DealPageContextStateProps) => {
 | 
				
			||||||
    const { refetchDeals } = props;
 | 
					    const { refetchDeals, defaultDealId } = props;
 | 
				
			||||||
    const [selectedDeal, setSelectedDeal] = useState<DealSchema | undefined>(
 | 
					    const [selectedDeal, setSelectedDeal] = useState<DealSchema | undefined>(
 | 
				
			||||||
        undefined,
 | 
					        undefined,
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    useEffect(() => {
 | 
				
			||||||
 | 
					        if (!defaultDealId)
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        DealService.getDealById({ dealId: defaultDealId }).then(deal => {
 | 
				
			||||||
 | 
					            setSelectedDeal(deal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }, []);
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
        selectedDeal,
 | 
					        selectedDeal,
 | 
				
			||||||
        setSelectedDeal,
 | 
					        setSelectedDeal,
 | 
				
			||||||
@@ -31,13 +40,15 @@ const useDealPageContextState = (props: DealPageContextStateProps) => {
 | 
				
			|||||||
type DealPageContextProviderProps = {
 | 
					type DealPageContextProviderProps = {
 | 
				
			||||||
    children: React.ReactNode;
 | 
					    children: React.ReactNode;
 | 
				
			||||||
    refetchDeals: () => Promise<void>;
 | 
					    refetchDeals: () => Promise<void>;
 | 
				
			||||||
 | 
					    defaultDealId?: number;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const DealPageContextProvider: FC<DealPageContextProviderProps> = ({
 | 
					export const DealPageContextProvider: FC<DealPageContextProviderProps> = ({
 | 
				
			||||||
                                                                              children,
 | 
					                                                                              children,
 | 
				
			||||||
                                                                              refetchDeals,
 | 
					                                                                              refetchDeals,
 | 
				
			||||||
 | 
					                                                                              defaultDealId,
 | 
				
			||||||
                                                                          }) => {
 | 
					                                                                          }) => {
 | 
				
			||||||
    const state = useDealPageContextState({ refetchDeals });
 | 
					    const state = useDealPageContextState({ refetchDeals, defaultDealId });
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
        <DealPageContext.Provider value={state}>
 | 
					        <DealPageContext.Provider value={state}>
 | 
				
			||||||
            {children}
 | 
					            {children}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,6 +22,7 @@ import { motion } from "framer-motion";
 | 
				
			|||||||
import { dateWithoutTimezone } from "../../../shared/lib/date.ts";
 | 
					import { dateWithoutTimezone } from "../../../shared/lib/date.ts";
 | 
				
			||||||
import DealPrefillDrawer from "../drawers/DealPrefillDrawer/DealPrefillDrawer.tsx";
 | 
					import DealPrefillDrawer from "../drawers/DealPrefillDrawer/DealPrefillDrawer.tsx";
 | 
				
			||||||
import { PrefillDealContextProvider } from "../contexts/PrefillDealContext.tsx";
 | 
					import { PrefillDealContextProvider } from "../contexts/PrefillDealContext.tsx";
 | 
				
			||||||
 | 
					import { useParams } from "@tanstack/react-router";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum DisplayMode {
 | 
					enum DisplayMode {
 | 
				
			||||||
    BOARD,
 | 
					    BOARD,
 | 
				
			||||||
@@ -30,7 +31,7 @@ enum DisplayMode {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const LeadsPage: FC = () => {
 | 
					export const LeadsPage: FC = () => {
 | 
				
			||||||
    const { data, form } = useDealsPageState();
 | 
					    const { data, form } = useDealsPageState();
 | 
				
			||||||
 | 
					    const { dealId } = useParams({ strict: false });
 | 
				
			||||||
    const { summariesRaw, refetch } = useDealSummaries();
 | 
					    const { summariesRaw, refetch } = useDealSummaries();
 | 
				
			||||||
    const [summaries, setSummaries] = useState(summariesRaw);
 | 
					    const [summaries, setSummaries] = useState(summariesRaw);
 | 
				
			||||||
    const [displayMode, setDisplayMode] = useState<DisplayMode>(
 | 
					    const [displayMode, setDisplayMode] = useState<DisplayMode>(
 | 
				
			||||||
@@ -394,9 +395,11 @@ export const LeadsPage: FC = () => {
 | 
				
			|||||||
                backgroundColor: "transparent",
 | 
					                backgroundColor: "transparent",
 | 
				
			||||||
                boxShadow: "none",
 | 
					                boxShadow: "none",
 | 
				
			||||||
            }}>
 | 
					            }}>
 | 
				
			||||||
            <DealPageContextProvider refetchDeals={async () => {
 | 
					            <DealPageContextProvider
 | 
				
			||||||
                await refetch();
 | 
					                defaultDealId={(dealId && parseInt(dealId)) || undefined}
 | 
				
			||||||
            }}>
 | 
					                refetchDeals={async () => {
 | 
				
			||||||
 | 
					                    await refetch();
 | 
				
			||||||
 | 
					                }}>
 | 
				
			||||||
                <PrefillDealContextProvider>
 | 
					                <PrefillDealContextProvider>
 | 
				
			||||||
                    <PageBlock style={{ flex: 0 }}>
 | 
					                    <PageBlock style={{ flex: 0 }}>
 | 
				
			||||||
                        <Flex
 | 
					                        <Flex
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,6 +13,7 @@ import { createFileRoute } from '@tanstack/react-router'
 | 
				
			|||||||
// Import Routes
 | 
					// Import Routes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { Route as rootRoute } from './routes/__root'
 | 
					import { Route as rootRoute } from './routes/__root'
 | 
				
			||||||
 | 
					import { Route as LeadsDealIdImport } from './routes/leads.$dealId'
 | 
				
			||||||
import { Route as DealsDealIdImport } from './routes/deals.$dealId'
 | 
					import { Route as DealsDealIdImport } from './routes/deals.$dealId'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Create Virtual Routes
 | 
					// Create Virtual Routes
 | 
				
			||||||
@@ -106,6 +107,12 @@ const IndexLazyRoute = IndexLazyImport.update({
 | 
				
			|||||||
  getParentRoute: () => rootRoute,
 | 
					  getParentRoute: () => rootRoute,
 | 
				
			||||||
} as any).lazy(() => import('./routes/index.lazy').then((d) => d.Route))
 | 
					} as any).lazy(() => import('./routes/index.lazy').then((d) => d.Route))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const LeadsDealIdRoute = LeadsDealIdImport.update({
 | 
				
			||||||
 | 
					  id: '/$dealId',
 | 
				
			||||||
 | 
					  path: '/$dealId',
 | 
				
			||||||
 | 
					  getParentRoute: () => LeadsLazyRoute,
 | 
				
			||||||
 | 
					} as any)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const DealsDealIdRoute = DealsDealIdImport.update({
 | 
					const DealsDealIdRoute = DealsDealIdImport.update({
 | 
				
			||||||
  id: '/deals/$dealId',
 | 
					  id: '/deals/$dealId',
 | 
				
			||||||
  path: '/deals/$dealId',
 | 
					  path: '/deals/$dealId',
 | 
				
			||||||
@@ -207,17 +214,36 @@ declare module '@tanstack/react-router' {
 | 
				
			|||||||
      preLoaderRoute: typeof DealsDealIdImport
 | 
					      preLoaderRoute: typeof DealsDealIdImport
 | 
				
			||||||
      parentRoute: typeof rootRoute
 | 
					      parentRoute: typeof rootRoute
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    '/leads/$dealId': {
 | 
				
			||||||
 | 
					      id: '/leads/$dealId'
 | 
				
			||||||
 | 
					      path: '/$dealId'
 | 
				
			||||||
 | 
					      fullPath: '/leads/$dealId'
 | 
				
			||||||
 | 
					      preLoaderRoute: typeof LeadsDealIdImport
 | 
				
			||||||
 | 
					      parentRoute: typeof LeadsLazyImport
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Create and export the route tree
 | 
					// Create and export the route tree
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					interface LeadsLazyRouteChildren {
 | 
				
			||||||
 | 
					  LeadsDealIdRoute: typeof LeadsDealIdRoute
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const LeadsLazyRouteChildren: LeadsLazyRouteChildren = {
 | 
				
			||||||
 | 
					  LeadsDealIdRoute: LeadsDealIdRoute,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const LeadsLazyRouteWithChildren = LeadsLazyRoute._addFileChildren(
 | 
				
			||||||
 | 
					  LeadsLazyRouteChildren,
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface FileRoutesByFullPath {
 | 
					export interface FileRoutesByFullPath {
 | 
				
			||||||
  '/': typeof IndexLazyRoute
 | 
					  '/': typeof IndexLazyRoute
 | 
				
			||||||
  '/admin': typeof AdminLazyRoute
 | 
					  '/admin': typeof AdminLazyRoute
 | 
				
			||||||
  '/barcode': typeof BarcodeLazyRoute
 | 
					  '/barcode': typeof BarcodeLazyRoute
 | 
				
			||||||
  '/clients': typeof ClientsLazyRoute
 | 
					  '/clients': typeof ClientsLazyRoute
 | 
				
			||||||
  '/leads': typeof LeadsLazyRoute
 | 
					  '/leads': typeof LeadsLazyRouteWithChildren
 | 
				
			||||||
  '/login': typeof LoginLazyRoute
 | 
					  '/login': typeof LoginLazyRoute
 | 
				
			||||||
  '/marketplaces': typeof MarketplacesLazyRoute
 | 
					  '/marketplaces': typeof MarketplacesLazyRoute
 | 
				
			||||||
  '/products': typeof ProductsLazyRoute
 | 
					  '/products': typeof ProductsLazyRoute
 | 
				
			||||||
@@ -226,6 +252,7 @@ export interface FileRoutesByFullPath {
 | 
				
			|||||||
  '/statistics': typeof StatisticsLazyRoute
 | 
					  '/statistics': typeof StatisticsLazyRoute
 | 
				
			||||||
  '/test': typeof TestLazyRoute
 | 
					  '/test': typeof TestLazyRoute
 | 
				
			||||||
  '/deals/$dealId': typeof DealsDealIdRoute
 | 
					  '/deals/$dealId': typeof DealsDealIdRoute
 | 
				
			||||||
 | 
					  '/leads/$dealId': typeof LeadsDealIdRoute
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface FileRoutesByTo {
 | 
					export interface FileRoutesByTo {
 | 
				
			||||||
@@ -233,7 +260,7 @@ export interface FileRoutesByTo {
 | 
				
			|||||||
  '/admin': typeof AdminLazyRoute
 | 
					  '/admin': typeof AdminLazyRoute
 | 
				
			||||||
  '/barcode': typeof BarcodeLazyRoute
 | 
					  '/barcode': typeof BarcodeLazyRoute
 | 
				
			||||||
  '/clients': typeof ClientsLazyRoute
 | 
					  '/clients': typeof ClientsLazyRoute
 | 
				
			||||||
  '/leads': typeof LeadsLazyRoute
 | 
					  '/leads': typeof LeadsLazyRouteWithChildren
 | 
				
			||||||
  '/login': typeof LoginLazyRoute
 | 
					  '/login': typeof LoginLazyRoute
 | 
				
			||||||
  '/marketplaces': typeof MarketplacesLazyRoute
 | 
					  '/marketplaces': typeof MarketplacesLazyRoute
 | 
				
			||||||
  '/products': typeof ProductsLazyRoute
 | 
					  '/products': typeof ProductsLazyRoute
 | 
				
			||||||
@@ -242,6 +269,7 @@ export interface FileRoutesByTo {
 | 
				
			|||||||
  '/statistics': typeof StatisticsLazyRoute
 | 
					  '/statistics': typeof StatisticsLazyRoute
 | 
				
			||||||
  '/test': typeof TestLazyRoute
 | 
					  '/test': typeof TestLazyRoute
 | 
				
			||||||
  '/deals/$dealId': typeof DealsDealIdRoute
 | 
					  '/deals/$dealId': typeof DealsDealIdRoute
 | 
				
			||||||
 | 
					  '/leads/$dealId': typeof LeadsDealIdRoute
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface FileRoutesById {
 | 
					export interface FileRoutesById {
 | 
				
			||||||
@@ -250,7 +278,7 @@ export interface FileRoutesById {
 | 
				
			|||||||
  '/admin': typeof AdminLazyRoute
 | 
					  '/admin': typeof AdminLazyRoute
 | 
				
			||||||
  '/barcode': typeof BarcodeLazyRoute
 | 
					  '/barcode': typeof BarcodeLazyRoute
 | 
				
			||||||
  '/clients': typeof ClientsLazyRoute
 | 
					  '/clients': typeof ClientsLazyRoute
 | 
				
			||||||
  '/leads': typeof LeadsLazyRoute
 | 
					  '/leads': typeof LeadsLazyRouteWithChildren
 | 
				
			||||||
  '/login': typeof LoginLazyRoute
 | 
					  '/login': typeof LoginLazyRoute
 | 
				
			||||||
  '/marketplaces': typeof MarketplacesLazyRoute
 | 
					  '/marketplaces': typeof MarketplacesLazyRoute
 | 
				
			||||||
  '/products': typeof ProductsLazyRoute
 | 
					  '/products': typeof ProductsLazyRoute
 | 
				
			||||||
@@ -259,6 +287,7 @@ export interface FileRoutesById {
 | 
				
			|||||||
  '/statistics': typeof StatisticsLazyRoute
 | 
					  '/statistics': typeof StatisticsLazyRoute
 | 
				
			||||||
  '/test': typeof TestLazyRoute
 | 
					  '/test': typeof TestLazyRoute
 | 
				
			||||||
  '/deals/$dealId': typeof DealsDealIdRoute
 | 
					  '/deals/$dealId': typeof DealsDealIdRoute
 | 
				
			||||||
 | 
					  '/leads/$dealId': typeof LeadsDealIdRoute
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface FileRouteTypes {
 | 
					export interface FileRouteTypes {
 | 
				
			||||||
@@ -277,6 +306,7 @@ export interface FileRouteTypes {
 | 
				
			|||||||
    | '/statistics'
 | 
					    | '/statistics'
 | 
				
			||||||
    | '/test'
 | 
					    | '/test'
 | 
				
			||||||
    | '/deals/$dealId'
 | 
					    | '/deals/$dealId'
 | 
				
			||||||
 | 
					    | '/leads/$dealId'
 | 
				
			||||||
  fileRoutesByTo: FileRoutesByTo
 | 
					  fileRoutesByTo: FileRoutesByTo
 | 
				
			||||||
  to:
 | 
					  to:
 | 
				
			||||||
    | '/'
 | 
					    | '/'
 | 
				
			||||||
@@ -292,6 +322,7 @@ export interface FileRouteTypes {
 | 
				
			|||||||
    | '/statistics'
 | 
					    | '/statistics'
 | 
				
			||||||
    | '/test'
 | 
					    | '/test'
 | 
				
			||||||
    | '/deals/$dealId'
 | 
					    | '/deals/$dealId'
 | 
				
			||||||
 | 
					    | '/leads/$dealId'
 | 
				
			||||||
  id:
 | 
					  id:
 | 
				
			||||||
    | '__root__'
 | 
					    | '__root__'
 | 
				
			||||||
    | '/'
 | 
					    | '/'
 | 
				
			||||||
@@ -307,6 +338,7 @@ export interface FileRouteTypes {
 | 
				
			|||||||
    | '/statistics'
 | 
					    | '/statistics'
 | 
				
			||||||
    | '/test'
 | 
					    | '/test'
 | 
				
			||||||
    | '/deals/$dealId'
 | 
					    | '/deals/$dealId'
 | 
				
			||||||
 | 
					    | '/leads/$dealId'
 | 
				
			||||||
  fileRoutesById: FileRoutesById
 | 
					  fileRoutesById: FileRoutesById
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -315,7 +347,7 @@ export interface RootRouteChildren {
 | 
				
			|||||||
  AdminLazyRoute: typeof AdminLazyRoute
 | 
					  AdminLazyRoute: typeof AdminLazyRoute
 | 
				
			||||||
  BarcodeLazyRoute: typeof BarcodeLazyRoute
 | 
					  BarcodeLazyRoute: typeof BarcodeLazyRoute
 | 
				
			||||||
  ClientsLazyRoute: typeof ClientsLazyRoute
 | 
					  ClientsLazyRoute: typeof ClientsLazyRoute
 | 
				
			||||||
  LeadsLazyRoute: typeof LeadsLazyRoute
 | 
					  LeadsLazyRoute: typeof LeadsLazyRouteWithChildren
 | 
				
			||||||
  LoginLazyRoute: typeof LoginLazyRoute
 | 
					  LoginLazyRoute: typeof LoginLazyRoute
 | 
				
			||||||
  MarketplacesLazyRoute: typeof MarketplacesLazyRoute
 | 
					  MarketplacesLazyRoute: typeof MarketplacesLazyRoute
 | 
				
			||||||
  ProductsLazyRoute: typeof ProductsLazyRoute
 | 
					  ProductsLazyRoute: typeof ProductsLazyRoute
 | 
				
			||||||
@@ -331,7 +363,7 @@ const rootRouteChildren: RootRouteChildren = {
 | 
				
			|||||||
  AdminLazyRoute: AdminLazyRoute,
 | 
					  AdminLazyRoute: AdminLazyRoute,
 | 
				
			||||||
  BarcodeLazyRoute: BarcodeLazyRoute,
 | 
					  BarcodeLazyRoute: BarcodeLazyRoute,
 | 
				
			||||||
  ClientsLazyRoute: ClientsLazyRoute,
 | 
					  ClientsLazyRoute: ClientsLazyRoute,
 | 
				
			||||||
  LeadsLazyRoute: LeadsLazyRoute,
 | 
					  LeadsLazyRoute: LeadsLazyRouteWithChildren,
 | 
				
			||||||
  LoginLazyRoute: LoginLazyRoute,
 | 
					  LoginLazyRoute: LoginLazyRoute,
 | 
				
			||||||
  MarketplacesLazyRoute: MarketplacesLazyRoute,
 | 
					  MarketplacesLazyRoute: MarketplacesLazyRoute,
 | 
				
			||||||
  ProductsLazyRoute: ProductsLazyRoute,
 | 
					  ProductsLazyRoute: ProductsLazyRoute,
 | 
				
			||||||
@@ -380,7 +412,10 @@ export const routeTree = rootRoute
 | 
				
			|||||||
      "filePath": "clients.lazy.tsx"
 | 
					      "filePath": "clients.lazy.tsx"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "/leads": {
 | 
					    "/leads": {
 | 
				
			||||||
      "filePath": "leads.lazy.tsx"
 | 
					      "filePath": "leads.lazy.tsx",
 | 
				
			||||||
 | 
					      "children": [
 | 
				
			||||||
 | 
					        "/leads/$dealId"
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "/login": {
 | 
					    "/login": {
 | 
				
			||||||
      "filePath": "login.lazy.tsx"
 | 
					      "filePath": "login.lazy.tsx"
 | 
				
			||||||
@@ -405,6 +440,10 @@ export const routeTree = rootRoute
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    "/deals/$dealId": {
 | 
					    "/deals/$dealId": {
 | 
				
			||||||
      "filePath": "deals.$dealId.tsx"
 | 
					      "filePath": "deals.$dealId.tsx"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "/leads/$dealId": {
 | 
				
			||||||
 | 
					      "filePath": "leads.$dealId.tsx",
 | 
				
			||||||
 | 
					      "parent": "/leads"
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								src/routes/leads.$dealId.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/routes/leads.$dealId.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					import { createFileRoute } from "@tanstack/react-router";
 | 
				
			||||||
 | 
					import { LeadsPage } from "../pages/LeadsPage";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const Route = createFileRoute("/leads/$dealId")({
 | 
				
			||||||
 | 
					    component: LeadsPage,
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
		Reference in New Issue
	
	Block a user