|
| 1 | +import { useParams } from 'react-router-dom'; |
| 2 | +import { |
| 3 | + Datagrid, |
| 4 | + DateInput, |
| 5 | + List, |
| 6 | + TextField, |
| 7 | + useListContext, |
| 8 | +} from 'react-admin'; |
| 9 | +import { Box } from '@mui/material'; |
| 10 | +import { FlexBox } from '../common/components/box'; |
| 11 | +import { useEffect, useState } from 'react'; |
| 12 | +import { projectionFutureApi } from '@/providers/api'; |
| 13 | + |
| 14 | +export const FluxDargentList = () => { |
| 15 | + const { id } = useParams(); |
| 16 | + |
| 17 | + return ( |
| 18 | + <List |
| 19 | + title="" |
| 20 | + resource="fluxImpossibles" |
| 21 | + queryOptions={{ |
| 22 | + meta: { patrimoineNom: id }, |
| 23 | + }} |
| 24 | + filters={[ |
| 25 | + <DateInput source="debut" label="Debut" alwaysOn />, |
| 26 | + <DateInput source="fin" label="Fin" alwaysOn />, |
| 27 | + ]} |
| 28 | + filterDefaultValues={{ |
| 29 | + fin: new Date('2024-07-30').toISOString(), |
| 30 | + debut: new Date().toISOString(), |
| 31 | + }} |
| 32 | + exporter={false} |
| 33 | + > |
| 34 | + <FlexBox> |
| 35 | + <Datagrid bulkActionButtons={false}> |
| 36 | + <FlexBox sx={{ width: '100%' }}> |
| 37 | + <Graphe /> |
| 38 | + <Box sx={{ flex: 1 }}> |
| 39 | + <TextField source="nom" label="Nom" /> |
| 40 | + </Box> |
| 41 | + </FlexBox> |
| 42 | + </Datagrid> |
| 43 | + </FlexBox> |
| 44 | + </List> |
| 45 | + ); |
| 46 | +}; |
| 47 | + |
| 48 | +export const Graphe = () => { |
| 49 | + const { id } = useParams(); |
| 50 | + const { filterValues } = useListContext(); |
| 51 | + const [state, setState] = useState<any>([]); |
| 52 | + |
| 53 | + useEffect(() => { |
| 54 | + const test = async () => { |
| 55 | + const defaultDebut = new Date().toISOString(); |
| 56 | + const defaultFin = new Date('2025-07-30').toISOString(); |
| 57 | + |
| 58 | + const graphe = await projectionFutureApi() |
| 59 | + .getPatrimoineGraph( |
| 60 | + id!, |
| 61 | + (filterValues.debut = defaultDebut), |
| 62 | + (filterValues.fin = defaultFin) |
| 63 | + ) |
| 64 | + .then((response) => response.data); |
| 65 | + setState(URL.createObjectURL(new Blob([graphe as any]))); |
| 66 | + }; |
| 67 | + test(); |
| 68 | + }, [id]); |
| 69 | + |
| 70 | + return ( |
| 71 | + <img |
| 72 | + src={state as string} |
| 73 | + width="400px" |
| 74 | + style={{ display: 'block' }} |
| 75 | + height="300px" |
| 76 | + /> |
| 77 | + ); |
| 78 | +}; |
0 commit comments