175 lines
5.8 KiB
TypeScript
175 lines
5.8 KiB
TypeScript
import { mdiChartTimelineVariant } from '@mdi/js'
|
|
import Head from 'next/head'
|
|
import { uniqueId } from 'lodash';
|
|
import React, { ReactElement, useState } from 'react'
|
|
import CardBox from '../../components/CardBox'
|
|
import LayoutAuthenticated from '../../layouts/Authenticated'
|
|
import SectionMain from '../../components/SectionMain'
|
|
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton'
|
|
import LegalOpsPageIntro from '../../components/LegalOpsPageIntro'
|
|
import { getPageTitle } from '../../config'
|
|
import TablePractice_groups from '../../components/Practice_groups/TablePractice_groups'
|
|
import BaseButton from '../../components/BaseButton'
|
|
import axios from "axios";
|
|
import {useAppDispatch, useAppSelector} from "../../stores/hooks";
|
|
import CardBoxModal from "../../components/CardBoxModal";
|
|
import DragDropFilePicker from "../../components/DragDropFilePicker";
|
|
import {setRefetch, uploadCsv} from '../../stores/practice_groups/practice_groupsSlice';
|
|
|
|
|
|
import {hasPermission} from "../../helpers/userPermissions";
|
|
|
|
|
|
|
|
const Practice_groupsTablesPage = () => {
|
|
const [filterItems, setFilterItems] = useState([]);
|
|
const [csvFile, setCsvFile] = useState<File | null>(null);
|
|
const [isModalActive, setIsModalActive] = useState(false);
|
|
const [showTableView, setShowTableView] = useState(false);
|
|
|
|
|
|
const { currentUser } = useAppSelector((state) => state.auth);
|
|
|
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
|
|
const [filters] = useState([{label: 'Practice group name', title: 'name'},{label: 'Description', title: 'description'},
|
|
|
|
|
|
|
|
|
|
|
|
{label: 'Practice group lead', title: 'lead_user'},
|
|
|
|
|
|
|
|
|
|
]);
|
|
|
|
const hasCreatePermission = currentUser && hasPermission(currentUser, 'CREATE_PRACTICE_GROUPS');
|
|
|
|
|
|
const addFilter = () => {
|
|
const newItem = {
|
|
id: uniqueId(),
|
|
fields: {
|
|
filterValue: '',
|
|
filterValueFrom: '',
|
|
filterValueTo: '',
|
|
selectedField: '',
|
|
},
|
|
};
|
|
newItem.fields.selectedField = filters[0].title;
|
|
setFilterItems([...filterItems, newItem]);
|
|
};
|
|
|
|
const getPractice_groupsCSV = async () => {
|
|
const response = await axios({url: '/practice_groups?filetype=csv', method: 'GET',responseType: 'blob'});
|
|
const type = response.headers['content-type']
|
|
const blob = new Blob([response.data], { type: type })
|
|
const link = document.createElement('a')
|
|
link.href = window.URL.createObjectURL(blob)
|
|
link.download = 'practice_groupsCSV.csv'
|
|
link.click()
|
|
};
|
|
|
|
const onModalConfirm = async () => {
|
|
if (!csvFile) return;
|
|
await dispatch(uploadCsv(csvFile));
|
|
dispatch(setRefetch(true));
|
|
setCsvFile(null);
|
|
setIsModalActive(false);
|
|
};
|
|
|
|
const onModalCancel = () => {
|
|
setCsvFile(null);
|
|
setIsModalActive(false);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Head>
|
|
<title>{getPageTitle('Practice groups')}</title>
|
|
</Head>
|
|
<SectionMain>
|
|
<SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="Practice groups" main>
|
|
{''}
|
|
</SectionTitleLineWithButton>
|
|
<LegalOpsPageIntro
|
|
eyebrow='Legal ownership map'
|
|
title='Route AI governance work to the right legal practice teams'
|
|
description='Maintain practice groups, group leads, active status, and descriptions so AI use cases, reviews, and policies can be assigned to accountable legal owners.'
|
|
metrics={[
|
|
{ label: 'Ownership', value: 'Practice lead', helper: 'Each group can anchor review responsibility and escalation.' },
|
|
{ label: 'Routing', value: 'Use-case context', helper: 'AI requests inherit the right legal domain and reviewer context.' },
|
|
{ label: 'Governance', value: 'Active groups', helper: 'Inactive groups stay out of day-to-day routing decisions.' },
|
|
]}
|
|
>
|
|
{hasCreatePermission && <BaseButton href={'/practice_groups/practice_groups-new'} color='info' label='New practice group'/>}
|
|
<BaseButton
|
|
color='info'
|
|
label='Add filter'
|
|
onClick={addFilter}
|
|
/>
|
|
<BaseButton color='whiteDark' label='Export CSV' onClick={getPractice_groupsCSV} />
|
|
|
|
{hasCreatePermission && (
|
|
<BaseButton
|
|
color='whiteDark'
|
|
label='Upload CSV'
|
|
onClick={() => setIsModalActive(true)}
|
|
/>
|
|
)}
|
|
|
|
<div className='md:inline-flex items-center ms-auto'>
|
|
<div id='delete-rows-button'></div>
|
|
</div>
|
|
|
|
<BaseButton href={'/practice_groups/practice_groups-table'} color='whiteDark' label='Table view'/>
|
|
|
|
</LegalOpsPageIntro>
|
|
|
|
<CardBox className="mb-6" hasTable>
|
|
<TablePractice_groups
|
|
filterItems={filterItems}
|
|
setFilterItems={setFilterItems}
|
|
filters={filters}
|
|
showGrid={false}
|
|
/>
|
|
</CardBox>
|
|
|
|
</SectionMain>
|
|
<CardBoxModal
|
|
title='Upload CSV'
|
|
buttonColor='info'
|
|
buttonLabel={'Confirm'}
|
|
// buttonLabel={false ? 'Deleting...' : 'Confirm'}
|
|
isActive={isModalActive}
|
|
onConfirm={onModalConfirm}
|
|
onCancel={onModalCancel}
|
|
>
|
|
<DragDropFilePicker
|
|
file={csvFile}
|
|
setFile={setCsvFile}
|
|
formats={'.csv'}
|
|
/>
|
|
</CardBoxModal>
|
|
</>
|
|
)
|
|
}
|
|
|
|
Practice_groupsTablesPage.getLayout = function getLayout(page: ReactElement) {
|
|
return (
|
|
<LayoutAuthenticated
|
|
|
|
permission={'READ_PRACTICE_GROUPS'}
|
|
|
|
>
|
|
{page}
|
|
</LayoutAuthenticated>
|
|
)
|
|
}
|
|
|
|
export default Practice_groupsTablesPage
|