Skip to content

Commit

Permalink
Merge pull request #6 from Samagra-Anamaya/ste-tabs
Browse files Browse the repository at this point in the history
Ste tabs
  • Loading branch information
amit-s19 authored Dec 6, 2023
2 parents 20585ce + 0effcd6 commit 00287fd
Show file tree
Hide file tree
Showing 11 changed files with 770 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/authProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const authProvider: AuthProvider = {
);
return fetch(request)
.then((response) => {
console.log({ response });
if (response.status < 200 || response.status >= 300) {
throw new Error(response.statusText);
}
Expand All @@ -32,6 +31,8 @@ export const authProvider: AuthProvider = {
localStorage.setItem("token", resp.result.data.user.token);
localStorage.setItem("user", JSON.stringify(resp?.result?.data?.user))
return Promise.resolve(resp);
} else {
throw new Error(resp?.params?.errMsg);
}
});
},
Expand Down
22 changes: 21 additions & 1 deletion src/components/MenuOptions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import gps from "../../pages/gps";
import villages from "../../pages/villages";
import submissions from "../../pages/submissions";
import transactions from "../../pages/transactions";
import records from "../../pages/records";

const MenuOptions: any[] = [
{
Expand All @@ -27,7 +29,25 @@ const MenuOptions: any[] = [
icon: "submissionIcon",

permissions: ["admin"]
}
},
{
name: "Transactions",
resource: "transactions",
props: transactions,

icon: "submissionIcon",

permissions: ["department"]
},
{
name: "Records",
resource: "records",
props: records,

icon: "submissionIcon",

permissions: ["department"]
},
];

export const MenuItemsWithPermissionResolver = (permissions: any) => {
Expand Down
41 changes: 41 additions & 0 deletions src/dataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const customDataProvider = {
});
}
}

if (resource === "submissions") {

const { page, perPage } = params.pagination;
Expand Down Expand Up @@ -135,11 +136,38 @@ export const customDataProvider = {
});
}
}
if (resource == 'transactions') {
const { page, perPage } = params.pagination;
const url = `${import.meta.env.VITE_SIMPLE_REST_URL
}/ste/transactionHistory?page=${page}&limit=${perPage}`;
return httpClient(url).then(({ headers, json }) => {
console.log({ headers, json });

return {
data: json,
total: json?.length,
};
});
}
if (resource == 'records') {
const { page, perPage } = params.pagination;
const url = `${import.meta.env.VITE_SIMPLE_REST_URL
}/ste/savedSchemeTransactions?page=${page}&limit=${perPage}`;
return httpClient(url).then(({ headers, json }) => {
console.log({ headers, json });

return {
data: json,
total: json?.length,
};
});
}
// For other resources, use the default implementation
return dataProvider.getList(resource, params);
},
getOne: (resource: any, params: any) => {
console.log({ resource, params })

if (resource === "submissions") {
console.log("hello");
const { id } = params;
Expand All @@ -156,6 +184,19 @@ export const customDataProvider = {
};
});
}

if (resource === 'transactions') {
const url = `${import.meta.env.VITE_SIMPLE_REST_URL
}/ste/transactionHistory/${params.id}`;
return httpClient(url).then(({ headers, json }) => {
console.log({ headers, json });

return {
data: json
};
});
}

// // For other resources, use the default implementation
return dataProvider.getOne(resource, params);
},
Expand Down
176 changes: 176 additions & 0 deletions src/pages/records/RecordsList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import * as React from 'react';
import { Fragment, memo } from 'react';
import BookIcon from '@mui/icons-material/Book';
import { Box, Chip, useMediaQuery } from '@mui/material';
import { Theme, styled } from '@mui/material/styles';
import lodashGet from 'lodash/get';
import jsonExport from 'jsonexport/dist';
import {
BooleanField,
BulkDeleteButton,
BulkExportButton,
ChipField,
SelectColumnsButton,
CreateButton,
DatagridConfigurable,
DateField,
downloadCSV,
EditButton,
ExportButton,
FilterButton,
List,
InfiniteList,
NumberField,
ReferenceArrayField,
ReferenceManyCount,
SearchInput,
ShowButton,
SimpleList,
SingleFieldList,
TextField,
TextInput,
TopToolbar,
useTranslate,
useRedirect,
Datagrid,
} from 'react-admin'; // eslint-disable-line import/no-unresolved
import { useLocation } from 'react-router-dom';

