Skip to content

Commit

Permalink
Add notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
tdraier committed Dec 20, 2024
1 parent 1e4440f commit c7f6a68
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion front/lib/swr/data_source_view_documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export function useCreateDataSourceViewDocument(
disabled: true,
});

const sendNotification = useSendNotification();

const doCreate = async (body: PostDataSourceWithNameDocumentRequestBody) => {
const createUrl = `/api/w/${owner.sId}/spaces/${dataSourceView.spaceId}/data_sources/${dataSourceView.dataSource.sId}/documents`;
const res = await fetch(createUrl, {
Expand All @@ -129,11 +131,21 @@ export function useCreateDataSourceViewDocument(
});
if (!res.ok) {
const errorData = await getErrorFromResponse(res);
console.error("Error creating document", errorData);
sendNotification({
type: "error",
title: "Failed to create document",
description: `Error: ${errorData.message}`,
});
return null;
} else {
void mutateContentNodes();

sendNotification({
type: "success",
title: "Document created",
description: "Document has been created",
});

const response: PostDocumentResponseBody = await res.json();
return response.document;
}
Expand Down

0 comments on commit c7f6a68

Please sign in to comment.