Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (dispatch, getState) => {
// Check to see if the form is already loaded.
const form = selectForm(name, getState());
if (form.components && Array.isArray(form.components) && form.components.length && form._id === id) {
return;
}
const path = `${Formiojs.getProjectUrl()}/${id ? `form/${id}` : name}`;
const formio = new Formiojs(path);
dispatch(requestForm(name, id, path));
return formio.loadForm()
.then((result) => {
dispatch(receiveForm(name, result));
done(null, result);
})
.catch((result) => {
dispatch(failForm(name, result));
done(result);
});
};
};
export const getSubmission = (name, id, formId, done = () => {}) => (dispatch, getState) => {
// Check to see if the submission is already loaded.
if (getState().id === id) {
return;
}
const url = `${Formiojs.getProjectUrl()}/${formId ? `form/${formId}` : name}/submission/${id}`;
const formio = new Formiojs(url);
dispatch(requestSubmission(name, id, formId, url));
formio.loadSubmission()
.then((result) => {
dispatch(receiveSubmission(name, result));
done(null, result);
})
.catch((error) => {
dispatch(failSubmission(name, error));
done(error);
});
};
export const saveSubmission = (name, data, formId, done = () => {}) => (dispatch) => {
dispatch(sendSubmission(name, data));
const id = data._id;
const formio = new Formiojs(`${Formiojs.getProjectUrl()}/${formId ? `form/${formId}` : name}/submission${id ? `/${id}` : ''}`);
formio.saveSubmission(data)
.then((result) => {
const url = `${Formiojs.getProjectUrl()}/${formId ? `form/${formId}` : name}/submission/${result._id}`;
dispatch(receiveSubmission(name, result, url));
done(null, result);
})
.catch((error) => {
dispatch(failSubmission(name, error));
done(error);
});
};
return (dispatch) => {
const path = `${Formiojs.getProjectUrl()}/form/${id}`;
const formio = new Formiojs(path);
return formio.deleteForm()
.then(() => {
dispatch(resetForm(name));
done();
})
.catch((result) => {
dispatch(failForm(name, result));
done(result);
});
};
};
return (dispatch) => {
dispatch(sendForm(name, form));
const id = form._id;
const path = `${Formiojs.getProjectUrl()}/form${id ? `/${id}` : ''}`;
const formio = new Formiojs(path);
formio.saveForm(form)
.then((result) => {
const url = `${Formiojs.getProjectUrl()}/form/${result._id}`;
dispatch(receiveForm(name, result, url));
done(null, result);
})
.catch((result) => {
dispatch(failForm(name, result));
done(result);
});
};
};