← marzneshin
/
dashboard/src/features/entity-table/contexts/sidebar-entity-table-provider.ts
/
blame
https://dev.kronoz.win/r/marzneshin.git
| 1 | 4cebd65 | Mardin | 2y ago | import { createContext, useContext } from "react"; |
| 2 | 4cebd65 | Mardin | 2y ago | import { |
| 3 | 4cebd65 | Mardin | 2y ago | type SidebarEntityCardSectionsProps |
| 4 | 4cebd65 | Mardin | 2y ago | } from "@marzneshin/features/entity-table/components"; |
| 5 | 4cebd65 | Mardin | 2y ago | |
| 6 | 4cebd65 | Mardin | 2y ago | interface SidebarEntityTableContextProps<SData> { |
| 7 | 4cebd65 | Mardin | 2y ago | sidebarEntityId?: string; |
| 8 | 4cebd65 | Mardin | 2y ago | setSidebarEntityId: (s: string | undefined) => void; |
| 9 | 4cebd65 | Mardin | 2y ago | sidebarEntities: SData[]; |
| 10 | 4cebd65 | Mardin | 2y ago | sidebarCardProps: SidebarEntityCardSectionsProps<SData>; |
| 11 | 4cebd65 | Mardin | 2y ago | } |
| 12 | 4cebd65 | Mardin | 2y ago | |
| 13 | 4cebd65 | Mardin | 2y ago | export const SidebarEntityTableContext = createContext<SidebarEntityTableContextProps<any> | null>(null); |
| 14 | 4cebd65 | Mardin | 2y ago | |
| 15 | 4cebd65 | Mardin | 2y ago | export const useSidebarEntityTableContext = () => { |
| 16 | 4cebd65 | Mardin | 2y ago | const ctx = useContext(SidebarEntityTableContext); |
| 17 | 4cebd65 | Mardin | 2y ago | if (!ctx) |
| 18 | 4cebd65 | Mardin | 2y ago | throw new Error('SidebarEntityTable.* component must be rendered as child of SidebarEntityTable'); |
| 19 | 4cebd65 | Mardin | 2y ago | return ctx; |
| 20 | 4cebd65 | Mardin | 2y ago | } |