fix: created document composable to get any doctype record
(cherry picked from commit ccd240f4e8a5c717ed3d3929c1b710714ad54527)
This commit is contained in:
parent
ddc142b0bc
commit
fab665ad3f
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