fix: created document composable to get any doctype record
This commit is contained in:
parent
7b34c5eb66
commit
ccd240f4e8
36
frontend/src/data/document.js
Normal file
36
frontend/src/data/document.js
Normal file
@ -0,0 +1,36 @@
|
||||
import { createToast } from '@/utils'
|
||||
import { createDocumentResource } from 'frappe-ui'
|
||||
|
||||
const documentsCache = {}
|
||||
|
||||
export function useDocument(doctype, docname) {
|
||||
documentsCache[doctype] = documentsCache[doctype] || {}
|
||||
|
||||
if (!documentsCache[doctype][docname]) {
|
||||
documentsCache[doctype][docname] = createDocumentResource({
|
||||
doctype: doctype,
|
||||
name: docname,
|
||||
setValue: {
|
||||
onSuccess: () => {
|
||||
createToast({
|
||||
title: 'Data Updated',
|
||||
icon: 'check',
|
||||
iconClasses: 'text-ink-green-3',
|
||||
})
|
||||
},
|
||||
onError: (err) => {
|
||||
createToast({
|
||||
title: 'Error',
|
||||
text: err.messages[0],
|
||||
icon: 'x',
|
||||
iconClasses: 'text-red-600',
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
document: documentsCache[doctype][docname],
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user