fix review changes
This commit is contained in:
@@ -1,10 +1,25 @@
|
||||
import CaptainDocumentAPI from 'dashboard/api/captain/document';
|
||||
import { createStore } from './storeFactory';
|
||||
|
||||
// Constants
|
||||
const DOCUMENT_TYPE = {
|
||||
PDF: 'pdf',
|
||||
URL: 'url',
|
||||
};
|
||||
|
||||
const FORM_DATA_FIELDS = {
|
||||
PDF_DOCUMENT: 'pdf_document',
|
||||
ASSISTANT_ID: 'assistant_id',
|
||||
};
|
||||
|
||||
const actions = mutationTypes => ({
|
||||
async uploadPdf({ commit }, formData) {
|
||||
async uploadPdf({ commit }, { pdf_document, assistant_id }) {
|
||||
commit(mutationTypes.SET_UI_FLAG, { creatingItem: true });
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append(FORM_DATA_FIELDS.PDF_DOCUMENT, pdf_document);
|
||||
formData.append(FORM_DATA_FIELDS.ASSISTANT_ID, assistant_id);
|
||||
|
||||
const response = await CaptainDocumentAPI.uploadPdf(formData);
|
||||
const { data } = response;
|
||||
// Use UPSERT like the create action for consistency
|
||||
@@ -16,6 +31,23 @@ const actions = mutationTypes => ({
|
||||
return Promise.reject(error);
|
||||
}
|
||||
},
|
||||
|
||||
async createDocument({ dispatch }, documentData) {
|
||||
// Unified method to handle both URL and PDF document creation
|
||||
if (documentData.type === DOCUMENT_TYPE.PDF) {
|
||||
return dispatch('uploadPdf', {
|
||||
pdf_document: documentData.pdf_document,
|
||||
assistant_id: documentData.assistant_id,
|
||||
});
|
||||
}
|
||||
// URL creation uses the standard create action from storeFactory
|
||||
return dispatch('create', {
|
||||
document: {
|
||||
external_link: documentData.external_link,
|
||||
assistant_id: documentData.assistant_id,
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default createStore({
|
||||
|
||||
Reference in New Issue
Block a user