Skip to content

Commit

Permalink
Merge pull request #276 from jadmsaadaot/SUBMIT-task#349
Browse files Browse the repository at this point in the history
Fix adding internal staff document infinite pending row
  • Loading branch information
jadmsaadaot authored Feb 3, 2025
2 parents 0e4a227 + 353c25d commit 2a102e7
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SubmitPrimaryRowTableCell,
SubmitTablePrimaryRow,
} from "@/components/Shared/Table/common";
import { useState } from "react";
import { useEffect, useMemo, useState } from "react";

type InternalDocumentsProps = Readonly<{
internalStaffDocuments: Array<InternalStaffDocument>;
Expand All @@ -25,10 +25,17 @@ export default function Rows({
);
const { uploadObjects: pendingDocuments } = useObjectUploadStore();

const internalStaffDocumentsIds = new Set(documents.map((doc) => doc.id));
const internalStaffDocumentsIds = useMemo(() => {
return new Set(documents.map((doc) => doc.id));
}, [documents]);

useEffect(() => {
setDocuments(internalStaffDocuments);
}, [internalStaffDocuments]);

const filteredPendingDocuments = pendingDocuments.filter(
(doc) => !internalStaffDocumentsIds.has(doc.submissionId ?? 0),
(doc) =>
!doc.submissionId || !internalStaffDocumentsIds.has(doc.submissionId),
);

return (
Expand Down

0 comments on commit 2a102e7

Please sign in to comment.