export interface SigningProps {
forms: Document[]
todos?: Document[]
listingId: string
listingAddress: Address
addDocument?: (data: DocumentInput) => void
printPdf?: (data: PrintPdfInput) => void
fillInPdfForm: (data: FillInPdfInput) => Promise<string>
deleteTodo?: (id: string) => void
}
function fillInPdfForm(fillInPdfInput: FillInPdfInput): Promise<string> {
return new Promise((resolve, reject) => {
fillInPdf({
variables: {
fillInPdfInput: fillInPdfInput,
},
})
.then((data: any) => {
const doc = {
...data.data.fillInPdf,
created: new Date().toString(),
}
setDocuments([...documents, doc])
const todoDocs = todoDocuments.filter(todo => todo.name !== doc.name)
setTodoDocuments(todoDocs)
resolve('')
})
.catch((error: any) => {
console.log(error)
reject(error)
})
})
}
useEffect(() => {
const fillInPdf = async () => {
try {
let fieldNames: string[] = []
let fieldValues: string[] = []
if (formValues) {
for (const name in formValues) {
fieldNames.push(name)
fieldValues.push(formValues[name])
}
}
await fillInPdfForm({
listingId,
includeSignature: true,
docId: id,
fieldNames,
fieldValues,
signatureUrls,
})
setMessage('')
setOpenFillInPdfFormDialog(false)
} catch (error) {
setMessage(error.message)
}
setFillingInPdf(false)
}
if (fillingInPdf && formValues && signatureUrls) fillInPdf()
}, [fillingInPdf, fillInPdfForm, formValues, signatureUrls, listingId, id])
Comments
Post a Comment