Merge branch 'dev' into staging
This commit is contained in:
commit
c63912275b
@ -15,7 +15,6 @@ type IProps = {
|
||||
isCreateDocumentModalVisible: boolean;
|
||||
closeModal: () => void;
|
||||
folder: OfficeFolder;
|
||||
onDocumentAdded: () => Promise<void>;
|
||||
};
|
||||
|
||||
export default function ParameterDocuments(props: IProps) {
|
||||
@ -65,12 +64,14 @@ export default function ParameterDocuments(props: IProps) {
|
||||
}, [props]);
|
||||
|
||||
const addDocument = useCallback(async () => {
|
||||
try {
|
||||
if (addOrEditDocument === "add") {
|
||||
if (addOrEditDocument === "add") {
|
||||
try {
|
||||
const documentType = await DocumentTypes.getInstance().post({
|
||||
name: documentName,
|
||||
private_description: visibleDescription,
|
||||
office: { uid: props.folder.office!.uid! },
|
||||
office: {
|
||||
uid: props.folder.office!.uid!,
|
||||
},
|
||||
public_description: visibleDescription,
|
||||
});
|
||||
|
||||
@ -78,7 +79,15 @@ export default function ParameterDocuments(props: IProps) {
|
||||
await Deeds.getInstance().put(props.folder.deed?.uid!, {
|
||||
document_types: [...oldDocumentsType, documentType],
|
||||
});
|
||||
} else {
|
||||
|
||||
//await this.loadData();
|
||||
handleClose();
|
||||
window.location.reload();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
const oldDocumentsType = props.folder.deed?.document_types!;
|
||||
await Deeds.getInstance().put(props.folder.deed?.uid!, {
|
||||
document_types: [
|
||||
@ -86,12 +95,13 @@ export default function ParameterDocuments(props: IProps) {
|
||||
...selectedDocuments.map((document) => DocumentType.hydrate<DocumentType>({ uid: document.id as string })),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
await props.onDocumentAdded(); // ✅ Refresh AskDocuments state with the new document
|
||||
handleClose(); // ✅ Close modal
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
//await this.loadData();
|
||||
handleClose();
|
||||
window.location.reload();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}, [addOrEditDocument, documentName, handleClose, props, selectedDocuments, visibleDescription]);
|
||||
|
||||
|
@ -22,19 +22,30 @@ export default function AskDocuments() {
|
||||
const [isCreateDocumentModalVisible, setIsCreateDocumentModalVisible] = useState<boolean>(false);
|
||||
const [documentTypes, setDocumentTypes] = useState<IOption[]>([]);
|
||||
const [folder, setFolder] = useState<OfficeFolder | null>(null);
|
||||
const [selectedDocuments, setSelectedDocuments] = useState<string[]>([]);
|
||||
|
||||
const closeModal = () => setIsCreateDocumentModalVisible(false);
|
||||
const openModal = () => setIsCreateDocumentModalVisible(true);
|
||||
|
||||
const onFormSubmit = useCallback(
|
||||
async (e: React.FormEvent<HTMLFormElement> | null) => {
|
||||
async (
|
||||
e: React.FormEvent<HTMLFormElement> | null,
|
||||
values: {
|
||||
[key: string]: any;
|
||||
},
|
||||
) => {
|
||||
try {
|
||||
for (let i = 0; i < selectedDocuments.length; i++) {
|
||||
const documentAsked: [] = values["document_types"] as [];
|
||||
for (let i = 0; i < documentAsked.length; i++) {
|
||||
await Documents.getInstance().post({
|
||||
folder: { uid: folderUid },
|
||||
depositor: { uid: customerUid },
|
||||
document_type: { uid: selectedDocuments[i] },
|
||||
folder: {
|
||||
uid: folderUid,
|
||||
},
|
||||
depositor: {
|
||||
uid: customerUid,
|
||||
},
|
||||
document_type: {
|
||||
uid: documentAsked[i],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -47,7 +58,7 @@ export default function AskDocuments() {
|
||||
console.error(e);
|
||||
}
|
||||
},
|
||||
[selectedDocuments, customerUid, folderUid, router],
|
||||
[customerUid, folderUid, router],
|
||||
);
|
||||
|
||||
const getAvailableDocuments = useCallback(
|
||||
@ -111,30 +122,6 @@ export default function AskDocuments() {
|
||||
}
|
||||
}, [folderUid, getAvailableDocuments]);
|
||||
|
||||
const handleDocumentAdded = async () => {
|
||||
if (!folder) return;
|
||||
|
||||
try {
|
||||
// Fetch updated folder data to get the new document
|
||||
const updatedFolder = await Folders.getInstance().getByUid(folderUid as string, {
|
||||
q: {
|
||||
deed: { include: { document_types: true } },
|
||||
office: true,
|
||||
documents: { include: { depositor: true, document_type: true } },
|
||||
},
|
||||
});
|
||||
|
||||
if (!updatedFolder) return;
|
||||
|
||||
setFolder(updatedFolder); // ✅ Update the folder state
|
||||
setDocumentTypes(await getAvailableDocuments(updatedFolder)); // ✅ Refresh the document list
|
||||
|
||||
console.log("Document list updated with new document:", updatedFolder);
|
||||
} catch (error) {
|
||||
console.error("Failed to refresh document list:", error);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
}, [loadData]);
|
||||
@ -160,13 +147,6 @@ export default function AskDocuments() {
|
||||
toolTip={documentType.description}
|
||||
option={documentType}
|
||||
key={documentType.value as string}
|
||||
checked={selectedDocuments.includes(documentType.value as string)}
|
||||
onChange={(e) => {
|
||||
const value = documentType.value as string;
|
||||
setSelectedDocuments((prev) =>
|
||||
e.target.checked ? [...prev, value] : prev.filter((id) => id !== value),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@ -195,12 +175,7 @@ export default function AskDocuments() {
|
||||
</Form>
|
||||
</div>
|
||||
{folder && (
|
||||
<ParameterDocuments
|
||||
folder={folder}
|
||||
closeModal={closeModal}
|
||||
isCreateDocumentModalVisible={isCreateDocumentModalVisible}
|
||||
onDocumentAdded={handleDocumentAdded}
|
||||
/>
|
||||
<ParameterDocuments folder={folder} closeModal={closeModal} isCreateDocumentModalVisible={isCreateDocumentModalVisible} />
|
||||
)}
|
||||
</DefaultDoubleSidePage>
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user