summaryrefslogtreecommitdiff
path: root/src/lib/ServiceContext.tsx
blob: 2001d00bb737f37d543fe2d983c9fa6a4896b29c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React from 'react';
import { FormikProps } from 'formik';
import { Props as ButtonProps } from '../components/Button';
import { Field } from '../components/ListTable';
import { Option } from '../components/Select';

export interface Action extends ButtonProps {
  name: string;
}

export interface Filter extends Field {
  as?: string;
  options?: Option[];
  value?: string;
}

export interface PanelProps<T> {
  item: T;
  mutate: (item: T) => void;
}

export interface ServiceParams<T = any> {
  route: string;
  name: string;
  tableFields: Field[];
  nameSingular?: string;
  default?: Partial<T>;
  routes?: Record<string, React.FC>;
  actions?: Action[];
  filters?: Filter[];
  rowLink?: (item: T) => string;
  Form?: React.FC<FormikProps<T>>;
  Panel?: React.FC<PanelProps<T>>;
}

const ServiceContext = React.createContext<ServiceParams>({
  route: '',
  name: '',
  nameSingular: '',
  tableFields: [],
  default: {},
});

export const ServiceProvider = ServiceContext.Provider;
export default ServiceContext;