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

PM: Supporting documents #4260

Merged
merged 33 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d9d74dc
add new model
pavlo-mk Sep 24, 2024
03bfb62
add new urls
pavlo-mk Sep 24, 2024
206c327
Merge branch 'develop' into new_190339_Payment_plan_supporting_documents
pavlo-mk Sep 24, 2024
7fc8b78
add test & migrations
pavlo-mk Sep 24, 2024
43d1f92
Merge remote-tracking branch 'origin/new_190339_Payment_plan_supporti…
pavlo-mk Sep 24, 2024
c2dce82
imports
pavlo-mk Sep 24, 2024
57fdc49
tests & fixes
pavlo-mk Sep 24, 2024
72350f2
add modal for supporting documents
Sep 23, 2024
ef117bf
add delete, fix doc layout
Sep 24, 2024
39abbbd
add supporting docs to follow up pages
Sep 24, 2024
296c09d
add title validation
Sep 25, 2024
25fc37a
textfield size small
Sep 25, 2024
560875e
regenerate schema
Sep 25, 2024
6746073
add error for > 10 files, accept other filetypes
Sep 25, 2024
5b676d9
add message when deleting doc
Sep 25, 2024
2c26e5b
display both title and file name
Sep 25, 2024
84294c2
Merge branch 'develop' into new_190339_Payment_plan_supporting_documents
pavlo-mk Sep 25, 2024
580bed9
upd e2e test_smoke_details_payment_plan
pavlo-mk Sep 26, 2024
e7d85c0
conflicts
pavlo-mk Sep 26, 2024
d3f12c0
review
pavlo-mk Sep 26, 2024
095adb9
conflicts
pavlo-mk Sep 27, 2024
2dc3e6d
fix urls in tests
pavlo-mk Sep 27, 2024
f282e20
Merge branch 'develop' into new_190339_Payment_plan_supporting_documents
pavlo-mk Sep 27, 2024
9aa8bc1
conflicts
pavlo-mk Sep 30, 2024
b63e14b
migrations
pavlo-mk Sep 30, 2024
bbc139f
fix download resp
pavlo-mk Sep 30, 2024
85a48c0
fix
pavlo-mk Sep 30, 2024
2e35f4a
add get_id
pavlo-mk Sep 30, 2024
edae0aa
supporting docs fixes
Sep 30, 2024
4049751
mypy
pavlo-mk Oct 1, 2024
fb84fe6
Merge branch 'develop' into new_190339_Payment_plan_supporting_documents
pavlo-mk Oct 1, 2024
c0209e9
conflicts
pavlo-mk Oct 3, 2024
3ad14ed
fixes
pavlo-mk Oct 3, 2024
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
21 changes: 21 additions & 0 deletions src/frontend/data/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3370,6 +3370,7 @@ type PaymentPlanNode implements Node {
deliveryMechanisms: [DeliveryMechanismPerPaymentPlanNode]
paymentItems(offset: Int, before: String, after: String, first: Int, last: Int): PaymentNodeConnection!
approvalProcess(offset: Int, before: String, after: String, first: Int, last: Int): ApprovalProcessNodeConnection!
documents(offset: Int, before: String, after: String, first: Int, last: Int): PaymentPlanSupportingDocumentNodeConnection!
adminUrl: String
currencyName: String
hasPaymentListExportFile: Boolean
Expand All @@ -3392,6 +3393,7 @@ type PaymentPlanNode implements Node {
unsuccessfulPaymentsCount: Int
canSendToPaymentGateway: Boolean
canSplit: Boolean
supportingDocuments: [PaymentPlanSupportingDocumentNode]
}

type PaymentPlanNodeConnection {
Expand All @@ -3418,6 +3420,25 @@ enum PaymentPlanStatus {
FINISHED
}

type PaymentPlanSupportingDocumentNode implements Node {
id: ID!
paymentPlan: PaymentPlanNode!
title: String!
file: String!
uploadedAt: DateTime!
createdBy: UserNode
}

type PaymentPlanSupportingDocumentNodeConnection {
pageInfo: PageInfo!
edges: [PaymentPlanSupportingDocumentNodeEdge]!
}

type PaymentPlanSupportingDocumentNodeEdge {
node: PaymentPlanSupportingDocumentNode
cursor: String!
}

type PaymentRecordAndPaymentNode {
objType: String
id: String
Expand Down
77 changes: 74 additions & 3 deletions src/frontend/src/__generated__/graphql.tsx

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/frontend/src/__generated__/introspection-result.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions src/frontend/src/api/paymentModuleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,54 @@ export const bulkActionPaymentPlansManagerial = async (
);
return response.data;
};

export const deleteSupportingDocument = async (
businessArea: string,
programId: string,
paymentPlanId: string,
fileId: string,
) => {
try {
await api.delete(
`${businessArea}/programs/${programId}/payment-plans/${paymentPlanId}/supporting-documents/${fileId}/`,
);
return { success: true };
} catch (error: any) {
const errorMessage = error?.message || 'An unknown error occurred';
throw new Error(`Failed to delete supporting document: ${errorMessage}`);
}
};

export const uploadSupportingDocument = async (
businessArea: string,
programId: string,
paymentPlanId: string,
file: File,
title: string,
) => {
const formData = new FormData();
formData.append('file', file);
formData.append('title', title);

try {
const response = await api.post(
`${businessArea}/programs/${programId}/payment-plans/${paymentPlanId}/supporting-documents/`,
formData,
);
return response.data; // Return the response data
} catch (error) {
throw new Error(`Failed to upload supporting document: ${error.message}`);
}
};

export const fetchSupportingDocument = async (
businessAreaSlug: string,
programId: string,
paymentPlanId: string,
fileId: string,
): Promise<any> => {
const response = await api.get(
`${businessAreaSlug}/programs/${programId}/payment-plans/${paymentPlanId}/supporting-documents/${fileId}/download/`,
);
return response;
};
5 changes: 5 additions & 0 deletions src/frontend/src/apollo/queries/paymentmodule/PaymentPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ export const PAYMENT_PLAN_QUERY = gql`
unicefId
}
unsuccessfulPaymentsCount
supportingDocuments {
id
title
file
}
}
}
`;
30 changes: 18 additions & 12 deletions src/frontend/src/components/core/DropzoneField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ interface DropzoneContainerProps {
disabled: boolean;
}

interface DropzoneFieldProps {
onChange: (acceptedFiles: File[]) => void;
loading: boolean;
dontShowFilename: boolean;
accepts?: { [key: string]: string[] };
}

const DropzoneContainer = styled.div<DropzoneContainerProps>`
width: 500px;
height: 100px;
Expand All @@ -32,36 +39,35 @@ export const DropzoneField = ({
onChange,
loading,
dontShowFilename,
}: {
onChange: (acceptedFiles: File[]) => void;
loading: boolean;
dontShowFilename: boolean;
}): React.ReactElement => {
accepts = {
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': [
'.xlsx',
],
},
}: DropzoneFieldProps): React.ReactElement => {
const { t } = useTranslation();
const onDrop = useCallback((acceptedFiles: File[]) => {
onChange(acceptedFiles);
}, []);

const { getRootProps, getInputProps, acceptedFiles } = useDropzone({
disabled: loading,
accept: {
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': [
'.xlsx',
],
},
accept: accepts,
onDrop,
});

const acceptedFilename =
acceptedFiles.length > 0 ? acceptedFiles[0].name : null;

return (
<Box display="flex" justifyContent="center" p={5}>
<DropzoneContainer {...getRootProps()} disabled={loading}>
<LoadingComponent isLoading={loading} absolute />
<input
{...getInputProps()}
accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
accept={Object.values(accepts).flat().join(',')}
data-cy="file-input"
/>{' '}
/>
{dontShowFilename || !acceptedFilename
? t('UPLOAD FILE')
: acceptedFilename}
Expand Down
Loading
Loading