Compare commits
No commits in common. "3f9da22b58d7d5e487bbe7b11bc146314ddcf000" and "edf5ffc24483148a211a805653293a9d5549137b" have entirely different histories.
3f9da22b58
...
edf5ffc244
@ -1,5 +1,5 @@
|
||||
import PropTypes from 'prop-types'
|
||||
import { useState, useEffect, useContext, useCallback, useMemo, useRef } from 'react'
|
||||
import { useState, useEffect, useContext } from 'react'
|
||||
// import { getModelByName } from '../../../database/ObjectModels'
|
||||
import DocumentPrinterIcon from '../../Icons/DocumentPrinterIcon'
|
||||
import { Button, Dropdown, Modal } from 'antd'
|
||||
@ -15,9 +15,6 @@ const DocumentPrintButton = ({
|
||||
...buttonProps
|
||||
}) => {
|
||||
const { fetchObjects } = useContext(ApiServerContext)
|
||||
const fetchObjectsRef = useRef(fetchObjects)
|
||||
fetchObjectsRef.current = fetchObjects
|
||||
|
||||
const [documentTemplates, setDocumentTemplates] = useState([])
|
||||
const [currentDocumentTemplate, setCurrentDocumentTemplate] = useState(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
@ -28,12 +25,14 @@ const DocumentPrintButton = ({
|
||||
// Get the model by name
|
||||
//const model = getModelByName(type)
|
||||
|
||||
const loadDocumentTemplates = useCallback(async () => {
|
||||
// Fetch document templates when component mounts or type changes
|
||||
useEffect(() => {
|
||||
const loadDocumentTemplates = async () => {
|
||||
if (!type || token == null) return
|
||||
|
||||
setLoading(true)
|
||||
try {
|
||||
const result = await fetchObjectsRef.current('documentTemplate', {
|
||||
const result = await fetchObjects('documentTemplate', {
|
||||
filter: {
|
||||
objectType: type,
|
||||
global: false,
|
||||
@ -50,18 +49,10 @@ const DocumentPrintButton = ({
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [type, token])
|
||||
}
|
||||
|
||||
// Stable key from objectData._id (excludes _isEditing so toggling edit mode doesn't trigger template reload)
|
||||
const objectKey = useMemo(() => {
|
||||
if (!objectData) return null
|
||||
return objectData._id ?? objectData.id ?? null
|
||||
}, [objectData])
|
||||
|
||||
// Fetch document templates when component mounts or objectData, type or token changes
|
||||
useEffect(() => {
|
||||
loadDocumentTemplates()
|
||||
}, [objectKey, token, type, loadDocumentTemplates])
|
||||
}, [type, fetchObjects, token])
|
||||
|
||||
// Handle template selection
|
||||
const handleTemplateSelect = (template) => {
|
||||
|
||||
@ -29,7 +29,7 @@ const FilePreview = ({ file, style = {} }) => {
|
||||
}
|
||||
setFileObjectUrl(objectUrl)
|
||||
setLoading(false)
|
||||
}, [file, fetchFileContent, error])
|
||||
}, [file, fetchFileContent])
|
||||
|
||||
useEffect(() => {
|
||||
if (file?.type && token != null) {
|
||||
|
||||
@ -57,7 +57,7 @@ const FileUpload = ({
|
||||
: !currentFiles
|
||||
setHasNoItems(noItems)
|
||||
onChange(currentFiles)
|
||||
}, [currentFiles, multiple, onChange])
|
||||
}, [currentFiles, multiple])
|
||||
|
||||
const handleFileUpload = async (file) => {
|
||||
try {
|
||||
|
||||
@ -231,8 +231,7 @@ const AuthProvider = ({ children }) => {
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- run only on mount to load persisted session; deps are stable in behavior
|
||||
}, [])
|
||||
}, [isElectron, getAuthSession, clearPersistedSession, getUserInfo])
|
||||
|
||||
// Set up cookie synchronization between tabs
|
||||
useEffect(() => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user