Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const getSubmissions = (name, page = 0, params = {}, formId, done = () => {}) => (dispatch, getState) => {
dispatch(requestSubmissions(name, page, params, formId));
const {
limit,
query,
select,
sort,
} = selectRoot(name, getState());
const formio = new Formiojs(`${Formiojs.getProjectUrl()}/${(formId ? `form/${formId}` : name)}/submission`);
const requestParams = {...query, ...params};
// Ten is the default so if set to 10, don't send.
if (limit !== 10) {
requestParams.limit = limit;
}
else {
delete requestParams.limit;
}
if (page !== 1) {
requestParams.skip = (page - 1) * limit;
}
else {
delete requestParams.skip;
}
export const indexForms = (name, page = 1, params = {}, done = () => {}) => (dispatch, getState) => {
dispatch(requestForms(name, page, params));
const {
limit,
query,
select,
sort,
} = selectRoot(name, getState());
const formio = new Formiojs(`${Formiojs.getProjectUrl()}/form`);
const requestParams = {...query, ...params};
// Ten is the default so if set to 10, don't send.
if (limit !== 10) {
requestParams.limit = limit;
}
else {
delete requestParams.limit;
}
if (page !== 1) {
requestParams.skip = (page - 1) * limit;
}
else {
delete requestParams.skip;
}
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 deleteSubmission = (name, id, formId, done = () => {}) => (dispatch, getState) => {
const formio = new Formiojs(`${Formiojs.getProjectUrl()}/${formId ? `form/${formId}` : name}/submission/${id}`);
return formio.deleteSubmission()
.then(() => {
dispatch(resetSubmission(name));
done(null, true);
})
.catch((error) => {
dispatch(failSubmission(name, error));
done(error);
});
};
export const initAuth = () => (dispatch) => {
const projectUrl = formiojs.getProjectUrl();
dispatch(requestUser());
Promise.all([
formiojs.currentUser(),
formiojs.makeStaticRequest(`${projectUrl}/access`)
.then((result) => {
const submissionAccess = transformSubmissionAccess(result.forms);
const formAccess = transformFormAccess(result.forms);
dispatch(submissionAccessUser(submissionAccess));
dispatch(formAccessUser(formAccess));
dispatch(rolesUser(result.roles));
})
.catch(() => {}),
formiojs.makeStaticRequest(projectUrl)