mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
fix: project timesheet table.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { useProject } from '../../../hooks';
|
import { useProject, useProjectTimeEntries } from '../../../hooks';
|
||||||
|
|
||||||
const ProjectTimesheetContext = React.createContext();
|
const ProjectTimesheetContext = React.createContext();
|
||||||
|
|
||||||
@@ -12,6 +12,14 @@ function ProjectTimesheetsProvider({ ...props }) {
|
|||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const projectId = parseInt(id, 10);
|
const projectId = parseInt(id, 10);
|
||||||
|
|
||||||
|
// fetch project time entries.
|
||||||
|
const {
|
||||||
|
data: { projectTimeEntries },
|
||||||
|
isLoading: isProjectTimeEntriesLoading,
|
||||||
|
} = useProjectTimeEntries(projectId, {
|
||||||
|
enabled: !!projectId,
|
||||||
|
});
|
||||||
|
|
||||||
// Handle fetch project detail.
|
// Handle fetch project detail.
|
||||||
const { data: project } = useProject(projectId, {
|
const { data: project } = useProject(projectId, {
|
||||||
enabled: !!projectId,
|
enabled: !!projectId,
|
||||||
@@ -21,6 +29,8 @@ function ProjectTimesheetsProvider({ ...props }) {
|
|||||||
const provider = {
|
const provider = {
|
||||||
projectId,
|
projectId,
|
||||||
project,
|
project,
|
||||||
|
projectTimeEntries,
|
||||||
|
isProjectTimeEntriesLoading,
|
||||||
};
|
};
|
||||||
|
|
||||||
return <ProjectTimesheetContext.Provider value={provider} {...props} />;
|
return <ProjectTimesheetContext.Provider value={provider} {...props} />;
|
||||||
|
|||||||
@@ -6,10 +6,13 @@ import {
|
|||||||
TableSkeletonHeader,
|
TableSkeletonHeader,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { ActionsMenu } from './components';
|
import { ActionsMenu } from './components';
|
||||||
import { useProjectTimesheetColumns } from './hooks';
|
|
||||||
import { TABLES } from '@/constants/tables';
|
import { TABLES } from '@/constants/tables';
|
||||||
|
import { useProjectTimesheetColumns } from './hooks';
|
||||||
import { useMemorizedColumnsWidths } from '@/hooks';
|
import { useMemorizedColumnsWidths } from '@/hooks';
|
||||||
|
import { useProjectTimesheetContext } from './ProjectTimesheetsProvider';
|
||||||
import withSettings from '@/containers/Settings/withSettings';
|
import withSettings from '@/containers/Settings/withSettings';
|
||||||
|
import withAlertsActions from '@/containers/Alert/withAlertActions';
|
||||||
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
|
|
||||||
import { compose } from '@/utils';
|
import { compose } from '@/utils';
|
||||||
|
|
||||||
@@ -20,12 +23,25 @@ import { compose } from '@/utils';
|
|||||||
function ProjectTimesheetsTableRoot({
|
function ProjectTimesheetsTableRoot({
|
||||||
// #withSettings
|
// #withSettings
|
||||||
timesheetsTableSize,
|
timesheetsTableSize,
|
||||||
|
|
||||||
|
// #withDialog
|
||||||
|
openDialog,
|
||||||
|
// #withAlertsActions
|
||||||
|
openAlert,
|
||||||
}) {
|
}) {
|
||||||
|
const { projectTimeEntries } = useProjectTimesheetContext();
|
||||||
|
|
||||||
// Retrieve project timesheet table columns.
|
// Retrieve project timesheet table columns.
|
||||||
const columns = useProjectTimesheetColumns();
|
const columns = useProjectTimesheetColumns();
|
||||||
|
|
||||||
// Handle delete timesheet.
|
// Handle delete timesheet.
|
||||||
const handleDeleteTimesheet = () => {};
|
const handleDeleteTimesheet = ({ id }) => {
|
||||||
|
openAlert('project-timesheet-delete', { timesheetId: id });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditTimesheet = ({ id }) => {
|
||||||
|
openDialog('project-time-entry-form', { timesheetId: id, action: 'edit' });
|
||||||
|
};
|
||||||
|
|
||||||
// Local storage memorizing columns widths.
|
// Local storage memorizing columns widths.
|
||||||
const [initialColumnsWidths, , handleColumnResizing] =
|
const [initialColumnsWidths, , handleColumnResizing] =
|
||||||
@@ -34,7 +50,7 @@ function ProjectTimesheetsTableRoot({
|
|||||||
return (
|
return (
|
||||||
<ProjectTimesheetDataTable
|
<ProjectTimesheetDataTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={[]}
|
data={projectTimeEntries}
|
||||||
manualSortBy={true}
|
manualSortBy={true}
|
||||||
noInitialFetch={true}
|
noInitialFetch={true}
|
||||||
sticky={true}
|
sticky={true}
|
||||||
@@ -47,11 +63,14 @@ function ProjectTimesheetsTableRoot({
|
|||||||
size={timesheetsTableSize}
|
size={timesheetsTableSize}
|
||||||
payload={{
|
payload={{
|
||||||
onDelete: handleDeleteTimesheet,
|
onDelete: handleDeleteTimesheet,
|
||||||
|
onEdit: handleEditTimesheet,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
export const ProjectTimesheetsTable = compose(
|
export const ProjectTimesheetsTable = compose(
|
||||||
|
withAlertsActions,
|
||||||
|
withDialogActions,
|
||||||
withSettings(({ timesheetsSettings }) => ({
|
withSettings(({ timesheetsSettings }) => ({
|
||||||
timesheetsTableSize: timesheetsSettings?.tableSize,
|
timesheetsTableSize: timesheetsSettings?.tableSize,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -9,13 +9,18 @@ import { safeCallback, firstLettersArgs } from '@/utils';
|
|||||||
* Table actions cell.
|
* Table actions cell.
|
||||||
*/
|
*/
|
||||||
export function ActionsMenu({
|
export function ActionsMenu({
|
||||||
payload: { onDelete, onViewDetails },
|
payload: { onDelete, onEdit },
|
||||||
row: { original },
|
row: { original },
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
text={intl.get('timesheets.actions.delete_timesheet')}
|
icon={<Icon icon="pen-18" />}
|
||||||
|
text={intl.get('timesheets.action.edit_timesheet')}
|
||||||
|
onClick={safeCallback(onEdit, original)}
|
||||||
|
/>
|
||||||
|
<MenuItem
|
||||||
|
text={intl.get('timesheets.action.delete_timesheet')}
|
||||||
intent={Intent.DANGER}
|
intent={Intent.DANGER}
|
||||||
onClick={safeCallback(onDelete, original)}
|
onClick={safeCallback(onDelete, original)}
|
||||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export function useProjectTimesheetColumns() {
|
|||||||
id: 'duration',
|
id: 'duration',
|
||||||
Header: '',
|
Header: '',
|
||||||
accessor: 'duration',
|
accessor: 'duration',
|
||||||
width: 100,
|
width: 120,
|
||||||
className: 'duration',
|
className: 'duration',
|
||||||
align: 'right',
|
align: 'right',
|
||||||
clickable: true,
|
clickable: true,
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ export function useProjectTimeEntry(timeId, props, requestProps) {
|
|||||||
[t.PROJECT_TIME_ENTRY, timeId],
|
[t.PROJECT_TIME_ENTRY, timeId],
|
||||||
{ method: 'get', url: `projects/times/${timeId}`, ...requestProps },
|
{ method: 'get', url: `projects/times/${timeId}`, ...requestProps },
|
||||||
{
|
{
|
||||||
select: (res) => res.data.time,
|
select: (res) => res.data.time_entry,
|
||||||
defaultData: {},
|
defaultData: {},
|
||||||
...props,
|
...props,
|
||||||
},
|
},
|
||||||
@@ -95,7 +95,7 @@ export function useProjectTimeEntry(timeId, props, requestProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const transformProjectTimeEntries = (res) => ({
|
const transformProjectTimeEntries = (res) => ({
|
||||||
projectTasks: res.data.times,
|
projectTimeEntries: res.data.timeline,
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,10 +105,10 @@ const transformProjectTimeEntries = (res) => ({
|
|||||||
* @param requestProps
|
* @param requestProps
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function useProjectTimeEntries(taskId, props, requestProps) {
|
export function useProjectTimeEntries(id, props, requestProps) {
|
||||||
return useRequestQuery(
|
return useRequestQuery(
|
||||||
[t.PROJECT_TIME_ENTRIES, taskId],
|
[t.PROJECT_TIME_ENTRIES, id],
|
||||||
{ method: 'get', url: `projects/tasks/${taskId}/times`, ...requestProps },
|
{ method: 'get', url: `projects/${id}/times`, ...requestProps },
|
||||||
{
|
{
|
||||||
select: transformProjectTimeEntries,
|
select: transformProjectTimeEntries,
|
||||||
defaultData: {
|
defaultData: {
|
||||||
|
|||||||
Reference in New Issue
Block a user