Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create financial reports guide #1091

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/components/PeriodicReports/FinancialReportGuide.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Button } from '@material-ui/core';
import React from 'react';
import { ProjectOverviewFragment } from '../../scenes/Projects/Overview/ProjectOverview.generated';
import {
EditableProjectField,
UpdateProjectDialog,
} from '../../scenes/Projects/Update';
import { Many } from '../../util';
import { useDialog } from '../Dialog';
import { ButtonLink } from '../Routing';

const ReportGuideAction = {
SET_RANGE: 'SET_RANGE',
ADD_MANAGING_PARTNER: 'ADD_MANAGING_PARTNER',
SET_REPORT_FREQUENCY: 'SET_REPORT_FREQUENCY',
};

export const FinancialReportGuide = ({
project,
}: {
project: ProjectOverviewFragment;
}) => {
const [editState, editField, fieldsBeingEdited] =
useDialog<Many<EditableProjectField>>();
let action;

if (!project.mouRange.value.start || !project.mouRange.value.end) {
action = ReportGuideAction.SET_RANGE;
} else if (project.partnerships.items.length === 0) {
action = ReportGuideAction.ADD_MANAGING_PARTNER;
} else {
action = ReportGuideAction.SET_REPORT_FREQUENCY;
}
return (
<>
{action === ReportGuideAction.SET_RANGE ? (
<Button color="primary" onClick={() => editField('mouRange')}>
Set date range
</Button>
) : action === ReportGuideAction.ADD_MANAGING_PARTNER ? (
<ButtonLink color="primary" to={'partnerships'}>
Add managing partner
</ButtonLink>
) : (
<ButtonLink color="primary" to={'partnerships'}>
Set reporting frequency
</ButtonLink>
)}
<UpdateProjectDialog
{...editState}
project={project}
editFields={fieldsBeingEdited}
/>
</>
);
};
13 changes: 11 additions & 2 deletions src/components/PeriodicReports/PeriodicReportCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Typography,
} from '@material-ui/core';
import { AssignmentOutlined, BarChart, ShowChart } from '@material-ui/icons';
import React, { useState } from 'react';
import React, { ReactNode, useState } from 'react';
import { useDropzone } from 'react-dropzone';
import { ReportType } from '../../api';
import {
Expand Down Expand Up @@ -69,10 +69,18 @@ export interface PeriodicReportCardProps {
dueNext?: SecuredPeriodicReportFragment;
disableIcon?: boolean;
hasDetailPage?: boolean;
cardAction?: ReactNode;
}

const PeriodicReportCardInContext = (props: PeriodicReportCardProps) => {
const { type, dueCurrently, dueNext, disableIcon, hasDetailPage } = props;
const {
type,
dueCurrently,
dueNext,
disableIcon,
hasDetailPage,
cardAction,
} = props;
const classes = useStyles();

const currentFile = dueCurrently?.value?.reportFile;
Expand Down Expand Up @@ -138,6 +146,7 @@ const PeriodicReportCardInContext = (props: PeriodicReportCardProps) => {
<ButtonLink color="primary" to={link}>
View Reports
</ButtonLink>
{cardAction}
{needsUpload ? (
<Tooltip
title={
Expand Down
15 changes: 15 additions & 0 deletions src/scenes/Projects/Overview/ProjectOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { LanguageEngagementListItemFragment } from '../../../components/Language
import { List, useListQuery } from '../../../components/List';
import { PartnershipSummary } from '../../../components/PartnershipSummary';
import { PeriodicReportCard } from '../../../components/PeriodicReports';
import { FinancialReportGuide } from '../../../components/PeriodicReports/FinancialReportGuide';
import { ProjectChangeRequestSummary } from '../../../components/ProjectChangeRequestSummary';
import { ProjectMembersSummary } from '../../../components/ProjectMembersSummary';
import { Redacted } from '../../../components/Redacted';
Expand All @@ -41,6 +42,7 @@ import { CreateInternshipEngagement } from '../../Engagement/InternshipEngagemen
import { CreateLanguageEngagement } from '../../Engagement/LanguageEngagement/Create/CreateLanguageEngagement';
import { useProjectCurrentDirectory, useUploadProjectFiles } from '../Files';
import { ProjectListQueryVariables } from '../List/projects.generated';
import { FinancialReportsDocument } from '../Reports/ProjectReports.generated';
import { EditableProjectField, UpdateProjectDialog } from '../Update';
import { ProjectWorkflowDialog } from '../Update/ProjectWorkflowDialog';
import { useProjectId } from '../useProjectId';
Expand Down Expand Up @@ -159,6 +161,10 @@ export const ProjectOverview: FC = () => {
},
});

const { data: financialReportsData } = useQuery(FinancialReportsDocument, {
variables: { projectId, changeset: changesetId },
});
zkhin marked this conversation as resolved.
Show resolved Hide resolved

const projectName = projectOverviewData?.project.name;
const isTranslation = projectOverviewData
? projectOverviewData.project.__typename === 'TranslationProject'
Expand Down Expand Up @@ -496,6 +502,15 @@ export const ProjectOverview: FC = () => {
projectOverviewData?.project.currentFinancialReportDue
}
dueNext={projectOverviewData?.project.nextFinancialReportDue}
cardAction={
projectOverviewData?.project &&
financialReportsData?.project.reports.canRead === true &&
financialReportsData.project.reports.items.length === 0 && (
<FinancialReportGuide
project={projectOverviewData.project}
/>
)
}
/>
</Grid>
<Grid item xs={12} md={6}>
Expand Down
1 change: 1 addition & 0 deletions src/scenes/Projects/Reports/ProjectReports.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ query FinancialReports($projectId: ID!, $changeset: ID) {
items {
...PeriodicReport
}
canRead
}
}
}