Skip to content

Commit

Permalink
Merge pull request #2026 from bcgov/re-unite-orphaned-RFI-files
Browse files Browse the repository at this point in the history
Re unite orphaned rfi files
  • Loading branch information
rafasdc authored Aug 10, 2023
2 parents 09be10b + dd67b25 commit ec289cd
Show file tree
Hide file tree
Showing 10 changed files with 445 additions and 40 deletions.
22 changes: 21 additions & 1 deletion app/components/Analyst/RFI/ListFilesWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { WidgetProps } from '@rjsf/core';
import styled from 'styled-components';
import { useRouter } from 'next/router';
import { useFeature } from '@growthbook/growthbook-react';
import { AddButton } from '../Project';

const StyledContainer = styled.div`
margin-bottom: 24px;
Expand Down Expand Up @@ -33,7 +36,13 @@ type File = {
type: string;
};

const ListFilesWidget: React.FC<WidgetProps> = ({ label, value }) => {
const ListFilesWidget: React.FC<WidgetProps> = ({
formContext,
label,
value,
}) => {
const showRfiUpload = useFeature('show_analyst_rfi_upload').value;
const router = useRouter();
const isFiles = value?.length > 0;

const handleDownload = async (uuid: string, fileName: string) => {
Expand Down Expand Up @@ -66,6 +75,17 @@ const ListFilesWidget: React.FC<WidgetProps> = ({ label, value }) => {
) : (
<StyledP>Not received</StyledP>
)}
{showRfiUpload && (
<AddButton
isFormEditMode={false}
title="Add file(s) sent by Email"
onClick={() => {
router.push(
`/analyst/application/${formContext.applicationId}/rfi/${formContext.rfiId}/upload`
);
}}
/>
)}
</StyledContainer>
);
};
Expand Down
1 change: 1 addition & 0 deletions app/components/Analyst/RFI/RFI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const RFI: React.FC<Props> = ({ rfiDataByRfiDataId, id }) => {
formData={jsonData}
noValidate
tagName="div"
formContext={{ applicationId, rfiId: rowId }}
// Pass children to hide submit button
// eslint-disable-next-line react/no-children-prop
children
Expand Down
73 changes: 73 additions & 0 deletions app/components/Analyst/RFI/RFIAnalystUpload.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Button } from '@button-inc/bcgov-theme';
import { ISubmitEvent } from '@rjsf/core';
import { FormDiv } from 'components';
import { RfiTheme } from 'components/Analyst/RFI';
import { RfiFormStatus, FormBase } from 'components/Form';
import { rfiSchema } from 'formSchema/analyst';
import { rfiAnalystUiSchema } from 'formSchema/uiSchema/analyst/rfiUiSchema';
import { useRouter } from 'next/router';
import { useUpdateWithTrackingRfiMutation } from 'schema/mutations/application/updateWithTrackingRfiMutation';
import styled from 'styled-components';

const Flex = styled('header')`
display: flex;
justify-content: space-between;
width: 100%;
`;

const RfiAnalystUpload = ({ rfiQuery }) => {
// const query = usePreloadedQuery(rfiQuery, preloadedQuery);
const { rfiDataByRowId, applicationByRowId } = rfiQuery;
const [updateRfi] = useUpdateWithTrackingRfiMutation();
const router = useRouter();

const handleSubmit = (e: ISubmitEvent<any>) => {
updateRfi({
variables: {
input: {
jsonData: e.formData,
rfiRowId: rfiDataByRowId.rowId,
},
},
onCompleted: () => {
router.push(`/analyst/application/${router.query.applicationId}/rfi`);
},
onError: (err) => {
// eslint-disable-next-line no-console
console.log('Error updating RFI', err);
},
});
};

return (
<div>
<Flex>
<div>
<h2>Upload new files</h2>
{rfiDataByRowId?.jsonData.rfiDueBy && (
<p>
Please upload the following files by{' '}
{rfiDataByRowId?.jsonData.rfiDueBy}
</p>
)}
</div>
<RfiFormStatus application={applicationByRowId} isSaving={false} />
</Flex>
<FormDiv>
<FormBase
theme={RfiTheme}
schema={rfiSchema}
uiSchema={rfiAnalystUiSchema}
omitExtraData={false}
formData={rfiDataByRowId?.jsonData}
onSubmit={handleSubmit}
noValidate
>
<Button>Save</Button>
</FormBase>
</FormDiv>
</div>
);
};

export default RfiAnalystUpload;
35 changes: 35 additions & 0 deletions app/formSchema/uiSchema/analyst/rfiUiSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export const rfiApplicantUiSchema = {
'ui:widget': 'FileWidget',
'ui:options': {
hideOptional: true,
allowMultipleFiles: true,
},
},
eligibilityAndImpactsCalculatorRfi: {
Expand All @@ -317,6 +318,7 @@ export const rfiApplicantUiSchema = {
'ui:widget': 'FileWidget',
'ui:options': {
hideOptional: true,
allowMultipleFiles: true,
},
},
detailedBudgetRfi: {
Expand All @@ -329,6 +331,7 @@ export const rfiApplicantUiSchema = {
'ui:widget': 'FileWidget',
'ui:options': {
hideOptional: true,
allowMultipleFiles: true,
},
},
financialForecastRfi: {
Expand All @@ -341,6 +344,7 @@ export const rfiApplicantUiSchema = {
'ui:widget': 'FileWidget',
'ui:options': {
hideOptional: true,
allowMultipleFiles: true,
},
},
lastMileIspOfferingRfi: {
Expand All @@ -353,6 +357,7 @@ export const rfiApplicantUiSchema = {
'ui:widget': 'FileWidget',
'ui:options': {
hideOptional: true,
allowMultipleFiles: true,
},
},
popWholesalePricingRfi: {
Expand All @@ -365,6 +370,7 @@ export const rfiApplicantUiSchema = {
'ui:widget': 'FileWidget',
'ui:options': {
hideOptional: true,
allowMultipleFiles: true,
},
},
communityRuralDevelopmentBenefitsTemplateRfi: {
Expand All @@ -377,6 +383,7 @@ export const rfiApplicantUiSchema = {
'ui:widget': 'FileWidget',
'ui:options': {
hideOptional: true,
allowMultipleFiles: true,
},
},
wirelessAddendumRfi: {
Expand All @@ -389,6 +396,7 @@ export const rfiApplicantUiSchema = {
'ui:widget': 'FileWidget',
'ui:options': {
hideOptional: true,
allowMultipleFiles: true,
},
},
supportingConnectivityEvidenceRfi: {
Expand All @@ -401,6 +409,7 @@ export const rfiApplicantUiSchema = {
'ui:widget': 'FileWidget',
'ui:options': {
hideOptional: true,
allowMultipleFiles: true,
},
},
geographicNamesRfi: {
Expand All @@ -413,6 +422,7 @@ export const rfiApplicantUiSchema = {
'ui:widget': 'FileWidget',
'ui:options': {
hideOptional: true,
allowMultipleFiles: true,
},
},
equipmentDetailsRfi: {
Expand Down Expand Up @@ -507,6 +517,7 @@ export const rfiApplicantUiSchema = {
'ui:options': {
hideOptional: true,
fileTypes: '.kmz',
allowMultipleFiles: true,
},
},
geographicCoverageMapRfi: {
Expand All @@ -519,6 +530,7 @@ export const rfiApplicantUiSchema = {
'ui:widget': 'FileWidget',
'ui:options': {
hideOptional: true,
allowMultipleFiles: true,
},
},
coverageAssessmentStatisticsRfi: {
Expand Down Expand Up @@ -558,4 +570,27 @@ export const rfiApplicantUiSchema = {
},
};

// create a new schema with file date and file date Title
export const rfiAnalystUiSchema = JSON.parse(
JSON.stringify(rfiApplicantUiSchema)
);
const stack = [rfiAnalystUiSchema.rfiAdditionalFiles];
while (stack.length) {
const currentObj = stack.pop();
Object.keys(currentObj).forEach((key) => {
if (typeof currentObj[key] === 'object') {
if (currentObj[key]['ui:widget'] === 'FileWidget') {
if (!currentObj[key]['ui:options']) {
currentObj[key]['ui:options'] = {};
}
currentObj[key]['ui:options'].allowMultipleFiles = true;
currentObj[key]['ui:options'].useFileDate = true;
currentObj[key]['ui:options'].fileDateTitle = 'Date received';
currentObj[key]['ui:options'].maxDate = new Date();
}
stack.push(currentObj[key]);
}
});
}

export default rfiUiSchema;
Loading

0 comments on commit ec289cd

Please sign in to comment.