export const PostIcon = BookIcon;



const exporter = posts => {
const data = posts.map(post => ({
...post,
backlinks: lodashGet(post, 'backlinks', []).map(
backlink => backlink.url
),
}));
return jsonExport(data, (err, csv) => downloadCSV(csv, 'posts'));
};

const PostListMobileActions = () => (
<TopToolbar>
<ExportButton />
</TopToolbar>
);

const RecordsListMobile = () => (
<InfiniteList
// sort={{ field: 'published_at', order: 'DESC' }}
exporter={exporter}
actions={<PostListMobileActions />}
>
<SimpleList
primaryText={record => record.gpCode}
secondaryText={record => record.gpName}
tertiaryText={record => record.villagesUnderGp}
/>
</InfiniteList>
);

const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({
'& .title': {
maxWidth: '16em',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
},
'& .hiddenOnSmallScreens': {
[theme.breakpoints.down('lg')]: {
display: 'none',
},
},
'& .column-tags': {
minWidth: '9em',
},
'& .publishedAt': { fontStyle: 'italic' },
}));

const PostListBulkActions = memo(
({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
children,
...props
}) => (
<Fragment>
<BulkDeleteButton {...props} />
<BulkExportButton {...props} />
</Fragment>
)
);

const PostListActions = () => (
<TopToolbar>
<SelectColumnsButton />
<ExportButton />
</TopToolbar>
);

const PostListActionToolbar = ({ children }) => (
<Box sx={{ alignItems: 'center', display: 'flex' }}>{children}</Box>
);



const tagSort = { field: 'name.en', order: 'ASC' };

const RecordsListDesktop = () => {
const location = useLocation();
const params: any = new URLSearchParams(location.search);
for (const [key, value] of params) {
console.log(key, value)
}

// const Filters = [
// <TextInput label="GP Code" source="gpCode" alwaysOn />
// ]



return <><List
// filters={Filters}
exporter={exporter}
actions={<PostListActions />}
filterDefaultValues={{
gpCode: '5433'
}}
>
<DatagridConfigurable
bulkActionButtons={false}
>
<TextField source="id" label="ID" />
<TextField source="aadhaar_number" label="Aadhaar Number" />
<TextField source="aadhaar_reference_number" label="Aadhaar Reference Number" />
<TextField source="unique_beneficiary_id" label="Unique Beneficiary ID" />
<TextField source="financial_year" label="Financial Year" />
<TextField source="in_kind_benefit_detail" label="Benefit Detail In Kind" />
<TextField source="scheme_code" label="Scheme Code" />
<TextField source="transaction_amount" label="Transaction Amount" />
<TextField source="transaction_date" label="Transaction Date" />
<TextField source="transaction_type" label="Transaction Type" />
</DatagridConfigurable>
</List>
<style>
{`
.MuiTablePagination-selectLabel {
margin-top: 1em;
}
.MuiTablePagination-displayedRows {
margin-top: 1rem;
}
`}
</style>
</>
};

const RecordsList = () => {
const isSmall = useMediaQuery<Theme>(
theme => theme.breakpoints.down('sm'),
{ noSsr: true }
);
return isSmall ? <RecordsListMobile /> : <RecordsListDesktop />;
};

export default RecordsList;
10 changes: 10 additions & 0 deletions src/pages/records/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

import RecordsList from './RecordsList'

export default {
list: RecordsList,
permissions: {
canList: ["department"],
},
recordRepresentation: 'title',
};
Loading

0 comments on commit 00287fd

Please sign in to comment.