Add notes fetch

This commit is contained in:
Oliver Walters 2026-05-20 11:43:17 +00:00
parent 19c497fb19
commit 88158610af
2 changed files with 31 additions and 2 deletions

View File

@ -240,6 +240,7 @@ export enum ApiEndpoints {
error_report_list = 'error-report/',
project_code_list = 'project-code/',
custom_unit_list = 'units/',
note_list = 'note/',
notes_image_upload = 'notes-image-upload/',
email_list = 'admin/email/',
email_test = 'admin/email/test/',

View File

@ -31,11 +31,38 @@ export default function NotesEditor({
editable?: boolean;
setDirtyCallback?: (dirty: boolean) => void;
}>) {
const api = useApi();
const user = useUserState();
const [selectedNote, setSelectedNote] = useState<string | undefined>(
undefined
);
// Fetch the available notes for the given model type and ID
const notesQuery = useQuery({
queryKey: ['notes', modelType, modelId],
queryFn: async () => {
return api
.get(apiUrl(ApiEndpoints.note_list), {
params: {
model_id: modelId,
model_type: modelType
}
})
.then((response) => response.data ?? []);
},
staleTime: 0,
refetchOnWindowFocus: false,
refetchOnMount: true,
enabled: !!modelId && !!modelType
});
const canEdit = useMemo(
() => user.hasChangePermission(modelType),
[user, modelType]
() =>
user.hasChangePermission(modelType) &&
notesQuery.isFetched &&
notesQuery.isSuccess,
[user, modelType, notesQuery]
);
const editor = useCreateBlockNote();
@ -46,6 +73,7 @@ export default function NotesEditor({
<Paper p='md' shadow='sm' withBorder>
<BlockNoteView
editor={editor}
content={selectedNote}
editable={canEdit}
style={{ minHeight: '400px' }}
/>